Question:
Let S be a stack of size n> = 1. Starting from an empty stack, suppose we push the first n integers in a sequence, and then perform n pop operations.
Assume that the Push and Pop operations take X seconds each, and Y seconds elapse between the end of one operation with such a stack and the start of the next operation.
For m> = 1, define the service life of m as the time elapsed from the end of Push (m) before the start of a pop operation that removes m from S. The average service life of an element from this stack is
(A) n(X+ Y)
(B) 3Y + 2X
(C) n(X + Y)-X
(D) Y + 2X
Question taken from this link
My approach:
For n elements Push takes X time, hence for m elements Push takes m/n*X
For n elements Pop takes X time, hence for m elements Push takes m/n*X
Interval Time is m/n*Y
Stack Life = End of Push(m) to start of Pop(m) = Interval Time = m/n*Y
Average Stack Life = (m/n*Y) / m = Y/n
None of the answers fit. Please guide me on the right path to achieve my goal.
source
share