Download presentation
Presentation is loading. Please wait.
1
Minimum Spanning Trees
2
Example Application for MST
Minimum Spanning Tree for Electrical wiring
3
Spanning Trees Connected and having no cycles.
A graph having more than V – 1 edges contains at least one cycle.
4
Minimum Spanning Tree (MST)
What is minimum spanning tree? A tree that covers (spans) all the vertices of a connected graph which has the minimum total cost of edges in the tree. A MST exists for a graph iff the graph is connected. The same problem makes sense for directed graphs too, but the solution is more difficult.
5
Minimum Spanning Tree (MST)
Our problem is finding a minimum spanning tree in an undirected and connected graph.
6
Example: Minimum Spanning Tree
v1 2 v2 4 1 3 10 2 v3 v4 7 v5 8 4 5 6 v6 1 v7 Example undirected and connected graph v1 v2 v5 v3 v6 v7 2 1 4 6 v4 The corresponding minimum spanning tree
7
Properties: Minimum Spanning Tree
If the number of vertices of a connected undirected graph is |V|, then its minimum spanning tree will have |V| vertices |V| - 1 edges. A MST does not contain any cycle, since it is a tree. If we add an extra edge to a MST, then it will have a cycle.
8
Example Application for MST
power outlet or light Electrical wiring of a house using minimum amount of wires (cables)
9
Example Application for MST
Minimum Spanning Tree for Electrical wiring
10
Prim’s Algorithm for MST
MST is constructed in successive stages. At each stage: A new vertex is added to the tree by choosing the edge (u,v) such that the cost of (u,v), w(u,v), is the smallest among all edges where u is in the tree and v is not.
11
1 2 3 4 5 6 7
14
6 8 5 3 7 9 15
15
Prim’s Algorithm: Example
Start with vertex v1. It is the initial current tree which we will grow to an MST V1 0 V4 1 V2 2 V3 4 V6 v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 Content of the priority queue A connected, undirected graph G is given above.
16
Prim’s Algorithm: Example
Select an edge from graph: that is not in the current tree, that has the minimum cost, and that can be connected to the current tree. Step 1 v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V4 1 V2 2 V3 4 Content of the priority queue
17
Prim’s Algorithm: Example
The edges that can be connected are: (v1,v2): cost 2 (v1,v4): cost 1 (v1,v3): cost 2 Step 1 v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V4 1 V2 2 V3 4 Content of the priority queue
18
Prim’s Algorithm: Example
We include the vertex v4, that is connected to the selected edge, to the current tree. In this way we grow the tree. Step 2 v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V2 2 V3 2 V7 4 V5 7 V6 8 Content of the priority queue
19
Content of the priority queue
Prim’s Algorithm Repeat steps: 1, and 2 Add either edge (v4, v3) v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V3 2 V7 4 V5 7 V6 8 Content of the priority queue
20
Content of the priority queue
Prim’s Algorithm Grow the tree! v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V7 4 V6 5 V5 7 Content of the priority queue
21
Content of the priority queue
Prim’s Algorithm Add edge (v4, v7) v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V7 4 V6 5 V5 7 Content of the priority queue
22
Content of the priority queue
Prim’s Algorithm Grow the tree! v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V6 1 V5 6 Content of the priority queue
23
Content of the priority queue
Prim’s Algorithm Add edge (v7, v6) v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V6 1 V5 6 Content of the priority queue
24
Content of the priority queue
Prim’s Algorithm Grow the tree! v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V5 6 Content of the priority queue
25
Content of the priority queue
Prim’s Algorithm Add edge (v7, v5) v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 V5 6 Content of the priority queue
26
Prim’s Algorithm: Example
Grow the tree! v1 v2 v5 v3 v6 v7 4 2 1 5 8 7 3 10 6 v4 Content of the priority queue
27
Prim’s Algorithm: Example
v1 v2 v5 v3 v6 v7 2 1 4 6 v4 Finished! The resulting MST is shown below!
32
PRIM’s algorithm is similar to the Dijkstra’s shortest path algorithm
PRIM’s algorithm is similar to the Dijkstra’s shortest path algorithm. Complexities are the same.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.