Question

Describe an algorithm to test whether a given directed graph is a tree. Hint: Modify topological...

Describe an algorithm to test whether a given directed graph is a tree. Hint: Modify topological sort.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. Find the vertex with only outgoing edges.
  2. Compute in-degree for each of the vertex present in the directed graph and initialize the count of visited nodes as 0.
  3. Pick all the vertices with in-degree as 0 and add them into a queue,  If you encounter an already visited vertex, it's not a tree.

4. Remove a vertex from the queue and then  

- Increment count of visited nodes by 1.

-Decrease in-degree by 1 for all its neighboring nodes.

-If in-degree of a neighboring nodes is reduced to zero, then add it to the queue.

5.  Repeat Step 4 until the queue is empty, if you're done and there are unexplored vertices, it's not a tree - the graph is not connected.

6. Otherwise, it's a tree.

Add a comment
Know the answer?
Add Answer to:
Describe an algorithm to test whether a given directed graph is a tree. Hint: Modify topological...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT