Data Structures & AlgorithmsModerateGATE CS · ICPC regional
On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (4, 5) and must reach (6, 1) (as (row, column)). A knight move is the usual L shape (two in one direction and one perpendicular), and all squares are available. What is the minimum number of knight moves?
- A. 6
- B. 3
- C. 2
- D. 4
Correct answer: C. 2
A BFS over knight moves gives 2; the Chebyshev or Manhattan distance ignores the L-shape, which is why both are wrong.
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
- Distinct words ['c', 'bcb', 'cccb', 'ba', 'bcba', 'bb', 'ac'] are inserted into an empty trie (one node per character, shared prefixes…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(8) and count every invocation of f…
- Directed graph on vertices A, B, C, D, E, F, G with edges F→B, E→B, G→E, C→G, E→D, F→D, F→C, F→E, G→F, C→B, G→A. How many strongly…
- Keys [49, 47, 26, 15, 3, 33, 12, 19, 21] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Directed weighted graph on vertices A, B, C, D, E with edges A→C (6); A→E (2); C→A (-2); C→B (1); D→A (1); E→C (5); C→E (3); E→D (2); D→E…
- Rooted tree with root 0 and vertices 0 to 8; the edges are 0–1, 1–2, 2–3, 1–4, 1–5, 4–6, 4–7, 6–8 (parent–child). Every edge has length 1…