2 votes 2 votes Consider the following expression with infix notation A * B - (C + D) * (E / 5) ^ F What is the maximum height of the operator stack during conversion from infix to postfix ? a) 3 b) 4 c) 5 d) 6 DS made-easy-test-series data-structures stack infix-prefix + – Tushar Shinde asked Jan 28, 2016 edited Mar 5, 2019 by akash.dinkar12 Tushar Shinde 3.6k views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply shivanisrivarshini commented Jan 28, 2016 reply Follow Share is it 4 ?? 1 votes 1 votes Tushar Shinde commented Jan 28, 2016 reply Follow Share Yes, but how did u get dat? 0 votes 0 votes Please log in or register to add a comment.
Best answer 4 votes 4 votes This normal conversion of infix to post fix operator stack is nothing just it contains operators thats it see this here in stack at max we have 4 elements so stack size is 4 shivanisrivarshini answered Jan 28, 2016 selected Jan 28, 2016 by Tushar Shinde shivanisrivarshini comment Share Follow See all 4 Comments See all 4 4 Comments reply Tushar Shinde commented Jan 28, 2016 reply Follow Share But after / , on stack ^ should be there as ^ has highest precedence among all. So, ^ should reduce first. SO total height becomes 5. 0 votes 0 votes shivanisrivarshini commented Jan 28, 2016 reply Follow Share NO before that we get ) so (/ is poped out of stack then we left with * and then ^ comes in since ^ > *, * gets poped 1 votes 1 votes saket nandan commented Feb 10, 2016 reply Follow Share your , stack size is right but popping of operator ^ is wrong first ^ will be popped then * then - will be popped 2 votes 2 votes thor commented Nov 19, 2016 reply Follow Share Answer is right but stack will contain ^,* and - 1 votes 1 votes Please log in or register to add a comment.
0 votes 0 votes Stack grows only up to 4 sizes but in the image, it is shown that stack grows for 5 sizes but first left parenthesis is by default added so total size is 4. ravi kant Gautam answered Sep 22, 2017 ravi kant Gautam comment Share Follow See all 0 reply Please log in or register to add a comment.
–3 votes –3 votes when / is reached the operator stack will be - * ( / so max height =4 bobo diarda answered Jan 28, 2016 bobo diarda comment Share Follow See 1 comment See all 1 1 comment reply Tushar Shinde commented Jan 28, 2016 reply Follow Share Can you plz explain it more clearly..? 0 votes 0 votes Please log in or register to add a comment.