Connecting Tech Pros Worldwide Help | Site Map

Stack operations

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:49 AM
Stewart
Guest
 
Posts: n/a
Default Stack operations

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, 05:49 AM
Artie Gold
Guest
 
Posts: n/a
Default 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, 05:49 AM
benben
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.