Question discussion

A naive recursive function fib(n) returns n if n ≤ 1 and otherwise returns fib(n−1) + fib(n−2). How many function calls (including the firs…

1734Medium DSSSB TGT Computer Science 0 replies 1 views
0

A naive recursive function fib(n) returns n if n ≤ 1 and otherwise returns fib(n−1) + fib(n−2). How many function calls (including the first one) are made when fib(5) is called?

  • A11
  • B15
  • C13
  • D25
Correct answer: B

Explanation

The call count satisfies c(n) = 1 + c(n−1) + c(n−2) with c(0) = c(1) = 1, giving 1, 1, 3, 5, 9, 15 for n = 0 to 5.

Discussion 0

Nobody has replied yet. Start the discussion!