MHB What is the Template Algorithm for Minimum Spanning Trees?

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Algorithm
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

According to my notes:

Template algorithm
The algorithm keeps the invariant :
"before each iteration,the set $A$ of vertices is a subset of some minimum spanning trees" at each step,where $A$ is an initial set of vertices.

Code:
Template algorithm(G)
   A<-∅
   while A isn't a connected component
           we define an edge (u,v),that is secure for A
           A<-A U {(u,v)} 
   return A

Definition:
The edge $(u,v)$ is called secure for the set $A$,if it can be added to it,without the violation of the invariant.Could you explain me the following sentence? (Thinking)

The algorithm keeps the invariant :
"before each iteration,the set A of vertices is a subset of some minimum spanning trees" at each step,where $A$ is an initial set of vertices.
 
Physics news on Phys.org
evinda said:
Definition:
The edge $(u,v)$ is called secure for the set $A$,if it can be added to it,without the violation of the invariant.Could you explain me the following sentence? (Thinking)

The algorithm keeps the invariant :
"before each iteration,the set A of vertices is a subset of some minimum spanning trees" at each step,where $A$ is an initial set of vertices.

Hey evinda! (Wink)

An invariant is a statement (or property, or proposition) that holds true at each iteration of a loop.

In this case the statement is that A is a subset of a minimum spanning tree.
Initially A is an empty set, which satisfies the statement.
When we add an edge that belong to a minimum spanning tree, the statement will still be satisfied. So that edge was what they call secure.
 
I like Serena said:
Hey evinda! (Wink)

An invariant is a statement (or property, or proposition) that holds true at each iteration of a loop.

In this case the statement is that A is a subset of a minimum spanning tree.
Initially A is an empty set, which satisfies the statement.
When we add an edge that belong to a minimum spanning tree, the statement will still be satisfied. So that edge was what they call secure.

I understand...Thanks a lot! (Smile)
Could you also give me an example,at which I can apply the template algorithm? (Thinking)
 
The algorithm,that is in my notes,is the following:

Code:
Template algorithm(G)
   A<-∅
   while A isn't a connected tree
           we define an edge (u,v),that is secure for A
           A<-A U {(u,v)} 
   return A

I wrote component,instead of tree,in the first post.. (Blush) (Wasntme)
 
evinda said:
I understand...Thanks a lot! (Smile)
Could you also give me an example,at which I can apply the template algorithm? (Thinking)

Sure!

How about the following graph. (Blush)

View attachment 3113
evinda said:
I wrote component,instead of tree,in the first post.. (Blush) (Wasntme)

Ooooh! (Speechless)
 

Attachments

  • MinSpanTree.png
    MinSpanTree.png
    2.5 KB · Views: 93
I like Serena said:
Sure!

How about the following graph. (Blush)

View attachment 3113

Do we always choose the edge,with the minimum weight? (Thinking)

So..is this a minimum spanning tree? (Thinking)

View attachment 3115
 

Attachments

  • min.png
    min.png
    2.2 KB · Views: 101
evinda said:
Do we always choose the edge,with the minimum weight? (Thinking)

That is one of the ways to build a minimum spanning tree. (Happy)
So..is this a minimum spanning tree? (Thinking)

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

Yep! (Nod)

Is it unique?
If not, how many alternatives are there? (Wondering)Anyway, how would you apply the Template algorithm? (Wondering)
 
I like Serena said:
That is one of the ways to build a minimum spanning tree. (Happy)
Nice! (Yes)
I like Serena said:
Is it unique?
If not, how many alternatives are there? (Wondering)

No,it isn't unique.. (Shake) There are two alternatives..The other one is this:

View attachment 3116

Or am I wrong? (Thinking)

I like Serena said:
Anyway, how would you apply the Template algorithm? (Wondering)

Α={}
A isn't a connected tree
Α={(Α,Β)}
A isn't a connected tree
Α={(Α,Β),(Β,Ε)}
A isn't a connected tree
Α={(Α,Β),(Β,Ε),(E,C)}
A isn't a connected tree
A={(Α,Β),(Β,Ε),(E,C),(C,F)}
A isn't a connected tree
A={(Α,Β),(Β,Ε),(E,C),(C,F),(A,D)}

So,a minimum spanning tree is the tree with the edges:
(Α,Β),(Β,Ε),(E,C),(C,F),(A,D)Am I right? (Thinking)
 

Attachments

  • min.png
    min.png
    2.3 KB · Views: 109
evinda said:
No,it isn't unique.. (Shake) There are two alternatives..The other one is this:

Or am I wrong? (Thinking)

Yes. That is also a minimum spanning tree!
... but I think there is also a third one. (Wondering)
Α={}
A isn't a connected tree
Α={(Α,Β)}
A isn't a connected tree
Α={(Α,Β),(Β,Ε)}
A isn't a connected tree
Α={(Α,Β),(Β,Ε),(E,C)}
A isn't a connected tree
A={(Α,Β),(Β,Ε),(E,C),(C,F)}
A isn't a connected tree
A={(Α,Β),(Β,Ε),(E,C),(C,F),(A,D)}

So,a minimum spanning tree is the tree with the edges:
(Α,Β),(Β,Ε),(E,C),(C,F),(A,D)Am I right? (Thinking)

Yup!
That is one way to execute the Template algorithm.

Could you also do it in another way? (Thinking)
(Other than making a different choice for the 4-edge.)
 
  • #10
I like Serena said:
Yes. That is also a minimum spanning tree!
... but I think there is also a third one. (Wondering)
Could you also do it in another way? (Thinking)
(Other than making a different choice for the 4-edge.)

I didn't find an other spanning tree with weight $16$.. (Sweating)

For which edge could I make a different choice? (Thinking)
 
  • #11
evinda said:
I didn't find an other spanning tree with weight $16$.. (Sweating)

Well... node (d) has 3 edge that each have weight 4.
I think you can pick either one (but only one) of them...
For which edge could I make a different choice? (Thinking)

All of them.

For executing the Template algorithm, you can pick any order you like.
Just as long as you only add edges that actually belong to specific minimum spanning tree. Those are secure.

However, to find secure edge without knowing the tree already, you need a more specific algorithm.
Like Prim's algorithm, or Kruskal's algorithm. (Thinking)
 
  • #12
I like Serena said:
Well... node (d) has 3 edge that each have weight 4.
I think you can pick either one (but only one) of them...

A ok.. (Nod) So,this is an other spanning tree,right?

View attachment 3120

In this case, we execute the Template algorithm,like that:

A={}
A isn't a connected tree
A={(A,B)}
A isn't a connected tree
A={(A,B),(B,D)}
A isn't a connected tree
A={(A,B),(B,D),(B,E)}
A isn't a connected tree
A={(A,B),(B,D),(B,E),(E,C)}
A isn't a connected tree
A={(A,B),(B,D),(B,E),(E,C),(C,F)}

Right? (Thinking)

I like Serena said:
All of them.

For executing the Template algorithm, you can pick any order you like.
Just as long as you only add edges that actually belong to specific minimum spanning tree. Those are secure.

However, to find secure edge without knowing the tree already, you need a more specific algorithm.
Like Prim's algorithm, or Kruskal's algorithm. (Thinking)

I understand! (Sun)
 

Attachments

  • tree3.png
    tree3.png
    2.5 KB · Views: 101
  • #13
evinda said:
A ok.. (Nod) So,this is an other spanning tree,right?

Right? (Thinking)

I understand! (Sun)

Yep, yep, and good! (Mmm)
 
  • #14
I like Serena said:
Yep, yep, and good! (Mmm)

Great! Thanks a lot! (Cool)
 

Similar threads

Replies
8
Views
2K
Replies
3
Views
2K
Replies
2
Views
2K
Replies
2
Views
3K
Replies
5
Views
2K
Replies
11
Views
3K
Back
Top