Application of greedy method prim
-
Upload
techmx -
Category
Technology
-
view
1.453 -
download
1
Transcript of Application of greedy method prim
![Page 1: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/1.jpg)
Application of greedy method: Prim’s Algorithm
![Page 2: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/2.jpg)
Greedy Method ???
A greedy method is an method that follows the problem solving technique of making the locally optimal choice at each stage with the hope of finding a global optimum.
![Page 3: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/3.jpg)
Prim’s Algorithm
Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. This means it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized.
![Page 4: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/4.jpg)
Spanning Tree ???
A spanning tree of a connected graph G can be defined as a maximal set of edges of G that contains no cycle, or as a minimal set of edges that connect all vertices.
![Page 5: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/5.jpg)
![Page 6: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/6.jpg)
Minimum Spanning Tree ???
• it is a tree (i.e., it is acyclic)• it covers all the vertices V
– contains |V| - 1 edges
• the total cost associated with tree edges is the minimum among all possible spanning trees
• not necessarily unique
A minimum spanning tree is a subgraph of an undirected weighted graph G, such that
![Page 7: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/7.jpg)
![Page 8: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/8.jpg)
Algorithm
![Page 9: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/9.jpg)
![Page 10: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/10.jpg)
![Page 11: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/11.jpg)
Example 1
![Page 12: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/12.jpg)
C
FE
A B
D
5
64
3
4
2
1 2
3
2
![Page 13: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/13.jpg)
C
FE
A B
D
5
64
3
4
2
1 2
3
2
![Page 14: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/14.jpg)
C
FE
A B
D
5
64
3
4
2
1 2
3
2
![Page 15: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/15.jpg)
C
FE
A B
D
5
64
3
4
2
1 2
3
2
![Page 16: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/16.jpg)
C
FE
A B
D
3
4
2
1 2
3
2
![Page 17: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/17.jpg)
C
FE
A B
D
3
2
1 2
3
2
![Page 18: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/18.jpg)
C
FE
A B
D
3
2
1 2
2
3
![Page 19: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/19.jpg)
C
FE
A B
D
3
2
1 2
2
![Page 20: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/20.jpg)
C
FE
A B
D
3
2
1 2
2
![Page 21: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/21.jpg)
C
FE
A B
D
3
2
1 2
2
minimum- spanning tree
![Page 22: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/22.jpg)
Example 2
![Page 23: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/23.jpg)
Prim’s Algorithm
a
ce
d
b2
45
9
6
4
5
5
![Page 24: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/24.jpg)
Prim’s algorithm
a
ce
d
b2
45
9
6
4
5
5
The MST initially consists of the vertex e
![Page 25: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/25.jpg)
Prim’s algorithm
a
ce
d
b2
45
9
6
4
5
5
![Page 26: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/26.jpg)
Prim’s algorithm
a
ce
d
b2
45
9
6
4
5
5
![Page 27: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/27.jpg)
Prim’s algorithm
a
ce
d
b2
45
9
6
4
5
5
![Page 28: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/28.jpg)
Prim’s algorithm
a
ce
d
b2
45
9
6
4
5
5
The final minimum spanning tree
![Page 29: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/29.jpg)
Example 3
![Page 30: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/30.jpg)
![Page 31: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/31.jpg)
![Page 32: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/32.jpg)
![Page 33: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/33.jpg)
![Page 34: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/34.jpg)
![Page 35: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/35.jpg)
![Page 36: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/36.jpg)
Weight (T) = 23 + 29 + 31 + 32 + 47 + 54 + 66 = 282
![Page 37: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/37.jpg)
Problem: Laying Telephone Wire
Central office
![Page 38: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/38.jpg)
Wiring: Normal Approach
Central office
Expensive!
![Page 39: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/39.jpg)
Wiring: Better Approach
Central office
Minimize the total length of wire connecting the customers
![Page 40: Application of greedy method prim](https://reader030.fdocuments.us/reader030/viewer/2022012910/557cfca8d8b42a071b8b4e11/html5/thumbnails/40.jpg)
Thank You