Connecting Tech Pros Worldwide Help | Site Map

Stack operations

  #1  
Old July 23rd, 2005, 06:49 AM
Stewart
Guest
 
Posts: n/a
Is it possible to implement a stack in which push, pop, and min all
work in O(1) or constant number of steps.

push inserts element at the top of the stack.
pop removes element at the top of the stack.
min returns the element with minimum value in the stack.

There are no restrictions, i.e any amount of resouces (memory, cpu,
etc) can be used for implementation. The only requirement is that all
three operations must be O(1).

  #2  
Old July 23rd, 2005, 06:49 AM
Artie Gold
Guest
 
Posts: n/a

re: Stack operations


Stewart wrote:[color=blue]
> Is it possible to implement a stack in which push, pop, and min all
> work in O(1) or constant number of steps.
>
> push inserts element at the top of the stack.
> pop removes element at the top of the stack.
> min returns the element with minimum value in the stack.
>
> There are no restrictions, i.e any amount of resouces (memory, cpu,
> etc) can be used for implementation. The only requirement is that all
> three operations must be O(1).
>[/color]
Yes. Now what's your question about C++?

--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
  #3  
Old July 23rd, 2005, 06:49 AM
benben
Guest
 
Posts: n/a

re: Stack operations



"Stewart" <pntva@yahoo.com> wrote in message
news:1120424800.376330.51930@o13g2000cwo.googlegro ups.com...[color=blue]
> Is it possible to implement a stack in which push, pop, and min all
> work in O(1) or constant number of steps.
>
> push inserts element at the top of the stack.
> pop removes element at the top of the stack.
> min returns the element with minimum value in the stack.
>
> There are no restrictions, i.e any amount of resouces (memory, cpu,
> etc) can be used for implementation. The only requirement is that all
> three operations must be O(1).
>[/color]

Yes! And believe it or not, it's easy! Hint: use the standard library.

ben


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Queue implementation, stack implementation,file operations tabassumpatil answers 0 November 9th, 2008 03:39 AM
[Question]activities of stack pointer and frame pointer when function called anonymous answers 4 November 14th, 2005 06:02 PM
implementing stack Ben answers 8 July 22nd, 2005 01:17 PM
When to use a stack? Andrew answers 15 July 17th, 2005 10:13 PM