0

enter image description here

Apply the Dijkstra/Prim Minimum Spanning Tree algorithm (not Shortest Paths) on the following graph starting at vertex a.

enter image description here

enter image description here I'm not too sure how I would get started with filling in those charts. This is a question for an exam practice so I want to work on it and understand it. Can someone please help me on how to get started with filling in the charts please?

I would appreciate any informative help. Thanks everyone.

V G
  • 18,822
  • 6
  • 51
  • 89
  • This is the second image as I don't have enough reputation to post more than 2: http://i.imgur.com/0gcdeMV.png Hope someone can help me! – user3010923 Nov 21 '13 at 19:22

1 Answers1

0

Since there are 7 vertices (you could also infer this from the chart), there will be 7 iterations. Start with phase 0 and fill in the distance of all immediate neighbors adjacent to your starting point. All those not directly connected to your starting point will be 'infinity' distance. From there, you should just be able to follow the algorithm.

orpheus
  • 479
  • 1
  • 7
  • 20
  • But from 0, do I go to C or D? Because the weights are 5 and 6? So do I have to go to the lower weight first or? Can you just give a few examples with the vertices given please? – user3010923 Nov 21 '13 at 19:37
  • 1
    How does the algorithm proceed? There are good examples available on YouTube if you're just confused about the algorithm itself. I'm assuming this is a class assignment, so I will not answer your question directly, but at each phase Dijkstra's selects the path with the lowest weight. – orpheus Nov 21 '13 at 19:43
  • It is not an assignment, this is simply exam prep question for an exam that I have late next week so I want to do all the practice questions and this one was the one I got stuck on. – user3010923 Nov 21 '13 at 19:44
  • I'm also confused with the actual charts like TREE and MIN_WT. Like can you just tell me how I would find the values for say the first one: a 0 for tree ? I understand there are tutorials on youtube but it's not really the algorithm that I am confused with , it's the charts I am given and how / what information I am supposed to fill them out with. I'm not asking for an answer to the whole thing as I want to learn and understand it myself as well. I'm only asking for you to explain it for possibly for the first phases for each of the charts if possible. Thanks bud. – user3010923 Nov 21 '13 at 19:48
  • Well for MIN_WT, your phase 0 should be obvious. (a) has only 2 neighbors and at the current iteration, all paths are optimal. I'm not 100% sure about the TREE chart, but I'm assuming it's just asking for the vertex path which for phase 0 would be from d to a (d->a) and c to a (c->a). For phase 1, you would select the lowest weight edge (a->c) and update all neighbors adjacent to (c), but including the weight from (a) to (c)'s neighbor. On MIN_WT, (a->e) would be 14, and your TREE would be (a->c->e) etc. Since there's no endpoint, you won't end up with a shortest path. You'll have a MST. – orpheus Nov 21 '13 at 19:57
  • So I'm assuming phase 0 for A would be an X in the MIN_WT? And an X for the whole diagonal? Can you confirm or let me know if this is incorrect? Thank you for your quick response too wes.. – user3010923 Nov 21 '13 at 20:00
  • Typically the convention is 0, not X. Also, there is no diagonal because you're not comparing each vertex to another vertex (shortest path from any vertex to another), you're looking for a minimum spanning tree. Hence, there will be no diagonal. – orpheus Nov 21 '13 at 20:06
  • So under phase 1 A, would I write 5? You mention for phase 1 , you would select the lowest weight edge which is a->c but how would that data be inputted into the chart? – user3010923 Nov 21 '13 at 20:06
  • I think I've made a mistake in my explanation somewhere. Give me just a minute. – orpheus Nov 21 '13 at 20:08
  • Actually, maybe I didn't. You're picking an arbitrary point (it's already picked for you as (a)) and you're looking for the shortest distance from (a) to all vertices on the graph (which will prevent a circuit). That gives you a MST. Since it's from (a) to all vertices, you won't need to make a distinction in the MIN_WT chart because you can just assume that it's from (a->whatever). So yes, you would just write '5'. – orpheus Nov 21 '13 at 20:12
  • So you're saying that the whole first row of A is 5? That doesn't make sense if you're trying to say that because how would that be the minimum weight for ALL the vertices ? I'm getting a bit confused now if that's what you meant.. sorry , can you just re-iterate what you said please. What I got for Phase 0 A is 0, Phase 1 A is 5 . I'm still a tad bit confused now. Hope you can respond to this, thanks Wes. – user3010923 Nov 21 '13 at 20:16
  • Sorry, I misread your question. No, you would write 0 all the way across because there is no cost to travel from (a) to itself (in this situation). You would write '5' in (c) and that won't change in any iteration because it's the lowest cost from (a->c). If there were an opportunity for a lower cost from (a->d->c), you would have picked (d) before (c) and arrived at that conclusion. – orpheus Nov 21 '13 at 20:20
  • You're saying write 0 in the diagonal or in the complete A row? – user3010923 Nov 21 '13 at 20:25
  • The complete (a) row. Like I said, there is no diagonal because you're never going to compare (b) to (b) or (c) to (c). You're not examining ALL shortest paths, you're just looking for a Minimum Spanning Tree starting from (a). – orpheus Nov 21 '13 at 20:27
  • But that is not true from A->C or A->D ? So how is the first row completely 0's? – user3010923 Nov 21 '13 at 20:33
  • You're always going to assume it's from (a) no matter what cell you're writing your answer in. (a) is your starting point and every other point on the graph is an endpoint (shortest distance from (a) to that point). – orpheus Nov 22 '13 at 02:34
  • so for the MIN_WT what would be the b value of phase 0? I just want to get the pattern of this before actually solving the rest of the values myself since what you wrote earlier was a bit confusing. Hope you can respond back to this soon. Thanks for your help. – user3010923 Nov 23 '13 at 06:28
  • Sorry! I really should get on SO more. Your value for (b) at phase 0 would be infinite. – orpheus Nov 23 '13 at 21:30
  • What do you mean infinity? I'm pretty sure that won't be a proper response for that graph for the real test lol. – user3010923 Nov 23 '13 at 21:38
  • It is. You don't "know" the shortest path from (a) to (b) because (a) is not directly connected to (b). The convention is to use an infinity symbol to represent that. – orpheus Nov 23 '13 at 21:43
  • So in B phase 0, is phase 0 corresponding to a? Because you talk about a not being directly connected to b. So does that mean phase 1 in B corresponds to itself (b)? – user3010923 Nov 23 '13 at 21:48
  • Phase 0 is in respect to vertex A, yes. Your only known values are costs from (a->d) and (a->c). You will not update your cost from (a->b) until you reach either vertex (e) or (f) (Notice that those two vertices are the only ones that are directly connected to (b).) – orpheus Nov 23 '13 at 21:52
  • So value for (b) at phase 1 would be 0 and at phase 2 would be infinity? – user3010923 Nov 23 '13 at 21:53
  • Not necessarily. It depends on how many phases it takes you to get to (e) or (f). This video might help clarify, but remember that you will need to include every vertex on the graph (which is the difference between a shortest path algorithm and a minimum spanning tree algorithm): https://www.youtube.com/watch?v=UG7VmPWkJmA – orpheus Nov 23 '13 at 21:58