



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















Department of Computer Science — University of San Francisco – p.1/
Given a connected, undirected graph
A^ subgraph^ of^ G
contains a subset of the vertices and edges in^ G A^ Spanning Tree
T^ of^ G^ is: subgraph of G contains all vertices in^ G connected acyclic
Department of Computer Science — University of San Francisco – p.2/
Minimal Cost Spanning Tree^ Given a weighted, undirected graph
Spanning tree of
G^ which minimizes the sum of all weights on edges of spanning tree
Department of Computer Science — University of San Francisco – p.7/
4 1
3 10 2 7 5 8
(^4 )
Department of Computer Science — University of San Francisco – p.8/
Can there be more than one minimal cost spanning treefor a particular graph?
Department of Computer Science — University of San Francisco – p.10/
Can there be more than one minimal cost spanning treefor a particular graph? YES!^ What happens when all edges have unit cost?
Department of Computer Science — University of San Francisco – p.11/
Two algorithms to calculate MST:^ Kruskal’s Algorithm^ Build a “forest” of spanning trees^ Combine into one tree^ Prims Algorithm^ Grow a single tree out from a start vertex
Department of Computer Science — University of San Francisco – p.13/
Start with an empty graph (no edges) Sort the edges by cost For each edge^ e (in increasing order of cost) Add e to G if it would not cause a cycle
Department of Computer Science — University of San Francisco – p.14/
Proof (by contradiction) Assume that^ no^
optimal MST^ T^ contains the minimum cost edge^ e Add^ e^ to^ T^ , which causes a cycle Remove an edge other than
e^ to break the cycle ′^ cost T ≤^ T^ , a contradiction
Department of Computer Science — University of San Francisco – p.16/
Coding Kruskal’s Algorithm:^ Place all edges into a list^ Sort list of edges by cost^ For each edge in the list^ Select the edge if it does not form a cycle withpreviously selected edges^ How can we do this?
Department of Computer Science — University of San Francisco – p.17/
We need to:^ Put each vertex in its own tree^ Given any two vertices
vand^ v, determine if they are^1 in the same tree Given any two vertices
vand^ v, merge the tree^1 containing^ vand the tree containing^1
v^2 ... sound familiar?
Department of Computer Science — University of San Francisco – p.19/
Disjoint sets! Create a list of all edges Sort list of edges For each edge^ e = (v, v)^ in the list^12 if FIND(v) != FIND(v) (^12) Add e to spanning tree UNION(v, v) 12
Department of Computer Science — University of San Francisco – p.20/