【发布时间】:2011-06-25 18:38:21
【问题描述】:
我刚刚阅读了this other question about the complexity of next_permutation,虽然我对响应 (O(n)) 感到满意,但似乎该算法可能有一个很好的摊销分析,显示出较低的复杂性。有人知道这样的分析吗?
【问题讨论】:
-
较低的复杂性将要求您在每个分摊时间 o(1) 内返回元素。对于意味着您必须能够在 0 个时钟周期内返回一些元素的大型数据集。这是不可能的。
-
@btilly- 不一定。 一次调用 next_permutation 的复杂度为 O(n),而不是一系列调用。因此,我怀疑这可以在摊销 o(n) 中完成。
-
只为算法迷发表评论。我在这里 (home.roadrunner.com/~hinnant/combinations.html) 对 next_permutation 进行了重新表述,称为 for_each_permutation,它的运行速度通常快 25% 到 50%,因为它不必进行比较即可找到下一次迭代。此实现还允许您一次置换 N 个项目 r。
标签: c++ algorithm stl big-o permutation