GATE / CS ARCHIVE

GATE CSE 2014 SET 3 / QUESTION 13

GATE CSE 2014 Set 3 Q13

Algorithms · Graph Algorithms · Full GATE CSE 2014 Set 3 paper

GATE 2014 Set 3, Q13 1 mark · NAT
Report issue

Graph Algorithms

Question 13, GATE 2014: The undirected graph consists of two 3×3 square grids, each with horizontal and vertical edges only between adjacent grid vertices. Label their vertices L(r,c) and R(r,c), rows and columns 1…3 from top-left. Add connector v with edges L(3,3)−v−R(3,1), a pendant vertex u attached only to v, and pendant w attached only to R(2,3). Recursive DFS starts at an unspecified vertex and calls visit only after confirming the neighbor is unvisited. Find the maximum possible call-stack depth, including the initial call.
Tap to enlarge
Answer & solution

Official answer: 19

Step 1: Active DFS calls form a simple path because an already visited vertex is never recursively called. Conversely, a desired simple path can be followed first by a suitable starting vertex and neighbor order. Step 2: A path spanning both grids must pass through connector v using its two grid edges; it cannot also visit pendant u without revisiting v. It uses at most nine left-grid vertices. Step 3: On the right, color the 3×3 grid like a checkerboard. A Hamilton path through all nine vertices starting at R(3,1), in the five-vertex color class, must end in that same color class. The pendant w attaches at R(2,3), in the opposite class, so a path entering at R(3,1) cannot include all nine grid vertices and then w. The right side contributes at most nine vertices including w. Step 4: Thus a spanning path has at most 9+1+9=19 vertices. Paths not spanning both grids are shorter, even with pendant leaves. Step 5: Attain 19 by snaking through all left vertices from L(1,1) to L(3,3), crossing v, then snaking through all right vertices from R(3,1) to R(1,3). DFS can follow this path before exploring unused pendants. The maximum depth is 19.

Original paper, page 56 · Answer key