【问题标题】:Design a stack + findmin and deletemin in O(1)? [closed]在 O(1) 中设计一个堆栈 + findmin 和 deletemin? [关闭]
【发布时间】:2013-10-21 04:01:04
【问题描述】:

我在 O(1) 时间内看到了有关使用 findmin 设计堆栈的问题的答案:

https://stackoverflow.com/a/3435998/2653179

如果请求相同怎么办:

Devise a stack-like data structure that does push, pop and min (or max) operations 
in O(1) time. There are no space constraints.

但是 deletemin 也应该在 O(1) 中?有可能吗?

【问题讨论】:

  • No deletemin 在 O(1) 中是不可能的。

标签: algorithm data-structures stack


【解决方案1】:

没有。无法完成 - 因为它将允许 O(n) 排序。

Assume there is such a DS, let it be D
Let A be an input array.
push all elements from A to D.
while D is not empty:
   yield D.min()
   D.popMin()

假设popMin()min()O(1),上述将在O(n) 中运行,并将对数组进行排序。
但是,排序是 Omega(nlogn) 问题。矛盾。
因此我们可以断定这样的DS不存在,

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 2010-10-12
    • 2010-10-15
    • 2019-05-09
    • 2016-04-14
    • 2011-06-13
    • 2012-08-17
    • 1970-01-01
    • 2017-08-12
    相关资源
    最近更新 更多