Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as _). Current board: _ 2 5 / 1 3 4. Goal board: 1 2 3 / 4 5 _. A move slides a tile that is orthogonally adjacent to the blank into the blank. What is the minimum number of moves to reach the goal?
- A. 7
- B. 9
- C. 4
- D. 11
Correct answer: B. 9
A BFS over all 360 reachable boards from the goal gives 9. Counting misplaced tiles or summing Manhattan distances are lower-bound heuristics, not the exact answer.
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
- Array [10, 28, 18, 27, 13, 14] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Array A = [3, 31, 23, 2, 8, 19, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Distinct keys [5, 4, 7, 27, 25] are inserted, in the order given by the sequence [25, 5, 4, 27, 7], into an empty binary search tree. How…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(7) and count every invocation of f…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(10) and count every invocation of f…
- Array [25, 3, 24, 17, 29, 1] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element at…