GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A recursive routine place(r) tries every column c for row r, recursing only if column c and both diagonals are free of earlier queens; at r == n it counts a solution. For n = 5 it is called as place(0), and every call (including those that find no valid column) counts. How many calls to place are made in total, and how many solutions are found?

  1. A. 60 calls, 10 solutions
  2. B. 54 calls, 12 solutions
  3. C. 44 calls, 6 solutions
  4. D. 54 calls, 10 solutions

Correct answer: D. 54 calls, 10 solutions

Backtracking on the 5x5 board explores 54 calls and finds 10 placements (the 5-queens problem has 10 solutions).

More Programming and Data Structures (GATE) questions

Exams that ask this topic