3.5.14 · D1Graphs

Foundations — Minimum Spanning Tree — Kruskal's (Union-Find), Prim's (priority queue)

2,061 words9 min readBack to topic

Before you can follow Kruskal or Prim, you must be able to look at a symbol like , or the phrase "same component", or , and instantly picture what it means. This page builds every one of those from nothing, in an order where each idea leans on the one before it.


1. A vertex — the dot

The whole set of vertices is written . When we say "there are vertices" we are (slightly loosely) using the same letter for both the set and its size (how many dots there are).

Figure — Minimum Spanning Tree — Kruskal's (Union-Find), Prim's (priority queue)

WHY the topic needs it: an MST must "touch every vertex". If you cannot picture a vertex as a dot, the phrase "touch every dot exactly once" has nothing to hold onto.


2. An edge — the line between two dots

The whole set of edges is written , and also stands for how many edges there are.


3. Undirected — the line has no arrow

Figure — Minimum Spanning Tree — Kruskal's (Union-Find), Prim's (priority queue)

WHY the topic needs it: the parent note's biggest "steel-manned error" is thinking MSTs work on directed graphs. They do not. The very definition of MST assumes every edge is two-way. If edges had arrows, "connecting two islands" would become ambiguous — which direction? So we insist on undirected from the start. (The directed cousin is a different beast, stored differently too.)


4. Weight — a price tag on the line

So means: an edge between vertex and vertex , costing .

WHY the topic needs it: the word "Minimum" in MST is entirely about these numbers. No weights, no notion of "cheapest".


5. A weighted undirected graph — dots + priced two-way lines

Figure — Minimum Spanning Tree — Kruskal's (Union-Find), Prim's (priority queue)

This picture is the exact graph the parent uses for its worked example. Keep it in your head; every later idea points back to it.


6. Connected — you can reach everyone

WHY the topic needs it: an MST only exists if the graph is connected. If two clumps of islands have no bridge between them at all, no set of edges can ever join them, so "spanning" everything is impossible.


7. Component — an isolated clump

Figure — Minimum Spanning Tree — Kruskal's (Union-Find), Prim's (priority queue)

WHY the topic needs it: this is the heartbeat of Kruskal. Every time Kruskal considers an edge it asks "are and already in the same component?" If yes, connecting them again just makes a loop — skip it. That single question is answered by Disjoint Set Union (Union-Find).


8. Cycle — a wasteful loop


9. Tree and Spanning Tree — connected with zero waste


10. The Minimum Spanning Tree itself

Recall Quick self-check

A spanning tree has how many edges on 4 vertices? ::: Exactly 3. Can an MST contain a cycle? ::: No — a tree by definition has no cycles.


11. Greedy — take the best-looking bite now


12. A cut — split the dots into two teams

WHY the topic needs it: the parent's entire correctness proof rides on the cut propertythe cheapest crossing edge of any cut is safe to add. You cannot read that theorem until "cut", "", and "crossing edge" are pictures, not symbols.


13. Reading the cost notation

Since a graph has at most edges, , which is why and are treated as the same order.


14. Two engines you'll call by name

  • — the inverse Ackermann function. Grows so unimaginably slowly it is effectively constant ( for any graph in the universe). It measures the cost of one Union-Find operation.
  • A min-heap / priority queue — a data structure that always hands you its smallest element fast. This is Prim's engine; details in Priority Queue (Binary Heap).
  • Prim's heap skeleton is identical to Dijkstra's Algorithm — the only difference is what number you store as the key (edge weight vs. path distance).

Prerequisite map

Vertex - a dot

Edge - a line

Undirected - no arrow

Weight - a price tag

Weighted Graph

Connected

Component - a clump

Cycle - a wasteful loop

Spanning Tree - V minus 1 edges

Minimum Spanning Tree

Cut and crossing edge

Greedy choice

Kruskal and Prim

Big-O and log

Union-Find engine

Priority Queue engine


Equipment checklist

Test yourself — you are ready for the parent page only if each reveal feels obvious.

What does the triple mean?
An undirected edge of cost joining vertex to vertex .
What is ?
All vertices in that are NOT in the set (set subtraction).
Why must the graph be undirected for an MST?
MST is defined only for two-way edges; directed graphs need a different algorithm (minimum arborescence).
How many edges does a spanning tree on vertices have?
Exactly .
Why does each non-cyclic edge drop the component count by 1?
It merges two separate clumps into one.
What is a crossing edge of a cut ?
An edge with one endpoint in and the other outside .
What question does answer?
How many times you can halve before reaching 1.
Why treat and as equal?
Because , so .
What does represent and why ignore it?
The inverse Ackermann cost of a Union-Find op; it stays , effectively constant.
What is a cycle and why does an MST avoid it?
A path returning to its start; the heaviest cycle edge is always removable, so it is wasteful.

Connections

  • Parent topic
  • Disjoint Set Union (Union-Find) — answers "same component?" in near-constant time.
  • Priority Queue (Binary Heap) — hands Prim the cheapest crossing edge fast.
  • Cut Property and Cycle Property — the theorem that makes greed correct.
  • Greedy Algorithms — why local-best is global-best here.
  • Graph Representations — edge list vs adjacency list.
  • Dijkstra's Algorithm — the same heap skeleton as Prim.