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?

  1. A. 23
  2. B. 26
  3. C. 21
  4. 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.

More Programming and Data Structures (GATE) questions

Exams that ask this topic