Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
A grid has 8 rows and 5 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. 11
- B. 13
- C. 14
- D. 7
Correct answer: B. 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
- A tree has the vertices D, G, O, Q, T, Y, Z and the edges T–Y, Y–G, Y–D, G–Q, T–Z, Z–O. What is the minimum number of vertices needed so…
- A tree has vertices with values in brackets: J[0], N[0], I[8], Q[3], K[-2]. The edges are J–N, N–I, N–Q, I–K. A path is any sequence of…
- Cities H, J, L, T, W are joined by roads with these travel costs: H–T 6, H–W 9, H–L 19, H–J 19, T–W 19, T–L 20, T–J 15, W–L 13, W–J 14…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 4) return g(n - 1) - 1 What value does…
- Cities E, S, T, U, V are joined by roads with these travel costs: T–E 16, T–V 1, T–S 8, T–U 3, E–V 2, E–S 4, E–U 14, V–S 2, V–U 4, S–U 12…
- Consider this recursive function: python def f(n): if n <= 0: return f(n - 2) if n % 3 == 0: f(n - 2) How many times is f called in total…