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)
- A.
O(n2)
- B.
O(2n)
- C.
O(n log n)
- D.
O(n)
Attempted by 207 students.
Show answer & explanation
Correct answer: B
Loading lesson…