Title: Graph Algorithms: Minimum Spanning Tree
1Graph Algorithms Minimum Spanning Tree
We are given a weighted, undirected graph G (V,
E), with weight function w E ? R mapping edges
to real valued weights.
1
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
2Graph Algorithms Minimum Spanning Tree
We are given a weighted, undirected graph G (V,
E), with weight function w E ? R mapping edges
to real valued weights.
1
A spanning tree T (V, E) is a subgraph of G
such that V V and T is a tree.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
3Graph Algorithms Minimum Spanning Tree
We are given a weighted, undirected graph G (V,
E), with weight function w E ? R mapping edges
to real valued weights.
1
A spanning tree T (V, E) is a subgraph of G
such that V V and T is a tree.
5
10
1
3
8
2
4
3
1
A minimum spanning tree is a spanning tree where
the sum of the weights in E is minimal.
1
4
6
6
5
2
4Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
5Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
6Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal and no
cycle will be created if v and the edge are added
to (V, E). Add v to V and the edge to E.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
7Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal and no
cycle will be created if v and the edge are added
to (V, E). Add v to V and the edge to
E. Repeat until all vertices have been added.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
8Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal and no
cycle will be created if v and the edge are added
to (V, E). Add v to V and the edge to
E. Repeat until all vertices have been added.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
9Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal and no
cycle will be created if v and the edge are added
to (V, E). Add v to V and the edge to
E. Repeat until all vertices have been added.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
10Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal and no
cycle will be created if v and the edge are added
to (V, E). Add v to V and the edge to
E. Repeat until all vertices have been added.
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
11Graph Algorithms Minimum Spanning Tree
Prims algorithm for finding a minimum spanning
tree 1. Starting from an empty tree, T, pick a
vertex, v0, at random and initialize V v0
and E .
v0
1
2. Choose a vertex v not in V such that edge
weight from v to a vertex in V is minimal and no
cycle will be created if v and the edge are added
to (V, E). Add v to V and the edge to
E. Repeat until all vertices have been added.
Done!
5
10
1
3
8
2
4
3
1
1
4
6
6
5
2
Sum of edge weights 1 3 4 1 1 10.