Let insert elements 1,2,3 into stack and pop it
1x. ( Y) 2x. ( Y) 3x. ( Y) 3x. (Y ) 2x. ( Y ) 1x
Here x represent time required pop or push operation....
Y represent time elapsed between two operations...
Life time of 1 = 5y + 4x
Life time of 2 = 3y + 2x
Life time of 3 = y + Ox
Avg = total time / total values
= (9y + 6x)/3
= 3y +2x
For instead of 3 values if we do for 4 values
Avg will be= 4y + 3x
So it is nothing but... n(x+y)-x