Let S be a stack of size n >= 1. Starting with the empty stack, suppose we push the first n natural numbers in sequence, and then perform n pop operations. Assume that Push and Pop operation take X seconds each, and Y seconds elapse between the end of one such stack operation and the start of the next operation. For m >= 1, define the stack-life of m as the time elapsed from the end of Push(m) to the start of the pop operation that removes m from S. The average stack-life of an element of this stack is
Quiz on stack and queue Q6
hello @nilotpal
Time for last element Y as it is just popped
time for second last element (time for previous)+2X + 2Y=y+2X+2Y
Time for third last (time for previous)+2X + 2Y=2X+3Y + 2X +2Y
similary doing it for all n element and suming them all and dividing it by N we will get answer.
n(X + Y)-X
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.