Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2
On an 8 × 8 chessboard with rows and columns numbered 0 to 7, a knight starts at (4, 7) and must reach (1, 0) (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. 10
- B. 5
- C. 7
- D. 4
Correct answer: D. 4
A BFS over knight moves gives 4; 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
- A trie keeps a counter at each node, and every word of the list W = ['bbaa', 'bc', 'a', 'cbaa', 'ccac', 'a'] is inserted once per…
- A binary trie of 6-bit numbers stores the set S = [25, 51, 62, 29]. For the query x = 53, what is the maximum value of x XOR s over all s…
- Directed graph on vertices A, B, C, D, E, F, G with edges C→F, F→G, F→E, A→D, E→C, C→G, B→F, A→G, B→C, G→C, A→E. How many strongly…
- On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (0, 0) and must reach (5, 1) (as (row, column)). A knight…
- A trie keeps a counter at each node, and every word of the list W = ['ab', 'acc', 'aac', 'bcaa', 'cab', 'ab', 'a'] is inserted once per…
- Array A = [22, 11, 12, 9, 20, 23, 25, 15, 2]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 21? (A trie with subtree counts answers…