Application of greedy method prim

2,562 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,562
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
67
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Application of greedy method prim

  1. 1. Application of greedy method:Prim’s Algorithm
  2. 2. Greedy Method ???A greedy method is an method that followsthe problem solving technique of making thelocally optimal choice at each stage with thehope of finding a global optimum.
  3. 3. Prim’s AlgorithmPrims algorithm is a greedy algorithm thatfinds a minimum spanning tree fora connected weighted undirected graph. Thismeans it finds a subset of the edges that formsa tree that includes every vertex, where thetotal weight of all the edges in the tree isminimized.
  4. 4. Spanning Tree ???A spanning tree of a connected graph G canbe defined as a maximal set of edges of G thatcontains no cycle, or as a minimal set of edgesthat connect all vertices.
  5. 5. Minimum Spanning Tree ???A minimum spanning tree is a subgraph of anundirected weighted graph G, such that• 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
  6. 6. Algorithm
  7. 7. Example 1
  8. 8. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4
  9. 9. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4
  10. 10. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4
  11. 11. 5 A B 4 6 2 2 D 3C 3 1 2 E F 4
  12. 12. A B 2 2 D 3C 3 1 2 E F 4
  13. 13. A B 2 2 D 3C 3 1 2 E F
  14. 14. A B 2 2 D 3C 3 1 2 E F
  15. 15. A B 2 2 DC 3 1 2 E F
  16. 16. A B 2 2 DC 3 1 2 E F
  17. 17. minimum- spanning tree A B 2 2 DC 3 1 2 E F
  18. 18. Example 2
  19. 19. Prim’s Algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  20. 20. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c The MST initially consists of the vertex e
  21. 21. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  22. 22. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  23. 23. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c
  24. 24. Prim’s algorithm 9 b a 2 6 d 4 5 5 4 5 e c The final minimum spanning tree
  25. 25. Example 3
  26. 26. Weight (T) = 23 + 29 + 31 + 32 + 47 + 54 + 66 = 282
  27. 27. Problem: Laying TelephoneWire Central office
  28. 28. Wiring: Normal Approach Central office Expensive!
  29. 29. Wiring: Better Approach Central officeMinimize the total length of wire connecting the customers
  30. 30. Thank You

×