开发者

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

开发者 https://www.devze.com 2023-02-22 16:52 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学JAVA Closed 11 years ago.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号