2 2 votes A stack of size (1 to N) and the initial position of top pointer is 0. get(i,S) is aroutine to get ith element from stack 'S' with respect to top. then,what is the underflow condition on stack to perform get() operation? $A) top-i<N$ $B) top-i+1<=N$ $C) top-i<=0$ $D) top-i+1<=0$ Data Structures data-structures stack + – Lakshman Bhaiya 5.6k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
5 5 votes Option D Magma answered Oct 22, 2018 Magma comment Share Follow See all 12 Comments 12 12 Comments reply Lakshman Bhaiya commented Oct 23, 2018 reply Follow flag everything seems to be correct, but when you push the element into the stack, why you leave $0$th Position empty? and what it is mean underflow occurs when top$==0??$ 0 0 replyShare Lakshman Bhaiya commented Oct 23, 2018 i edited by Lakshman Bhaiya Oct 23, 2018 reply Follow flag A stack of size (1 to N) and the initial position of top pointer is $0.$ (i,S) is aroutine to put ith element into stack 'S' with respect to top. then,what is the overflow condition on stack to perform put() operation? I think Condition should be the same for this case?? 0 0 replyShare Magma commented Oct 23, 2018 reply Follow flag why you leave 0th Position empty? In general when we implement Stack using Array we initialize the top = -1 and if top == -1 [is the underflow condition] what in the given question initially top = 0 therefore whenever we want to push element to the stack we start from index = 1 0 0 replyShare Lakshman Bhaiya commented Oct 23, 2018 reply Follow flag see my last comment similar for Overflow? 0 0 replyShare Magma commented Oct 23, 2018 reply Follow flag overflow condition if (top = = N ) printf("overflow"); 0 0 replyShare Lakshman Bhaiya commented Oct 23, 2018 reply Follow flag A stack of size (1 to N) and the initial position of top pointer is 0.0. (i,S) is aroutine to put ith element into stack 'S' with respect to top. then,what is the overflow condition on stack to perform put() operation? I think Condition should be the same for this case?? we want to put more that (N+1) elemet so this is "Overflow"?? 0 0 replyShare Magma commented Oct 23, 2018 reply Follow flag Ohk now see I give you a simple scenario for this N = 4 (i = 1 to 4 ) initially top is at index = 0 insert (10) --- > top is at index = 1 array[1] =10 insert(20) ----- > top is at index = 2 array[2] = 20 insert(30) ------> top is at index = 3 array[3] = 30 insert(40) ------> top is at index = 4 array[4] = 40 Now capacity of stack is full right ?? now if you insert one more element it's overflow condition right ??? insert(50) ----> if(top == 4) then there's a overflow condition 0 0 replyShare Magma commented Oct 23, 2018 reply Follow flag carefully go through my answer which is for underflow condition By taking any small example you could analyze it well !! 0 0 replyShare Lakshman Bhaiya commented Oct 23, 2018 reply Follow flag i understand, can you give the condition for overflow as well? 0 0 replyShare Magma commented Oct 23, 2018 reply Follow flag if (top = = N ) printf("overflow"); already given brother 0 0 replyShare Lakshman Bhaiya commented Oct 23, 2018 reply Follow flag I want to answer in terms of $i$ I think if(top=N+1)?? Because (top==N) point the last element. 0 0 replyShare altamash commented Nov 23, 2018 reply Follow flag PEEP FUNCTION -to fnd ith element from top of stack without deleting it to check stack underflow(top−i+1<=0) 0 0 replyShare Please log in or register to add a comment.