GATE CS 2014 Set 3 — Question 23
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+1 / -0MediumDFS TraversalGraphs (Data Structure)Programming & Data Structures
Programming & Data Structures → Graphs (Data Structure) → DFS Traversal
Last updated
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 _________.

Correct answer
19 to 19
Solution
In DFS, the recursion depth at any moment equals the number of vertices on the current chain of calls, which is a simple path in the graph. The maximum possible depth is therefore the number of vertices on the longest simple path, since a suitable start vertex and neighbour order lets DFS follow any simple path.The graph has 21 vertices: two grids (9 each), a middle vertex joining the bottom-right corner of the left grid to the bottom-left corner of the right grid, a pendant vertex above the middle vertex, and a pendant vertex attached to the middle-right vertex of the right grid.Count the vertices on the longest simple path.
- Pendant above the middle vertex. It has degree 1 and its only neighbour, the middle vertex, separates the two grids. A path containing it must end there, so it can visit only one grid: at most vertices. The longest path therefore avoids it.
- Upper bound. Colour each grid like a chessboard: the 4 corners and the centre (5 vertices) get one colour, the 4 edge-midpoints the other. A path inside the grid alternates colours, so a path through all 9 grid vertices must start and end at corners or the centre. A path that stays on one side of the middle vertex has at most vertices, so consider a path that crosses from one grid to the other; it enters the right grid at its bottom-left corner. If it also takes the right pendant, it must leave the grid at the middle-right vertex (an edge-midpoint), so it covers at most 8 right-grid vertices: . Without the right pendant it has at most vertices.
- The bound is reached. Start at the top-left vertex of the left grid and go through it row by row: top row left to right, middle row right to left, bottom row left to right. That ends at its bottom-right corner (9 vertices). Then take the middle vertex (1), enter the right grid at its bottom-left corner and go up the left column, then along the top row, down to the middle-right vertex, left to the centre, down to the bottom-middle vertex, and right to the bottom-right corner (9 vertices). Total .
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Graphs (Data Structure)
2026 Set 2 Q12The set T represents various traversals over binary tree. The set S represents the order of…2026 Set 2 Q19Consider the following three ANSI-C programs, P1, P2, and P3. P1 [code] P2 [code] **P3**…2026 Set 1 Q23Let be an odd number greater than 100. Consider a binary minheap with elements stored in an…2026 Set 1 Q24Consider a hash table that is initially empty. The hash table is maintained…2026 Set 1 Q27Consider the following C statements: [figure] Which of the following options is/are correct?