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
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
5
10
1
3
8
2
4
3
1
1
4
6
Add edge (1, 3) to E
6
5
2
5Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
2. Choose the edge e' not in E' such that, edge
weight of e' in E E' is minimal and no cycle
will be created if e' is added to E. Add e' to
E.
5
10
1
3
8
2
4
3
1
1
4
6
Add edge (2, 6) to E
6
5
2
6Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked at.
5
10
1
3
8
2
4
3
1
1
4
6
Add edge (2, 5) to E
6
5
2
7Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked at.
5
5
10
10
1
1
8
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
Edge (5, 6) is NOT added, since it creates a
cycle.
6
6
5
5
2
2
8Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked at.
5
5
10
10
1
1
8
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
Add edge (3, 4) to E
6
6
5
5
2
2
9Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked at.
5
5
10
10
1
1
8
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
Add edge (4, 5) to E
6
6
5
5
2
2
10Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked
at. Edge(1,4) is NOT added, since it creates a
cycle.
5
5
10
10
1
1
8
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
6
6
5
5
2
2
11Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked
at. Edge(2,3) is NOT added, since it creates a
cycle.
5
5
10
10
1
1
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
6
6
5
5
2
2
12Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked
at. Edge(1, 2) is NOT added, since it creates a
cycle.
5
5
10
10
1
1
8
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
6
6
5
5
2
2
13Graph Algorithms Minimum Spanning Tree
- Kruskals algorithm for finding an MST
- Starting from an empty tree, T, pick the edge e
with the - minimum weight, and initialize E e.
1
1
2. Choose the edge e' not in E such that, edge
weight of e' in E E is minimal and no cycle
will be created if e' is added to E. Add e' to
E. Repeat step 2 until all edges are looked
at. Done!!
5
5
10
10
1
1
8
3
8
2
4
2
4
3
3
1
1
1
1
4
4
6
6
6
6
5
5
2
2
Sum of edge weights 1 1 1 3 4 10.