Question: Question 1 : DFS and BFS in Graphs . . . . . . . . . . . . . . . . .

Question 1: DFS and BFS in Graphs .......................................... For the following graph problems, design linear time algorithms (i.e., running time \( O(|V|+|E|)\) or \( O(n+m)\) as we have been calling it). You should describe each algorithm in English, using around 2-3 bullets. Do not write code. You can use BFS and DFS as subroutines, without describing them. For each bullet, write down the running time.
In each case, assume that the graph is given to you as an adjacency list.
The goal of this question is for you to learn to think in terms of using standard graph algorithms as "primitives".
For DFS(u), the output will be a boolean array isReachable[], where isReachable[v] is true if \( v \) is reachable from \( u \) via a (directed) path and false otherwise. For BFS(u), the output will be an integer array dist [], where dist[v] denotes the minimum number of edges in a path from \( u \) to \( v \). dist [v] will be INFINITY if \( v \) is not reachable from \( u \).
(a)[5] Suppose \( G \) is an undirected graph, and let \( u v \) be an edge in \( G \). Determine if there is a cycle involving (i.e., containing) the edge \( u v \) in \( G \).
(b)[3] Suppose \( G \) is a directed graph and let \( u \) be one of the vertices. Let \( r \) be a given parameter. Determine if exist paths of length \(\leq r \) from \( u \) to every other vertex in \( G \).
Question 1 : DFS and BFS in Graphs . . . . . . .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!