TADM2E 4.44

From Algorithm Wiki
Revision as of 18:14, 11 September 2014 by Algowikiadmin (talk | contribs) (Recovering wiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If we are allowed to maintain a second stack on the side, this should be possible. The main stack is a regular stack that can be implemented using an array and an index to the top of the stack. The second stack will stack each entry when it becomes the new minimum, only. When an entry is poped from the main stack, it will be poped from the second stack only if identical. The minimum item is the top of the second stack.


I think the actual question was about ability of building the stack that has push/pop/extract-min operations as in the queues - the extract removes element. This is impossible - that would give us an opportunity to sort in O(n) time (n O(1) push'es to the data structure, and then n extract-min's) --Kubek2k 05:00, 6 November 2011 (EST)