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
  • Student Name: Q5-15 pts) Run the Depth First Search algorithm on the following directed acyclic graph...

    Student Name: Q5-15 pts) Run the Depth First Search algorithm on the following directed acyclic graph (DAG) and determine a topological sort of the vertices as well as identify the tree edges, forward edges and cross edges 3 5 0 2 4 7

  • Q6: 20 pts) For the directed graph assigned to you, run the Depth First Search algorithm....

    Q6: 20 pts) For the directed graph assigned to you, run the Depth First Search algorithm. (a) Clearly show the order in which the vertices are pushed and popped. (b) Clearly write the list of edges and their classification into one of the four categories as determined using DFS. (c) Determine whether the directed graph assigned to you is a DAG or not? If it is a DAG. write the topological sort of the vertices.

  • 3. Apply Topological sort algorithm on the following graph. Then, draw the sorted graph. 11 marvel

    3. Apply Topological sort algorithm on the following graph. Then, draw the sorted graph. 11 marvel

  • (A) Consider the following algorithm for computing a topological sort of a DAG G: add the...

    (A) Consider the following algorithm for computing a topological sort of a DAG G: add the vertices to an initially empty list in non-decreasing order of their indegrees. Either argue that the algorithm correctly computes a topological sort of G, or provide an example on which the algorithm fails. (B) Can the number of strongly connected components of a graph decrease if a new edge is added? Why or why not? Can it increase? Why or why not? (C) What...

  • Apply the topological sort algorithm to the graph. Follow the algorithm in you textbook and clearly...

    Apply the topological sort algorithm to the graph. Follow the algorithm in you textbook and clearly show the content of the three lists: resultList, noIncoming and remainingEdges after each iteration. 2. Apply the topological sort algorithm to the graph below. Follow the algorithm in you textbook and clearly show the content of the three lists: resultList, nolncoming and remainingEdges after each iteration GraphTopologicalSort (graph) { resultList = empty list of vertices no Incoming = list of all vertices with no...

  • Which of the following is TRUE about Topological Sorting? Topological Sort can be used as a...

    Which of the following is TRUE about Topological Sorting? Topological Sort can be used as a subroutine to find shortest paths in a weighted DAG in time O(V+E); in particular, the time does not depend on the magnitudes of the weights on the edges, and the weights on the edges may be negative. A Topological Sort algorithm sorts the nodes of an arbitrary directed graph G in an order that is consistent with all the paths in G, that is...

  • 3.3. Run the DFS-based topological ordering algorithm on the following graph. Whenever you have a...

    3.3. Run the DFS-based topological ordering algorithm on the following graph. Whenever you have a choice of vertices to explore, always pick the one that is alphabetically first. (a) Indicate the pre and post numbers of the nodes. (b) What are the sources and sinks of the graph? (c) What topological ordering is found by the algorithm? (d) How many topological orderings does this graph have? 3.3. Run the DFS-based topological ordering algorithm on the following graph. Whenever you have...

  • Consider a directed acyclic graph G = (V, E) without edge lengths and a start vertex...

    Consider a directed acyclic graph G = (V, E) without edge lengths and a start vertex s E V. (Recall, the length of a path in an graph without edge lengths is given by the number of edges on that path). Someone claims that the following greedy algorithm will always find longest path in the graph G starting from s. path = [8] Ucurrent = s topologically sort the vertices V of G. forall v EV in topological order do...

  • 1. (5 pts) Perform topological sorting on the directed graph below. Show two orderings that can...

    1. (5 pts) Perform topological sorting on the directed graph below. Show two orderings that can result, such that no letter is in the same position in each ordering: e.g., D cannot be in the 3rd position in both orderings; if the algorithm does not finish, show the part of the graph that remains unprocessed (and explain why it remains unprocessed). Order 1 Order 2

  • Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve...

    Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve this problem under the assumption that the graph is strongly connected.)

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