in DS
1,290 views
0 votes
0 votes
For every push pop>3 units time required. Do continuously 4 push afterward 4 pop. Then what is the average life time of stack.
in DS
1.3k views

2 Answers

2 votes
2 votes
Best answer
Answer is 12. As the lifetime of stack is not defined I am assuming life time is the time the element was in the stack til it was fully removed. Let the elements be a, b, c, d

Average life time = (life time of a + life time  of b + life time of c + life time of d) / 4

When a will be pushed the time will not be counted because yet no element was in the stack. After pushing a I'm pushing b, c, d, and then removing d, c, b, a in that order. So a will be in stack for 3 push and 4 pop operations, that is, 3*3 + 4*3 = 21 time units.
Similarly for b the life time will be 2*3 + 3*3 = 15,
for c, 3+6 = 9 and
for d, 3 time units.

Average life = (21+15+9+3) / 4
= 12 time units
selected by
0 votes
0 votes
answer should be 36 time units

1 comment

How to calculate it please explain.......
0
0

Related questions