GATE Computer ScienceHardGATE CS (PYQ pattern)
How many 10-bit unsigned values x (0 to 1023) have no two adjacent 1 bits, where bit 9 and bit 0 also count as adjacent (the bits are arranged in a circle)?
- A. 144
- B. 110
- C. 123
- D. 89
Correct answer: C. 123
Without the wrap-around condition the count is F(12) = 144 (strings of length n with no 11 number F(n+2)). Subtract those with bit 9 = bit 0 = 1: then bits 8 and 1 are forced to 0 and bits 2..7 (6 bits) are free of 11, F(8) = 21 strings. 144 - 21 = 123, the Lucas number L(10).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- unsigned g(unsigned n) { return n ^ (n >> 1); } For which 8-bit n is g(n) == 0xB5? Give n in decimal.
- A routine compresses runs in place: each maximal run of a repeated character c of length L becomes c if L = 1, else c followed by the…
- A 4 x 6 matrix (4 rows, 6 columns) holds 1 to 24 in row-major order. Its elements are visited in an anticlockwise spiral that starts at…
- int a[] = {1,1,2,2,2,3,4,4,5,5,5,5,6}; int w = 2; for (int i = 2; i < 13; i++) if (a[i] != a[w - 2]) a[w++] = a[i]; What is w after the…
- int p[10] = {1}; for (int r = 1; r <= 8; r++) for (int j = r; j >= 1; j--) p[j] += p[j - 1]; How many of p[0..8] are odd, and what is p[3]…
- Lomuto partition with the last element as pivot is applied to [34, 8, 64, 51, 32, 21, 78, 5, 40, 27]: i = -1; for j = 0 .. n-2, if a[j] <=…