Question
Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first checking that the vertex has not been visited earlier. Then the maximum possible recursion depth (including the initial call) is _____.
Official answer and solution
- Official answer
- 19
- From
- Official GATE 2014 answer key
Solution
Determine the maximum recursion depth by finding the longest simple path in the graph.
-
Graph Structure and Vertex Count:
- Left component: grid of vertices.
- The bottom-right vertex of the left grid connects via an edge to a bridge path.
- Bridge path: a bottom vertex with a degree-1 pendant vertex above it ( vertices).
- Right component: grid of vertices.
- Pendant vertex on the right: degree-1 vertex connected to the middle-right vertex of the right grid ( vertex).
-
DFS Recursion Depth and Simple Paths:
The maximum possible recursion depth in a DFS traversal without backtracking corresponds to the number of vertices in the longest simple path in the graph. -
Analyzing Endpoints of a Simple Path:
- A simple path has exactly two endpoints (start and finish).
- The left grid has only ONE edge connecting it to the rest of the graph (a bridge edge at its bottom-right vertex). Once a simple path enters the left grid, it cannot exit without repeating vertices. Therefore, any simple path visiting the left grid must either start or end in the left grid.
- This leaves only ONE endpoint available for the remainder of the graph.
- The remainder of the graph contains two distinct degree-1 pendant vertices:
- The middle upright pendant vertex.
- The rightmost pendant vertex.
- To visit a degree-1 vertex in a simple path, that vertex must be an endpoint of the path. Since there is only one remaining endpoint, a simple path can visit at most ONE of these two degree-1 vertices.
- Furthermore, if the path visits the middle pendant vertex as an endpoint, it cannot reach the right grid. Thus, to maximize vertices visited, the path must skip the middle pendant vertex and continue to the right grid, ending at the rightmost pendant vertex.
- In the right grid, a Hamiltonian path entering at the bottom-left and exiting to the right pendant at the middle-right vertex can visit 8 of the 9 grid vertices (or all 9 if properly routed), but at least two vertices overall in the graph cannot be included in any single simple path.
-
Therefore, the longest simple path can visit at most vertices.
Hence, the maximum recursion depth is .
19
Assuming DFS can visit all 21 vertices in a single recursive chain without backtracking.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 3
- Question
- 23 of 65, printed as CS Q.13
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.