IAE Academy

GATE 2025 DA Q.65: solution and answer

GATE 2025 · DAQ.65 · 2 marks · NAT

Consider a directed graph , where and . Suppose the adjacency list of each vertex is in decreasing order of vertex number, and depth-first search (DFS) is performed at vertex 0. The number of vertices that will be discovered after vertex 50 is ______ (Answer in integer)

See the question in the paper

Answer and solution

ANSWER

The number of vertices discovered after vertex 50 is 75.

Official answer: 75Source: Official answer key, GATE 2025 DA (IIT Roorkee)

  1. Each vertex has edges only to and (those that exist in ). In decreasing order the adjacency list of is , so DFS always tries first.

  2. DFS from therefore descends the even chain . Vertex has no out-edges, so DFS backtracks.

  3. The even vertices discovered after on this descent are , which is vertices.

  4. Back at : its list is . Vertex is already discovered, and is not, so is discovered. Its neighbours (, and which does not exist) give nothing new, so DFS returns to and then to .

  5. At every even vertex on the way back, the first neighbour is already discovered and the second neighbour is not, so is discovered. Its neighbours and are already discovered, so DFS returns. This happens at .

  6. Hence the odd vertices are discovered one by one during the backtrack, in that order. All of them are discovered after the descent has passed , so all odd vertices come after vertex .

  7. Vertices discovered after : .

KEY IDEA

With adjacency lists in decreasing order, DFS first runs straight down the even chain to 100, then discovers each odd vertex while backtracking, so the discovery order is fixed by 'always take the largest neighbour first'.

WATCH OUT FOR

Counting only the even vertices 52 to 100 (25), or forgetting that the odd vertices below 50 (1 to 49) are also discovered after 50, because they are only reached during backtracking, long after the descent passed 50.

From the GATE 2025 DA paper. Every question of this paper · Download the full paper · All 28 Graph algorithms questions, with notes

More Graph algorithms questions