Breadth First and Depth First Spanning Trees

  • Context: MHB 
  • Thread starter Thread starter andrew1
  • Start date Start date
  • Tags Tags
    Depth Trees
Click For Summary

Discussion Overview

The discussion revolves around constructing breadth first and depth first spanning trees for a given graph, focusing on the algorithms used for each method. Participants share their approaches and results, exploring the procedural steps involved in both algorithms.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the breadth first spanning tree construction using a queue, starting with vertex P and adding connected vertices in alphabetical order.
  • The same participant outlines the depth first spanning tree construction using a stack, also beginning with vertex P and pushing connected vertices in alphabetical order.
  • Another participant shares their own result for the breadth first spanning tree, stating they reached QSTUR as the last step before emptying the queue.
  • A subsequent reply confirms that the second participant's result matches their own implementation of the algorithm.

Areas of Agreement / Disagreement

Participants appear to agree on the procedural steps for both algorithms, but there is a lack of consensus on the final structure of the breadth first spanning tree, as one participant's result differs from the others.

Contextual Notes

Details regarding the specific graph structure and connections between vertices are not provided, which may affect the outcomes of the spanning tree constructions.

andrew1
Messages
20
Reaction score
0
Hi,

I'm currently stuck on how to construct a breadth first and depth first spanning tree for this graph, the algorithm that I'm following is somewhat ambiguous. I'd really appreciate if someone can provide an explanation on how I should go by doing this.

ThanksView attachment 2535
 

Attachments

  • fHhlAH4.jpg
    fHhlAH4.jpg
    56.7 KB · Views: 127
Physics news on Phys.org
Breadth first spanning tree:

In this method we use a queue (FIFO).

You first start with the vertex earliest in the alphabet. Which is vertex P. We add that to the queue.

Step1: queue = P, tree = vertex P

Currently, the front of the queue is P. **

We now have to add the next letter (in alphabetical order) to the end of the queue which is connected to the vertex at the front of the queue (which is P) **.

Step2: queue = PQ, tree = we have a line connecting P and Q

Then we repeat the same process, look for the next letter in alphabetical order, S in this case, which is connected to the vertex at the front of the queue (see ** above) which is still P until there are no other vertices that are connected to P.

So after repeating the steps above we realize that P doesn't connect to anything else. So we take P out of the queue.

We'll then have vertex Q at the start of the queue ***. We again check any vertices (in alphabetical order) connected to Q that is not already in the queue. R is the only one that is not already in the queue.

So we add R at the end of the queue.

Every time we add another vertex at the end of the queue, we draw a line between that and the vertex at the start of the queue.

When all the vertices has been added in the queue, we just need to delete the rest following the first in first out (FIFO) method (delete from vertex at the front of the queue until it's empty).Depth first spanning tree:

We again start at the vertex earliest in the alphabet.

We now use a stack (LIFO).

We push vertex P into the stack.

Step1: stack = P, tree = vertex P

Currently, the top of the stack is P. **

So we need to check which vertex is connected to the vertex at the top of the stack which is P (in alphabetical order). We can see that this is Q. So we push Q into the stack.

Step2: stack = PQ, tree = line connecting P and Q.

Currently, the top of the stack is Q. **

So we now need to check which vertex is connected to the letter at the top of the stack which is Q.

We can see that R is the earliest in the alphabet so we push R into the stack

Step3: stack = PQR, tree = line connecting P and Q, and line connecting Q and R.

Repeat the same process until all the letters has been pushed into the stack.

In the end we get:

Stack = PQRUTS

So we just have to pop everything out of the stack following last in first out (LIFO).

Stack:

PQRUTS
PQRUT
PQRU and so on until the stack is empty.*Assuming we do everything in alphabetical order.
 
Last edited:
Tried this myself the other night and got QSTUR as the last step in my breadth first spanning tree before taking out all the items from the queue, is this correct?
 
Yes, that is also what I got when I implemented the algorithm.
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 65 ·
3
Replies
65
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K