Skip to main content

GATE CSE 2014Algorithms › Graph AlgorithmsVerified

GATE CSE 2014 PYQ: Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a…

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 _________.

GATE CSE 2014 Graph Algorithms diagram: Suppose depth first search is executed on the graph below st

    Answer

    19

    Approach

    The recursion depth of DFS at any moment is the length of the current call stack, which corresponds to a simple path from the start vertex. Hence the maximum possible recursion depth is the number of vertices on a longest simple path in the graph.

    The maximum recursion depth is the maximum number of vertices on a simple path, and the graph admits a simple path with 19 vertices, so the answer is 19.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.