Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A grid has 5 rows and 8 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. 14
- B. 7
- C. 11
- D. 13
Correct answer: D. 13
A BFS over open cells gives 13 moves, the detour forced by the walls. The Manhattan distance 11 ignores walls, and allowing diagonal moves gives 7.
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
- An undirected graph on 5 vertices has the edges T–X, X–L, X–B, L–B, L–N, B–N. How many simple paths (no repeated vertex) go from T to N?…
- An undirected graph has the vertices D, E, H, J, M, P and the edges P–E, P–H, P–J, E–H, E–D, M–J, M–D. In how many ways can each vertex be…
- An undirected graph has the vertices A, B, F, I, J, P and the edges I–A, I–J, I–B, A–P, A–F, J–P, J–F, P–B. In how many ways can each…
- A directed acyclic graph has the vertices A, E, K, L, M, N and the directed edges L→A, K→N, E→K, L→E, M→N, L→K, M→E, E→N, L→N. How many…
- A directed weighted graph has the arcs u→v (weight): J→I (6), I→J (1), I→R (3), I→B (5), Q→I (2), Q→E (4), R→J (12), R→I (10), R→Q (2)…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {1, 5, 6} and s ≤ the pile size. The player who…