GATE Computer ScienceModerateGATE CSE · ISRO
int f(int n) { if (n == 0) return 0; return (n & 1) + f(n >> 1) + f(n >> 2); } What does f(100) return?
- A. 23
- B. 26
- C. 21
- D. 29
Correct answer: A. 23
Evaluating the recursion (n>>1 and n>>2 are floor-divisions by 2 and 4) gives f(100) = 23.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Assume sizeof(int) = 4 and sizeof(int ) = sizeof(int ()[4]) = 8. int a[3][4]; / a[i][j] = 4i + j / int (r)[4] = a + 1; int p = (r + 1) +…
- #include <stdio.h> int main() { int a[5] = {10, 20, 30, 40, 50}; int p = (int )(&a + 1); printf("%d %d", (a + 1), (p - 2)); } What is…
- Assume sizeof(int) = 4 and every pointer is 8 bytes. int f(int a[][3], char s[]) { return sizeof(a) + sizeof(a) + sizeof(s); } int main()…
- int a[] = {5, 6, 7, 8}; int p = a; p++ += 2; (p)++; ++p += 10; ++p; What are a[0], a[1], a[2], a[3] and p - a after these statements?
- void g(int pp, int q, int k) { q += k; pp = q + 1; pp += q; q = pp; q -= k; } int main() { int a[3] = {1, 2, 3}; int p = a; g(&p, p, 4)…
- int a[] = {1, 3, 4, 6, 8, 9, 11, 14}; int i = 0, j = 7, c = 0, it = 0; while (i < j) { it++; if (a[i] + a[j] > 15) { c += j - i; j--; }…