What is the time complexity of the following C function? (Assume n > 0) int…

2025

What is the time complexity of the following C function? (Assume n > 0)

int rec (int n)

{

if (n == 1)

return 1;

else

return (rec (n - 1) + rec (n - 1));

}

Answer: B. O(2n)

  1. A.

    O(n2)

  2. B.

    O(2n)

  3. C.

    O(n log n)

  4. D.

    O(n)

Attempted by 207 students.

Show answer & explanation

Correct answer: B

Explore the full course: Up Lt Grade Assistant Teacher 2025

Loading lesson…