GF6: Minimum Spanning Trees

San Skulrattanakulchai

November 16, 2018

Minimum Spanning Tree Problem

Prim's algorithm

Prim's algorithm, continued

    choose any vertex r
    d[v] ← ∞ for all v ≠ r
    d[r] ← 0
    let tree T be an empty tree
    while T has < n vertices do {
        let v be a vertex not in T with minimum value d[v]
        add v to T
        for edges vw do {
            if w is not in T then {
                if \ell[v,w] < d[w] then {
                    d[w] ← \ell[v,w]
                    p[w] ← v
                }
            }
        }
    }
    /* The tree defined by the edges p[v] (v ∈ V) is the MST. */

Example execution

Implementation & time

Why is Prim's algorithm correct

Kruskal's algorithm

    initialize T to a forest containing n vertices & no edges
    /* so T contains n different trees */

    for each edge e, in order of nondecreasing length \ell(e) do
        if e joins 2 different trees of T then add e to T

Execution

[RUN THE ALGORIHM ON THE EXAMPLE GRAPH.]

Implementating Kruskal's algorithm

Running Time