Describe an algorithm to test whether a given directed graph is a tree. Hint: Modify topological sort.
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.
Describe an algorithm to test whether a given directed graph is a tree. Hint: Modify topological...
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. (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
(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 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...
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 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 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
Consider the following directed graph for each of the problems: 1. Perform a breadth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Show the breadth-first search tree that is generated. 2. Perform a depth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Classify each edge as tree, back or cross edge. Label each vertex with its start and finish time. 3. Remove all the...
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.)