The function f is defined as follows: int f (int n) { if (n <= 1) return 1;…

GATE · 2007 · IT

The function f is defined as follows: 

int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
1. The function f terminates for finitely many different values of n ≥ 1. 
ii. The function f terminates for infinitely many different values of n ≥ 1. 
iii. The function f does not terminate for finitely many different values of n ≥ 1. 
iv. The function f does not terminate for infinitely many different values of n ≥ 1. 
Which one of the following options is true of the above?

  1. A.

    (i) and (iii)

  2. B.

    (i) and (iv)

  3. C.

    (ii) and (iii)

  4. D.

    (ii) and (iv)

Attempted by 256 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…