Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
A grid has 8 rows and 6 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. 12
- B. 14
- C. 15
- D. 8
Correct answer: B. 14
A BFS over open cells gives 14 moves, the detour forced by the walls. The Manhattan distance 12 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
- A tree on the vertices B, N, P, Q, W, Z has the arcs B→W, N→B, P→N, B→Z, B→Q (each undirected edge is directed as shown). You may reverse…
- An undirected graph has the vertices C, F, M, N, Q, V, X, Z and the edges V–M, V–C, V–N, F–M, F–C, X–Z, X–Q, X–M, Z–M, Z–N, Q–M, M–C. What…
- A grid has 7 rows and 7 columns (top to bottom; '.' open, '#' blocked): .....#. .#..##. ....... .###... ....... #...... ....#.. You may…
- An undirected graph has the vertices G, I, R, U, Y and the edges I–U, Y–G, Y–U, G–U, R–U. What is its chromatic number, the least number…
- A tree has the vertices B, E, F, G, N, O, Q, R, S, V and the edges F–V, F–O, F–Q, Q–G, F–S, O–E, V–R, E–B, S–N. A set D dominates the tree…
- Two unmarked jugs hold 6 litres and 7 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…