GATE Computer ScienceHardGATE CS (PYQ pattern)
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] + p[5]?
- A. 2 odd, 112
- B. 3 odd, 112
- C. 2 odd, 126
- D. 1 odd, 104
Correct answer: A. 2 odd, 112
After 8 rounds the array holds row 8 of Pascal's triangle: [1, 8, 28, 56, 70, 56, 28, 8, 1]. Its odd entries number 2^(number of 1-bits of 8) = 2, and p[3] + p[5] = 56 + 56 = 112.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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] <=…
- int cand = -1, cnt = 0, ch = 0; int a[] = {3,3,4,2,4,4,2,4,3,3,3,1,3,2}; for (int i = 0; i < 14; i++) { if (cnt == 0) { cand = a[i]; cnt =…
- Dutch-national-flag partition on a = [2, 0, 1, 2, 1, 0, 0, 2, 1, 1, 0, 2]: lo = mid = 0, hi = 11; while mid <= hi: if a[mid] == 0 {…
- A heap with 2000 elements is stored in an array (complete binary tree, last level filled left to right). How many elements are in the left…
- How many structurally distinct AVL trees (left and right distinguished, shape only) have exactly 9 nodes?
- A binary tree is serialised in preorder with # for a null child: A B D # # E G # # # C # F # #. What is its inorder traversal and its…