Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 B
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,3), (4,0), (4,5), (5,3). It starts at (2,1) and must reach (0,1). What is the minimum number of knight moves needed?
- A. 2
- B. 4
- C. 5
- D. 1
Correct answer: B. 4
A BFS that refuses blocked squares gives 4 moves. Ignoring the blocked squares gives 2, and treating the knight like a king gives 2.
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
- The directed acyclic graph has the vertices C, E, J, K, L, M, Q, Z and the arcs Q→C, Q→M, C→J, L→J, L→K, Q→K, E→J, M→C, M→L, M→E, Q→E…
- Starting from the integer 4, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A directed graph has the vertices A, M, O, V and the arcs O→M, O→A, M→O, M→A, A→O, A→V, V→O, V→A. Count the directed Hamiltonian paths…
- An undirected graph has the vertices B, D, E, F, I, M, X and the edges M–E, M–X, M–D, M–B, M–F, E–X, E–D, E–I, X–D, X–B, D–F, B–I, F–I…
- A directed weighted graph has the arcs u→v (weight): Y→K (14), Y→Q (6), K→L (4), K→T (5), L→Q (8), D→Y (3), D→Q (11), D→T (3), Q→Y (12)…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. UURD DLRU LRUU From a cell you may move…