Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A grid has 6 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. 9
- C. 15
- D. 12
Correct answer: A. 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 9.
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
- Two unmarked jugs hold 5 litres and 9 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A directed graph with no directed cycles has arcs u→v (weight) : X→E (-1), X→A (-3), X→J (8), E→G (-1), A→G (7), A→J (0), G→J (-3)…
- A directed acyclic graph has the vertices F, N, R, S, T, U, V, X and the directed edges R→V, U→S, S→X, F→X, N→V, R→S, U→F, F→N, R→F, R→T…
- An undirected graph has the vertices B, E, G, I, J, K, O, P and the edges I–J, I–O, J–E, J–G, J–P, E–K, E–B, G–P, G–B, G–O, K–P, K–B. What…
- An undirected connected graph on the vertices E, I, L, Y, Z has the edges Y–I, Y–Z, E–Y, L–Z, E–Z, E–I. How many spanning trees does it…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, with edges P2–Q3, P2–Q1, P2–Q2, P3–Q4, P1–Q3, P3–Q3. What is…