1.0 - Minimum Spanning Tree Algorithms

1.1 - Prim’s Approach

🌱 Look in previous lecture for notes.

1.2 - Kruskal’s Approach

🌱 Initially create a graph with V|V| forests (each vertex is a forest) and add least-cost edges that merge forests together. At each step, we perform a locally optimal, greedy action such that it produces a globally optimal solution

T is always a spanning acyclic subgraph; A forest of trees

1.2.1 - Disjoint Set Data Structure

🌱 To use Kruskal’s algorithm, we need to create a Disjoint Set data structure

The trees in T form disjoint sets of G.V

1.2.2 - Disjoint-Set Implementation as Disjoint-Set Forests

1.2.3 - Operation Analysis

🌱 The make_set(x) method runs in Θ(1)\Theta(1) time.

make_set(x): # Set x to be its own parent x.p = x # Set rank (height) of node to 0 x.rank 0

🌱 The find_set(x) method runs in Θ(logn)\Theta(\log n) worst case, and Θ(1)\Theta(1) time typically.

find_set(x): # not representative element if x ≠ x.p # set current node's parent # to representative element x.p = find_set(x.p) return x.p # if x = x.p

🌱 The union(x,y) method merges the two sets that contain x and y into a single tree.

link(x,y) if x.rank > y.rank # Set the parent of the shorter tree's # root node to taller tree's root node. y.p = x else x.p = y # If the ranks are equal, choose y # as parent, and increment y's rank. if x.rank == y.rank y.rank = y.rank + 1 union(x,y) link(find_set(x), find_set(y))

1.2.4 - Example of Kruskal’s Algorithm

- The next edge with the lowest cost is $(d, e)$ which connects two disjoint forests so we add it to the MST being constructed.