PRIM’sSPANNINGTREEALGORITHM
Name : Anwar
Roll No : 44
MCS 3rd Open
TOPIC
 An algorithm is designed to achieve optimum solution for a given problem.
In greedy algorithm approach, decisions are made from the given solution
domain. As being greedy, the closest solution that seems to provide an
optimum solution is chosen.
 Greedy algorithms try to find a localized optimum solution, which may
eventually lead to globally optimized solutions. However, generally greedy
algorithms do not provide globally optimized solutions.
Greedy Algorithm Approach
s
 Most networking algorithms use the greedy approach. Here is a list of few of them −
 Travelling Salesman Problem
 Prim's Minimal Spanning Tree Algorithm
 Kruskal's Minimal Spanning Tree Algorithm
 Dijkstra's Minimal Spanning Tree Algorithm
 Graph - Map Coloring
 Graph - Vertex Cover
 Knapsack Problem
 Job Scheduling Problem
 There are lots of similar problems that uses the greedy approach to find an optimum solution.
Examples
 Example: Use Prim’s algorithm to find a minimum spanning tree in the following
weighted graph. Use alphabetical order to break ties.
B
A
2
Prim's Minimal Spanning Tree Algorithm
 Prim’s algorithm will proceed as follows. First we add edge {d, e} of weight1.
 Next, we add edge {c, e} of weight 2. Next, we add edge {d, z} of weight 2.
 Next, we add edge {b, e} of weight 3. And finally, we add edge {a, b} of
weight 2.
 This produces a minimum spanning tree of weight 10.
SOLUTION
minimumspanning tree is the following
AAAA
or
A minimumspanningtree
Tree
Vertices
 A(_,_)
 B(A,2)
 E(B,3)
 D(E,1)
 C(E,2)
 Z(D,2)
Remaining
Vertices
 B(A,2) C(A,3) D(_,_) E(_,_) Z(_,_)
 C(A,3) D(B,5) E(B,3) Z(_,_)
 C(E,2) D(E,1) Z(E,4)
 C(E,2) Z(D,2)
 Z(D,2)
ILLUSTRATION
minimum spanning tree
Add a Slide Title - 3
 Tree
Vertices
 A(_,_)
 B(A,2)
 C(A,3)
 E(C,2)
 D(E,1)
 Z(D,2)
 Remaining
Vertices
 B(A,2) C(A,3) D(_,_) E(_,_) Z(_,_)
 C(A,3) D(B,5) E(B,3) Z(_,_)
 D(B,5) E(C,2) Z(_,_)
 D(E,1) Z(E,4)
 Z(D,2)
ILLUSTRATION
minimum spanning tree
Grady approach prim's spanning tree

Grady approach prim's spanning tree

  • 1.
  • 2.
     An algorithmis designed to achieve optimum solution for a given problem. In greedy algorithm approach, decisions are made from the given solution domain. As being greedy, the closest solution that seems to provide an optimum solution is chosen.  Greedy algorithms try to find a localized optimum solution, which may eventually lead to globally optimized solutions. However, generally greedy algorithms do not provide globally optimized solutions. Greedy Algorithm Approach
  • 3.
    s  Most networkingalgorithms use the greedy approach. Here is a list of few of them −  Travelling Salesman Problem  Prim's Minimal Spanning Tree Algorithm  Kruskal's Minimal Spanning Tree Algorithm  Dijkstra's Minimal Spanning Tree Algorithm  Graph - Map Coloring  Graph - Vertex Cover  Knapsack Problem  Job Scheduling Problem  There are lots of similar problems that uses the greedy approach to find an optimum solution. Examples
  • 4.
     Example: UsePrim’s algorithm to find a minimum spanning tree in the following weighted graph. Use alphabetical order to break ties. B A 2 Prim's Minimal Spanning Tree Algorithm
  • 5.
     Prim’s algorithmwill proceed as follows. First we add edge {d, e} of weight1.  Next, we add edge {c, e} of weight 2. Next, we add edge {d, z} of weight 2.  Next, we add edge {b, e} of weight 3. And finally, we add edge {a, b} of weight 2.  This produces a minimum spanning tree of weight 10. SOLUTION
  • 6.
    minimumspanning tree isthe following AAAA or
  • 7.
    A minimumspanningtree Tree Vertices  A(_,_) B(A,2)  E(B,3)  D(E,1)  C(E,2)  Z(D,2) Remaining Vertices  B(A,2) C(A,3) D(_,_) E(_,_) Z(_,_)  C(A,3) D(B,5) E(B,3) Z(_,_)  C(E,2) D(E,1) Z(E,4)  C(E,2) Z(D,2)  Z(D,2) ILLUSTRATION minimum spanning tree
  • 8.
    Add a SlideTitle - 3  Tree Vertices  A(_,_)  B(A,2)  C(A,3)  E(C,2)  D(E,1)  Z(D,2)  Remaining Vertices  B(A,2) C(A,3) D(_,_) E(_,_) Z(_,_)  C(A,3) D(B,5) E(B,3) Z(_,_)  D(B,5) E(C,2) Z(_,_)  D(E,1) Z(E,4)  Z(D,2) ILLUSTRATION minimum spanning tree