NTA UGC NET JUNE-2023 Paper-2
October 29, 2023UGC NET CS 2015 Dec- paper-2
October 29, 2023Question 9491 – GATE 2004
A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl < top2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for “stack full” is
Correct Answer: D
Question 3 Explanation:
Since the stacks are growing from opposite ends, so initially top1=1 and top2=Max_size. Now to make the efficient use of space we should allow one stack to use the maximum possible space as long as other stack doesn’t need it. So any of the stack can grow towards each other until there is space available in the array. Hence, the condition must be top1 = top2 – 1.
(top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
top1 + top2 = MAXSIZE
(top1 = MAXSIZE/2) or (top2 = MAXSIZE)
top1 = top2 – 1
Subscribe
Login
0 Comments