GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
128 views

Loading Question

asked in DS by Veteran (10.6k points)   | 128 views

1 Answer

+3 votes

Overflow condition for stack suggests that stack is full.

As mentioned in the questions , the stacks are arranged from left to right in a contiguous manner i.e. after stack S0 , say ends ,stack S1 begins.

So the ith stack is full if top of ith stack points to the last element of that stack and just after that the next stack contents begin i.e. we reach base address of next stack.

So if we have ith stack the condition for it to be full is that top[i] is just before base[i+1] i.e just before base address of (i+1)th stack 

Hence , the required condition is : Top[i] = Base[i+1] - 1

Hence , C) should be the correct option.

If asked for underflow , i.e. stack is empty , in that case , Top[i] = Base[i] - 1

answered by Veteran (66.5k points)  
I agree with you. But will there be another overflow condition where Top[i]=Base[i-1]-1???
Base[i-1] is the base address of preceding array .So Base[i-1] - 1 will lead us to (i-2)th stack which is not the case of overflow as the stack is growing from left to right
Question says address can also be given as X-n/m. Which means array can be represented S(m),S(m-1)......(S1). in that case there will be other overflow condition.
But I have explained you the meaning of overflow .Also it is mentioned that stack grows from left to right.So overflow will occur in right only not left.
sir, S(m) will be growing from left to right, and same for all arrays. i am just providing starting address of array to array-m. So i think my second overflow condition is correct and your answer is also correct.


Top Users Jun 2017
  1. Bikram

    3704 Points

  2. Hemant Parihar

    1502 Points

  3. junaid ahmad

    1432 Points

  4. Arnab Bhadra

    1416 Points

  5. Niraj Singh 2

    1391 Points

  6. Debashish Deka

    1246 Points

  7. Rupendra Choudhary

    1194 Points

  8. rahul sharma 5

    1158 Points

  9. Arjun

    956 Points

  10. srestha

    950 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 19 - 25
  1. Bikram

    1960 Points

  2. Niraj Singh 2

    1386 Points

  3. junaid ahmad

    502 Points

  4. Debashish Deka

    414 Points

  5. sudsho

    410 Points


23,373 questions
30,079 answers
67,406 comments
28,396 users