Prim's algorithm

• October 8th, 2010, 02:47 AM
mingming8888
Prim's algorithm
For prim's algorithm, if a vertice have the same weight to other vertices, so which one will it be choosen to put in the tree?
For example

A to B is 3
A to C is 3
A to D is 3
B to C is 3
B to D is 3
C to D is 3

How will be a minimal spanning tree be form?
• October 8th, 2010, 11:43 PM
helloworld922
Re: Prim's algorithm

It means that all the path to that point takes the same cost. So, it doesn't matter which path you choose. It's like saying do I want to go north 1 mile, then west 1 mile, or do I want to go west 1 mile and then north 1 mile? They're different paths, but the exact same distances.
• October 9th, 2010, 01:00 AM
mingming8888
Re: Prim's algorithm
yea, they have the same distance, so Prim's algorithm will choose which path first? If we start the tree from A, so the next one is B, C or D?
• October 9th, 2010, 09:32 AM
helloworld922
Re: Prim's algorithm
Without looking at a specific implementation, it's undetermined unless you knew which node the algorithm started looking from. Also, I would probably suspect that in general an implementation wouldn't change the span tree unless the distance was less than the current known shortest distance.

So, let's pretend the implementation looks top-down in the list.

A to B is 3
A to C is 3
A to D is 3
B to C is 3
B to D is 3
C to D is 3

Start from A, and look at all connected nodes.

The current span tree is A to B, A to C, and A to D with a total span weight of 9. Then it would look at B. B to C is an additional 3 to make 6, don't change the tree. B to D is also an additional 3, so don't change the tree. Look at node C and you'll find the similar condition between C and D.