1,304 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.

2 Answers

Best answer
2 votes
2 votes
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

Related questions

1 votes
1 votes
1 answer
1
Shubham Aggarwal asked Sep 1, 2018
1,869 views
A postfix expression P is given with n binary operators. To evaluate the operator using stack, how many PUSH and POP operations are needed? A) PUSH:n, POP:n ...
0 votes
0 votes
2 answers
2
iarnav asked May 17, 2017
710 views
Let's say stack is implemented as Link List, then what will pop() function will return to the calling function? The popped element or the what, because while popping at t...
0 votes
0 votes
1 answer
3
0 votes
0 votes
1 answer
4
prasitamukherjee asked Jul 16, 2015
557 views
q.26 : I do not understand the output . Why are real , integer and to coming?