Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of a O(2^N) algorithm [closed]

Tags:

java

algorithm

I've been told that

O(2^N) denotes an algorithm whose growth will double with each additional element in the input data set

Can someone provide an example that behaves like this?

like image 753
developer Avatar asked Apr 06 '11 12:04

developer


1 Answers

Recursive computation of Fibonacci numbers is a good example of O(2N) algorithm (though O(2N) is not a tight bound for it):

public int fib(int n) {
    if (n <= 1) return n;
    else return fib(n - 2) + fib(n - 1);
}
like image 58
axtavt Avatar answered Sep 30 '22 19:09

axtavt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!