Minimum Spanning Trees; Prim’s Algorithm
Announcements
Today:

You can pave road segments.
Each segment costs its number
of paving stones.
Goal: pave the __________ stones
so every house can reach every other.
Which roads do you pave?
How many stones total?
Input: a connected, undirected graph \(G\)
with edge weights.
Output: a subgraph \(G'\) of \(G\) such that
Number of edges in \(G'\): ______
MST of this graph? Total weight: ______
Split the vertices into two sets:
\(S\) and everything else.
Let \(e\) be a minimum-weight edge
crossing the partition.
Then \(e\) is in some MST.
Here: \(S = \{A, C, D\}\).
Crossing edges: __________________
Minimum: ______
Let \(e\) be a minimum crossing edge, and \(T\) an MST that does not contain \(e\).
Add \(e\) to \(T\). That creates a __________.
The cycle crosses the partition at \(e\), so it must cross back on another edge, \(f\).
\(f\) is a crossing edge, so \(\text{weight}(f) \geq \text{weight}(e)\).
Remove \(f\). \(T + e - f\) is still a spanning tree, and its weight is \(\leq\) ______.
So \(T + e - f\) is an MST, and it contains \(e\).
Grow a tree from a start vertex \(s\).
Every edge we add is in some MST, by the partition property.
How do we find the minimum crossing edge quickly? A _________________.
This is Prim’s algorithm (1957).
Dijkstra’s
\(d[w]\): shortest known path from \(s\) to \(w\).
Everything else is the same, so the running time is the same:
| Adj matrix | Adj list | |
|---|---|---|
| heap | O(n2 + m log n) | O(n log n + m log n) |
| unsorted array | O(n2) | O(n2) |
Negative edge weights? Dijkstra’s: __________ Prim’s: __________
Dijkstra’s from A (Wednesday’s practice)
Total weight: ______
Prim’s from A
Total weight: ______
A to E: ______ in the shortest-path tree, ______ in the MST.
Pause the video. Run Prim’s algorithm from A.
Ties alphabetical. Labelled order? Final d and p? Total weight?
Labelled: A C D E B F
Total weight: 0 + 2 + 1 + 3 + 2 + 5 = 13
Monday: Kruskal’s algorithm, a second MST algorithm.
It uses disjoint sets.
Examlet 9 is open until Sunday.
CPSC 221