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?
- A. 60 calls, 10 solutions
- B. 54 calls, 12 solutions
- C. 44 calls, 6 solutions
- 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).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Binary search (lo = 0, hi = n - 1, mid = (lo + hi) / 2 with integer division) is run on a sorted array of the 100 elements 1..100 once for…
- rot(a, n, k) does: reverse(a, 0, k-1); reverse(a, k, n-1); reverse(a, 0, n-1), where reverse(a, i, j) reverses a[i..j] in place. The array…
- int x = 10; void f() { static int x = 1; x += 2; { int x = 100; x++; } printf("%d ", x); } int main() { f(); f(); { extern int x…
- unsigned char rev(unsigned char x) { unsigned char r = 0; for (int i = 0; i < 8; i++) { r = (r << 1) | (x & 1); x >>= 1; } return r; }…
- Assume 4-byte int and 8-byte pointers. char s[] = "ab0cd"; char p = "ab0cd"; int a[3][4]; printf("%zu %zu %zu %zu %zu", sizeof(s)…
- For a BST built from distinct keys (deletion of a node with two children uses its inorder successor), consider: I. Inserting a new key and…