Data Structures & AlgorithmsHardGATE CS · ICPC regional
On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape (two squares in one direction and one square across). The knight may not land on the blocked squares (1,0), (2,4), (3,4), (4,2), (5,1), (5,2). It starts at (1,5) and must reach (5,3). What is the minimum number of knight moves needed?
- A. 3
- B. 5
- C. 2
- D. 4
Correct answer: D. 4
A BFS that refuses blocked squares gives 4 moves. Ignoring the blocked squares gives 2, and treating the knight like a king gives 4.
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 connected undirected graph has the vertices E, F, J, K, L, W, Y, Z and the edges Y–E, Y–W, E–Z, E–L, E–W, E–J, Z–L, Z–F, W–K. Parallel…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→C (7), B→E (5), D→B (7), D→C (2), C→B (9), C→E…
- Consider this function: python def g(n): if n < 2: return n if n % 2 == 0: return g(n - 3) + g(n - 3) return g(n - 3) - 1 What value does…
- A tree has vertices B, H, L, V, W, X, Y and weighted edges (weights in brackets): L–H (7), L–B (2), L–V (3), L–Y (7), L–X (3), X–W (1)…
- A tree has vertices C, G, I, L, M, R, X and weighted edges (weights in brackets): R–X (6), R–I (2), X–L (9), R–M (7), R–C (1), C–G (8)…
- Cities E, P, U, V, Y are joined by roads with these travel costs: V–E 6, V–P 20, V–U 9, V–Y 20, E–P 2, E–U 20, E–Y 11, P–U 15, P–Y 11, U–Y…