
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?

Re: Prim's algorithm
Think about what it means:
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.

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?

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 topdown 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.
So your final span tree:
A to B
A to C
A to D
with a total weight of 9.
You could repeat the same exercise by starting with any of the other nodes and it would be a similar tree, but the starting node would be the node you started with connected to the other 3 nodes. Note that this is only true if the above listed assumptions about the implementation not changing the tree if the distances are equal is true.

Re: Prim's algorithm
Thank you for your explanation