Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
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 (0,1), (1,4), (2,4), (4,0), (4,2). It starts at (4,5) and must reach (0,5). What is the minimum number of knight moves needed?
- A. 2
- B. 3
- C. 5
- 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
- An undirected connected graph on the vertices H, K, L, V has the edges L–K, V–H, H–K, V–K, L–H, V–L. How many spanning trees does it have?…
- A directed acyclic graph has the vertices A, E, G, V, X, Z and the edges G→E, G→V, X→G, X→A, A→Z, Z→E. A topological order lists every…
- A tree has the vertices A, F, I, O, P, U, Y and the edges I–A, I–F, F–U, U–O, F–P, P–Y. What is the minimum number of vertices needed so…
- A tree has vertices with values in brackets: U[-2], B[7], H[5], A[7], N[-2], P[5], C[4], S[-1]. The edges are U–B, U–H, H–A, A–N, B–P…
- An undirected graph has the vertices A, J, Q, T, Y and the edges T–Q, T–A, Y–Q, Y–A, Q–A. What is its chromatic number, the least number…
- A tree has the vertices B, C, D, E, M, P, S, U, V, W and the edges U–B, U–C, C–W, B–V, U–M, M–D, D–P, B–S, W–E. A set D dominates the tree…