Exploring Template Algorithm & Min Spanning Trees

  • MHB
  • Thread starter evinda
  • Start date
  • Tags
    Algorithm
In summary: Clapping)In summary, the conversation discusses the concept of an invariant in an algorithm, specifically in the context of finding minimum spanning trees. The Template algorithm is introduced and it is explained that the algorithm ensures the set of vertices, A, is always a subset of a minimum spanning tree at each iteration. The definition of a secure edge for set A is also provided. The conversation then continues to discuss examples of applying the Template algorithm and how different choices can lead to different minimum spanning trees. The speaker also mentions other algorithms, such as Prim's and Kruskal's, that can be used to find secure edges without prior knowledge of the tree.
  • #1
evinda
Gold Member
MHB
3,836
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
  • #2
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.
 
  • #3
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)
 
  • #4
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)
 
  • #5
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: 61
  • #6
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: 68
  • #7
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)
 
  • #8
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: 65
  • #9
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: 63
  • #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)
 

Related to Exploring Template Algorithm & Min Spanning Trees

1. What is a template algorithm?

A template algorithm is a generic, reusable algorithm that can be applied to different types of data structures or problems. It is designed to be flexible and efficient, and can be customized based on the specific needs of the problem at hand.

2. How does a template algorithm work?

A template algorithm works by defining a general set of instructions and steps that can be applied to a variety of different situations. It uses placeholders or variables to represent specific data or operations, which can be filled in or modified as needed.

3. What is a minimum spanning tree?

A minimum spanning tree is a subset of edges in a connected, weighted graph that connects all the vertices with the minimum possible total edge weight. It is used to find the most efficient way to connect all the nodes in a network or to minimize the cost of a project.

4. How is a minimum spanning tree calculated?

There are several different algorithms that can be used to calculate a minimum spanning tree, such as Prim's algorithm, Kruskal's algorithm, or Boruvka's algorithm. These algorithms use different approaches, such as greedy or divide and conquer, to find the minimum spanning tree for a given graph.

5. What are some applications of minimum spanning trees?

Minimum spanning trees have various real-world applications, such as designing efficient transportation networks, creating communication networks, optimizing power grid systems, and clustering data in machine learning algorithms. They can also be used in computer science for data compression, image segmentation, and network routing.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
Back
Top