Big-O of recursive functions (II)

1
2
3
4
5
6
int Fibonacci(unsigned int N){
    if (N==0 || N==1)
        return N;
    else
        return Fibonacci(N-1)+Fibonacci(N-2);
}

The function Fibonacci(N) , given above, runs in _ _ _ _ _ _ _ _ _ _ _ _ __ .

n 2 n^2 2 n 2^n log n 2 \log_n2 log 2 n \log_2n

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Tasneem Khaled
Jan 19, 2018

If we draw a tree for a fibonacci (N) , we will see that for the first level , there is one sub-branch corresponding to 2^0=1, for the second level there are 2^1=2 sub branches, for the third level, there are 2^2= 4 branches and the sequence keeps going like this, leading to the conclusion of 2^n.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...