2

alt text

can any one plz help me how to Find the MST using the PRIM algorithm. Highlight the edges of the MST and write the sequence in which the nodes are added to the MST.. thanks

5
  • 1
    What part of Prim's algorithm do you not understand? Commented Dec 30, 2010 at 19:38
  • yes i understand the prims algorithm but in non directed grapgh. Commented Dec 30, 2010 at 20:12
  • 1
    directed graph is a problem for me here. Commented Dec 30, 2010 at 20:12
  • 1
    @Programming_Kills Why didn't you mention that important detail in the question? See this. Commented Dec 30, 2010 at 20:24
  • I wrote a tutorial about how to implement prim's algorithm in c++ you can check it out maybe that will help: cedricve.me/2012/05/15/c-prims-algorithm Commented May 15, 2012 at 22:16

1 Answer 1

4

Quoting The Directed Minimum Spanning Tree Problem:

  1. Discard the arcs entering the root if any; For each node other than the root, select the entering arc with the smallest cost; Let the selected n-1 arcs be the set S.
  2. If no cycle formed, G(N,S) is a MST. Otherwise, continue.
  3. For each cycle formed, contract the nodes in the cycle into a pseudo-node (k), and modify the cost of each arc which enters a node (j) in the cycle from some node (i) outside the cycle according to the following equation.
    c(i,k)=c(i,j)-(c(x(j),j)-min_{j}(c(x(j),j)) here c(x(j),j) is the cost of the arc in the cycle which enters j.
  4. For each pseudo-node, select the entering arc which has the smallest modified cost; Replace the arc which enters the same real node in S by the new selected arc.
  5. Go to step 2 with the contracted graph.

The key idea of the algorithm is to find the replacing arc(s) which has the minimum extra cost to eliminate cycle(s) if any. The given equation exhibits the associated extra cost.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.