Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A grid has 8 rows and 7 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ..#.... .#..... ..#.##. .#....# .#..... ....#.# ...#... .#...#. Starting at the top-left cell, what is the minimum number of moves to reach the bottom-right cell, where a move goes to one of the four side-adjacent open cells?
- A. 13
- B. 16
- C. 15
- D. 8
Correct answer: C. 15
A BFS over open cells gives 15 moves, the detour forced by the walls. The Manhattan distance 13 ignores walls, and allowing diagonal moves gives 8.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (4), 1→3 (1), 2→3 (11), 2→4 (2), 2→5 (2), 3→1 (6), 3→2 (4), 4→2…
- A connected undirected graph has the vertices E, F, I, Q, S, Z and weighted edges (weights in brackets): E–I (3), F–E (8), Z–S (12), S–I…
- A directed weighted graph has the arcs u→v (weight): Z→G (12), G→Z (1), G→T (11), G→A (3), G→S (7), T→Z (11), T→M (1), A→Z (13), A→T (11)…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- An undirected connected graph on the vertices B, M, Q, R, U has the edges B–U, M–R, Q–R, M–Q, B–R, B–M, Q–U, B–Q. How many spanning trees…
- Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. LUL LRD RUU From a cell you may move to…