In a finite, simple graph, one can find the length of the shortest path between
ID: 3784463 • Letter: I
Question
In a finite, simple graph, one can find the length of the shortest path between two vertices u and v by performing a BFS, starting at u and continuing until encountering v, keeping track of the depth at which each vertex is first encountered. Assume that indices are used to order branching. Answer the following. If a strategy does not work, provide a graph of order at most five as an example of where it fails.
a. Will the BFS strategy work to find the longest path between u and v?
b. Will the BFS strategy work to find the longest cycle between u and v?
c. Will a DFS strategy work to find the longest path between u and v?
d. Will a DFS strategy work to find the longest cycle between u and v?
Explanation / Answer
a. yes, Breadth first search strategy will work to find longest path between u and v. Creating G0 is a simple process and only requires (V + E) time to iterate over all the edges and vertices to create our new graph and weight function. Topologically sorting the edges takes (V + E) since topological sort is done using a modification of the DFS algorithm. Finally, relaxing all the edges once only takes (E) time. Thus, the runtime is (V + E) overall.
So if positive edged weights are given then BFS strategy will work to find longest path between u to v in the given graph.
longest path In unweighted graph, the longest path is the path with most number of edges. With Breadth First, we always reach a vertex from given source using maximum number of edges.
b. Since finding a longest path is possible using BFS strategy then one can easily conclude that finding the longest cycle will also work for the given algorithm on a given graph. In undirected graphs, either Breadth First Search or Depth First Search can be used to detect cycle. In directed graph, only depth first search can be used.
c. Similarly in DFS algorithm just like BFS it is possible to find the longest path between u and v in a give graph.
We can specialize the DFS algorithm to find a path between two given vertices u and v.
i) Call DFS(G, u) with u as the start vertex.
ii) Use a stack S to keep track of the path between the start vertex and the current vertex.
iii) As soon as destination vertex z is encountered, return the path as the
contents of the stack
longest path In unweighted graph, the longest path is the path with most number of edges. With Depth First, we always reach a vertex from given source using maximum number of edges..
d. A graph has cycle if and only if we see a back edge during DFS. So we can run DFS for the graph and check for back edges.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.