Question

Consider the following recurrence:

f(1)=1;f(1) = 1;
f(2n)=2f(n)−1,for n≥1;f(2n) = 2f(n) - 1, \quad \text{for } n \ge 1;
f(2n+1)=2f(n)+1,for n≥1.f(2n + 1) = 2f(n) + 1, \quad \text{for } n \ge 1.

Then, which of the following statements is/are TRUE?

Choose every correct option
Official answer and solution
Official answer
A, B and C
From
Official GATE 2022 answer key

Solution

Relate the recurrence to the binary representation of integers (the Josephus problem).

This recurrence is the classic Josephus recurrence with step size 2:

f(1)=1,f(2n)=2f(n)−1,f(2n+1)=2f(n)+1f(1) = 1, \quad f(2n) = 2f(n) - 1, \quad f(2n + 1) = 2f(n) + 1

Writing any integer NN as N=2m+lN = 2^m + l where 0≤l<2m0 \le l < 2^m, the closed-form solution is f(N)=2l+1f(N) = 2l + 1.

Evaluating each option:

  • (A) For N=2n−1N = 2^n - 1: We have N=2n−1+(2n−1−1)N = 2^{n-1} + (2^{n-1} - 1), so m=n−1m = n-1 and l=2n−1−1l = 2^{n-1} - 1.
    f(2n−1)=2(2n−1−1)+1=2n−2+1=2n−1f(2^n - 1) = 2(2^{n-1} - 1) + 1 = 2^n - 2 + 1 = 2^n - 1 (TRUE)
  • (B) For N=2nN = 2^n: Here l=0l = 0.
    f(2n)=2(0)+1=1f(2^n) = 2(0) + 1 = 1 (TRUE)
  • (C) For N=5⋅2n=(4+1)⋅2n=2n+2+2nN = 5 \cdot 2^n = (4 + 1) \cdot 2^n = 2^{n+2} + 2^n: Here m=n+2m = n+2 and l=2n<2n+2l = 2^n < 2^{n+2}.
    f(5⋅2n)=2(2n)+1=2n+1+1f(5 \cdot 2^n) = 2(2^n) + 1 = 2^{n+1} + 1 (TRUE)
  • (D) For N=2n+1N = 2^n + 1: Here m=nm = n and l=1l = 1.
    f(2n+1)=2(1)+1=3≠2n+1f(2^n + 1) = 2(1) + 1 = 3 \ne 2^n + 1 for n≥2n \ge 2. (FALSE)

Therefore, (A), (B), and (C) are TRUE.

Final answer

Options (A), (B), (C)

Common trap

Assuming f(2n+1)=2n+1f(2^n + 1) = 2^n + 1 by extrapolating from n=1n=1 where f(3)=3f(3) = 3.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2022 Computer Science and Information Technology (CS)
Question
51 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.