java O(2^N) 算法示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5566173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:41:29  来源:igfitidea点击:

Example of a O(2^N) algorithm

javaalgorithm

提问by developer

I've been told that

有人告诉我

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

O(2^N) 表示一种算法,其增长将随着输入数据集中每增加一个元素而加倍

Can someone provide an example that behaves like this?

有人可以提供一个行为像这样的例子吗?

回答by axtavt

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

斐波那契数的递归计算是 O(2 N) 算法的一个很好的例子(尽管O(2 N) 不是它的严格界限):

public int fib(int n) {
    if (n <= 1) return n;
    else return fib(n - 2) + fib(n - 1);
}