Graph Algorithms

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.