Prim's algorithm-Minimum Spanning Tree

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Tree
Click For Summary

Discussion Overview

The discussion revolves around Prim's algorithm for finding a minimum spanning tree (MST) in a graph. Participants explore the application of the algorithm to a specific graph, discussing the steps involved, the tracking of vertex connections, and the implications of edge weights on the resulting tree.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant presents the algorithm and seeks validation of their application to a graph, asking which vertices to connect for the MST.
  • Another participant confirms the correctness of the approach and emphasizes the importance of tracking the predecessor nodes (p[v]) during the process.
  • A participant provides a detailed step-by-step application of the algorithm, identifying the edges that connect the vertices in the MST.
  • There is a discussion about whether the identified minimum spanning tree is unique, with participants considering scenarios where multiple edges have the same weight.
  • Some participants question if the method of constructing the MST based on edge weights will always yield the correct tree.
  • Concerns are raised about the potential for multiple valid trees when edges have equal weights, leading to different possible MSTs.

Areas of Agreement / Disagreement

Participants express uncertainty regarding the uniqueness of the minimum spanning tree and whether multiple configurations can exist based on edge weights. There is no consensus on whether the identified tree is the only one possible.

Contextual Notes

Participants note the importance of tracking predecessor nodes and the implications of edge weights on the construction of the MST. The discussion highlights the potential for ambiguity in cases of equal edge weights.

Who May Find This Useful

This discussion may be useful for students and practitioners interested in graph theory, algorithm design, and the practical application of Prim's algorithm in finding minimum spanning trees.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hi! (Mmm)

I am looking at Prim's algorithm:

Code:
Prim(G,w,v)

 for each u  ϵ V
      key[u]<-oo // the minimum of the weights of the edges,
                           that connect the vertex u with an other 
                           vertex of the tree
      p[u]<-∅
 key[v]<-0
 Q<-V // priority queue,the vertices are sorted,with respect to key[u]
 while Q≠∅
     u<-Εxtraction_of_minimum(Q)
     for each v ϵ adj[u]
          if v ϵ Q and w(u,v)<key[v] then
             p[v]<-u
             key[v]<-w(u,v)

and..I want to apply it at this graph:

View attachment 3111

These are the keys that I found:

View attachment 3112

Is it right,or have I done something wrong? (Thinking)

Which vertices do I have to connect now,to get a minimum spanning tree? (Thinking)
 

Attachments

  • prim.png
    prim.png
    5.7 KB · Views: 140
  • prim.png
    prim.png
    3.8 KB · Views: 149
Physics news on Phys.org
Hey! (Smile)

evinda said:
Is it right,or have I done something wrong? (Thinking)

It is right! (Nod)
Which vertices do I have to connect now,to get a minimum spanning tree? (Thinking)

Well, you were also supposed to track p[v] for every step.
p[v] identifies the node you were coming from when assigning the minimum weight.

Did you track p[v]? (Wondering)
Or can you otherwise still figure out what each p[v] should be? (Wondering)
 
evinda said:
Hi! (Mmm)

I am looking at Prim's algorithm:

Code:
Prim(G,w,v)

 for each u  ϵ V
      key[u]<-oo // the minimum of the weights of the edges,
                           that connect the vertex u with an other 
                           vertex of the tree
      p[u]<-∅
 key[v]<-0
 Q<-V // priority queue,the vertices are sorted,with respect to key[u]
 while Q≠∅
     u<-Εxtraction_of_minimum(Q)
     for each v ϵ adj[u]
          if v ϵ Q and w(u,v)<key[v] then
             p[v]<-u
             key[v]<-w(u,v)

and..I want to apply it at this graph:

https://www.physicsforums.com/attachments/3111

These are the keys that I found:

https://www.physicsforums.com/attachments/3112

Is it right,or have I done something wrong? (Thinking)

Which vertices do I have to connect now,to get a minimum spanning tree? (Thinking)

This problem is easy enough to do by hand. To find the minimal spanning tree, the process is always to find the minimum sized edge connecting a node that isn't already connected to the tree, until all the nodes are connected. Just keep a mental track of everything that is now connected.

So looking at the graph, the minimal node is 1, between "g" and "h".

The next minimal node is 2, between "g" and "f". Now f, g, h are connected.

The next minimal node is 2, between "c" and "i". Now f, g, h are connected, and c, i are connected.

The next minimal node is 4, connecting "c" with "f". Now c, f, g, h, i are connected.

The next minimal node is 4, connecting "a" with "b". Now c, f, g, h, i are connected, and a, b are connected.

The next minimal node is 7, connecting "c" with "d". Now c, d, f, g, h, i are connected, and a, b are connected. Notice we didn't use the 6, because g and i are already connected in the tree.

The next minimal node is 8, connecting "a" with "h". Now a, b, c, d, f, g, h, i are connected.

The next minimal node is 9, connecting "d" with "e". Now a, b, c, d, e, f, g, h, i are connected.

Now that everything is connected we have our minimal spanning tree (I'll leave you to draw it and to evaluate the minimal distance).
 
I like Serena said:
Well, you were also supposed to track p[v] for every step.
p[v] identifies the node you were coming from when assigning the minimum weight.

Did you track p[v]? (Wondering)
Or can you otherwise still figure out what each p[v] should be? (Wondering)

I found the following:

$$p[e]=d$$
$$p[h]=g$$
$$p[g]=f$$
$$p[d]=c$$
$$p[f]=c$$
$$p=c$$
$$p[c]=b$$
$$p=a$$

So..applying the algorithm,do we get this minimum spanning tree? (Thinking)

View attachment 3119
 

Attachments

  • spanning.png
    spanning.png
    4.3 KB · Views: 137
evinda said:
So..applying the algorithm,do we get this minimum spanning tree? (Thinking)

Yep! (Happy)

Did you notice that the number you had for each node, was actually the weight of edge that led to that node?
So you could construct the minimum spanning tree like that as well.

Would that always work? (Wondering)
 
I like Serena said:
Yep! (Happy)

Since I found these:

$$p[e]=d$$
$$p[h]=g$$
$$p[g]=f$$
$$p[d]=c$$
$$p[f]=c$$
$$p=c$$
$$p[c]=b$$
$$p=a$$

does this mean that this minimum spanning tree is the only one? (Thinking)
I like Serena said:
Did you notice that the number you had for each node, was actually the weight of edge that led to that node?
So you could construct the minimum spanning tree like that as well.

Would that always work? (Wondering)

So,if we have , for example, a node $u$ and the edges $(u,v)$, $(u,w)$ and $(u,r)$ and $w(u,v)< w(u,w)<w(u,r)$,then do we connect $u$ with $v$? (Thinking)
 
evinda said:
does this mean that this minimum spanning tree is the only one? (Thinking)

Why do you think so? (Wasntme)
So,if we have , for example, a node $u$ and the edges $(u,v)$, $(u,w)$ and $(u,r)$ and $w(u,v)< w(u,w)<w(u,r)$,then do we connect $u$ with $v$? (Thinking)

Yes.

Now suppose $w(u,v)= w(u,w)$, doesn't that give you 2 choices leading to different trees? (Wondering)
 
I like Serena said:
Why do you think so? (Wasntme)

I thought so,because I found specific $p[v], \forall v \in V$..So,could I also find other ones? (Thinking)
I like Serena said:
Yes.

Now suppose $w(u,v)= w(u,w)$, doesn't that give you 2 choice leading to different trees? (Wondering)

Yes! (Nod)
 
evinda said:
I thought so,because I found specific $p[v], \forall v \in V$..So,could I also find other ones? (Thinking)

Generally, yes, because $p[v]$ is selected to be the first neighbor with lowest weight. There might be other neighbors with the same weight.

In this particular example, there are no other ones though. (Wink)
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
8
Views
1K