on an avg... say if you insert 10 elemets n remove 10.........
you  consume O(20)

Best,
Prakhar Jain
http://web.iiit.ac.in/~prakharjain/


On Mon, Mar 22, 2010 at 7:39 PM, vikrant singh <[email protected]>wrote:

> Can u xplain what  amortized means?
>
> On Mon, Mar 22, 2010 at 7:32 PM, Prakhar Jain <[email protected]> wrote:
>
>> A better version exists where amortized order is (1) for both opreations
>>
>>
>> Best,
>> Prakhar Jain
>> http://web.iiit.ac.in/~prakharjain/<http://web.iiit.ac.in/%7Eprakharjain/>
>>
>>
>>   On Mon, Mar 22, 2010 at 6:56 PM, Brian <[email protected]> wrote:
>>
>>>  > How is it possible to implement a queue using a stack only?
>>>
>>> Interesting, but tricky... You need two stacks as Prakhar stated...
>>> In general, if you have Stack A and Stack B, you should keep all the
>>> items in stack A and then use stack B for processing.
>>>
>>> For example to insert an item:
>>> 1. Pop all the items from A  and then push them into B (this should push
>>> the items into Stack B in reverse order)
>>> 2. Insert the new item into A
>>> 3. Pop all the items in B and push them back into A (again this will push
>>> them back into Stack B in reverse order)
>>>
>>> Running time should be O(1)+O(2n), which is O(n) for larger values of n -
>>> which is not good...
>>>
>>> To retrieve an item, pop the first item in stack A
>>>
>>> Hope  this helps -
>>> Regards
>>> B
>>>
>>>
>>>
>>> On 3/22/2010 4:55 AM, Prakhar Jain wrote:
>>>
>>>  By a do u mean a single stack ?
>>> Otherwise if you use 2 its v simple
>>>
>>> Best,
>>> Prakhar Jain
>>> http://web.iiit.ac.in/~prakharjain/<http://web.iiit.ac.in/%7Eprakharjain/>
>>>
>>>
>>> On Mon, Mar 22, 2010 at 12:56 AM, Pushpesh Gupta 
>>> <[email protected]>wrote:
>>>
>>>> How is it possible to implement a queue using a stack only?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<algogeeks%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>> --
>>>  You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<algogeeks%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>>  You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Vikrant Singh
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to