2^n 复杂度算法
我需要实现并测试复杂度为 2^n 的算法。一段时间以来我一直在努力寻找一个。如果有什么方法可以通过实现来实现这一点——精确的复杂度为 2^n 这将是最佳的。如果有人知道某个位置,我可以找到一个示例,或者可以帮助我实现一个示例,那就太棒了:-)。基本操作可以是任何内容,但不能是像 i++ 这样的单个语句;会是最好的。
I need to implement and test an algorithm with a 2^n complexity. I have been trying to find one for a while. If there is any way I can acheive this by implementation -- with a exact complexity of 2^n that would be optimal. If anyone knows of a location I can find an example, or could help me implement one, that would be awesome :-). The basic operation can be anything, but a single statment like i++; would be best.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
生成包含 n 个元素的集合的所有子集。
额外。
生成 S = {a0, a1, ..., an-1} 的所有子集的最简单方法可能是在秩和子集的二进制表示之间进行转换。
取S = {a0, a1, a2}。
因此,二进制中的 1 表示相应的元素在子集中。 0 表示该元素不在子集中。
但您还应该查找格雷码。
Generate all subsets of a set with n elements.
Added.
The simplest way of generating all the subsets of S = {a0, a1, ..., an-1} is probably to translate between the binary representation of the rank and the subset.
Take S = {a0, a1, a2}.
So, a 1 in the binary means the corresponding element is in the subset. A 0 means the element is not in the subset.
But you should also lookup Gray code.
经典的递归斐波那契数计算是 O(2^n)。
由于上面实际上是 theta(Phi^n),所以我添加了一个返回 2^n 的 theta(2^n) 算法。感谢耶利米·威尔科克。
The classical recursive Fibonacci number calculation is O(2^n).
Since the above is actually theta(Phi^n), I'm adding a theta(2^n) algorithm that return 2^n. Thanks to Jeremiah Willcock.
Quantum Bogosort 的空间复杂度为 2^n。
Quantum Bogosort has 2^n space complexity.
我花了很多时间重新思考这个问题,并想发布我想出的解决方案。所有的答案都有助于我提出这个解决方案,并且非常感谢每个回复的人。 :-) 我意识到算法实际上什么也没做。
它是用java编写的
似乎无法让选项卡工作
基本操作是i++;
I spent a great deal of time rethinking the problem and would like to post a solution I came up with. All of the answers contributed to my ability to come up with this solution, and am very thankful for everyone that reponded. :-) I realize that algorithm does practically nothing.
it is written in java
can't seem to get the tabs to work
basic operation is i++;
其一:输出 2^(2^n) 的数字。
Here's one: output the digits of 2^(2^n).