edited by
947 views
3 votes
3 votes
Let S be a stack size of 4>=1 and it is initially empty.Suppose we push the numbers 1,2,3,4 and then perform 4 pop operations.Let one push operation takes 5ns; one pop operation takes 5ns; the time between the end of one such stack operation and start of next operation is 2ns.  

   The stack life of a particular element p>=1 is defined as time elapsed from end of push (P) to the start of operation that removes (P) from the stack.The average stack life of an element of this stack is........................(in ns).
edited by

1 Answer

0 votes
0 votes

Stack life of 4 = 2    {Since it will be on the top of the stack and the first one to pop and thus it will acquire only the in between time o operation}

Stack life of 3= 16 {2 [All it include the time of Gap after it is pushed ] + 5 [Time of push(4)] + 2 [gap] + 5[pop(4)] + 2 [gap] }

Now at this point we can derive the pattern the stack life of an element is the summation of the stack life of its consecutive element + 14 (Because the push pop and two gaps are not counted in the stack life of consequetive element)

Thus Stack life of 2 = 30 [same logic]

Stack life of 1 = 44

Total =92

Average = 23.

You can check this timeline for better understanding 

Related questions

2 votes
2 votes
2 answers
1
1 votes
1 votes
2 answers
2
Shamim Ahmed asked Dec 11, 2018
723 views
Every recursive program uses strictly more stack space compared to its iterative equivalent.This statement is false. Please explain with examples
2 votes
2 votes
0 answers
3
1 votes
1 votes
1 answer
4
radha gogia asked Jul 24, 2018
1,405 views
Suppose one character at a time comes as an input from a string of letters . There is an option either to 1) print the incoming letter or to 2) put the incoming letter on...