Example of a O(2^N) algorithm [closed]
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?
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);
}
精彩评论