Data Structures & AlgorithmsModerateGATE CS · ICPC regional
On an 8×8 chessboard, rows and columns are numbered 0 to 7, 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 (0,3), (2,1), (2,6), (3,6), (5,5), (6,4), (6,5). It starts at (7,6) and must reach (1,3). What is the minimum number of knight moves needed?
- A. 4
- B. 3
- C. 5
- D. 6
Correct answer: C. 5
A BFS that refuses blocked squares gives 5 moves. Ignoring the blocked squares gives 3, and treating the knight like a king gives 6.
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 has the vertices C, D, E, L, M, S, U and the edges U–E, U–S, U–C, D–L, D–C, D–M, L–S, L–M, E–S, E–M, C–M. What is the…
- An undirected graph has the vertices D, E, H, M, O, P, U, V and the edges H–O, H–M, H–D, H–V, O–E, O–V, O–P, M–U, M–V, E–D, E–U, D–U, D–V…
- An undirected connected graph on the vertices B, H, O, P, S has the edges H–S, O–B, S–P, H–P, S–B, B–P, H–B. How many spanning trees does…
- A tree has vertices A, C, G, J, N, Q, X, Y and weighted edges (weights in brackets): Y–Q (2), Y–X (5), Y–J (2), J–C (2), C–A (8), X–G (7)…
- Two unmarked jugs hold 5 litres and 7 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A connected undirected graph has the vertices B, H, J, P, Q, V, Z and weighted edges (weights in brackets): J–H (11), Q–P (16), B–P (9)…