D1.2 - Algorithms on graphs

Syllabus
2019
Topic
D1.2
Level
AS

Build a minimum spanning tree

A spanning tree connects every vertex of a connected weighted graph without cycles. With nn vertices it has exactly n1n-1 edges. A minimum spanning tree (MST), or minimum connector, is a spanning tree whose total edge weight is as small as possible.

Method Selection rule Stop
Kruskal consider edges in increasing weight order; add an edge only if it does not create a cycle n1n-1 edges have been selected
Prim start at the stated vertex; repeatedly choose the smallest edge joining the current tree to a new vertex every vertex has joined the tree

For Prim on a symmetric adjacency matrix, activate the start vertex's column and remove its row from future selection. Choose the least available entry in active columns; it identifies an edge to the vertex in that row. Activate the new vertex's column, remove its row, and repeat. Rows and columns represent vertices, symmetric entries represent undirected edge weights, and a blank or dash means no edge.

If AB=2AB=2, AC=5AC=5, BC=1BC=1, BD=4BD=4 and CD=3CD=3, Kruskal selects BCBC, ABAB, CDCD, with total 6. Prim from AA selects ABAB, BCBC, CDCD: the order differs, but the MST is the same.

Prim must choose the smallest edge crossing from the current tree to an unjoined vertex, not simply the smallest edge anywhere. An MST minimises the total weight needed to connect all vertices; it is not the shortest path between a chosen pair. Equal weights may allow more than one MST.

Find a shortest path with Dijkstra's algorithm

Dijkstra's algorithm finds shortest distances from one start vertex in a weighted network with non-negative edge weights. A temporary label is the best distance found so far; once it is the smallest temporary label and becomes permanent, its value cannot improve.

Give the start vertex permanent label 0 and every other vertex a temporary label \infty. From the newest permanent vertex uu, calculate a candidate for each adjacent non-permanent vertex vv. Replace vv's label and predecessor only when the candidate is smaller. Then make the smallest temporary label permanent and repeat until the destination is permanent.

\text{candidate label for }v=\text{permanent label of }u+w(u,v)

Let AB=4AB=4, AC=2AC=2, CB=1CB=1, BD=5BD=5, CD=8CD=8, BE=9BE=9 and DE=2DE=2. From AA, make CC permanent at 2, improve BB to 3 via CC, make BB permanent, improve DD to 8, then reach EE at 10 via DD. Backtracking predecessors gives ACBDEA-C-B-D-E, length 10.

The permanent destination label gives the shortest distance, but the route comes from predecessor labels: start at the destination and follow predecessors backwards to the start, then reverse the sequence. If a journey must pass through a specified vertex, find and join the required shortest-path segments.

Do not choose the smallest edge weight; choose the vertex with the smallest total temporary label. Never change a permanent label, and do not confuse the resulting shortest path with a minimum spanning tree, which connects every vertex rather than one chosen pair.