Data Structures & AlgorithmsModerateCodeforces 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,0), (0,3), (2,2), (2,3), (2,4), (3,2), (4,2). It starts at (5,0) and must reach (5,3). What is the minimum number of knight moves needed?
- A. 1
- 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 3.
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 D, K, R, S, X, Y and the edges Y–R, S–X, D–S, Y–D, Y–S, R–K, R–X, D–R, R–S, D–X. What is the minimum…
- A connected undirected graph has the vertices E, H, O, P, V, W, X and weighted edges (weights in brackets): E–P (4), O–W (16), X–H (8)…
- A directed acyclic graph has the vertices I, K, O, Q, T, U, X, Z and the directed edges K→Z, U→K, U→Z, T→K, X→I, X→K, O→K, T→I, X→U, X→O…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→D (9), S→A (2), S→B (9), S→T (3), A→D (7), A→T…
- A directed acyclic graph has the vertices C, F, K, Q, S, V, W and the directed edges Q→C, V→W, F→C, K→F, V→Q, S→Q, W→F, K→S, K→C, S→C. How…
- An undirected graph has the vertices H, K, N, T, U, X and the edges X–H, X–U, X–K, H–K, N–T, N–U, N–K, U–K. What is its chromatic number…