How many additional function calls does fib(n) require if "LINE 3" is removed?

Posted by BROCK on Stack Overflow See other posts from Stack Overflow or by BROCK
Published on 2010-03-13T10:15:36Z Indexed on 2010/03/13 10:25 UTC
Read the original article Hit count: 195

Filed under:
|
|

I just got this question on a interview and had no idea how to calculate the answer.
How many additional function calls does fib(n) require if "LINE 3" is removed? The answer should be in terms on n.

int fib(int n) {
  if(n == 0) return 0;
  if(n == 1) return 1;
  if(n == 2) return 1; //LINE 3 HERE <---

  return fib(n - 1) + fib(n - 2);
}

© Stack Overflow or respective owner

Related posts about algorithms

Related posts about complexity