How many PUSH and POP operations will be needed to evaluate the following expression by reverse polish notation in a stack machine \((A * B) + (C * D/E)\) ?
5 PUSH and 4 POP instructions
In a stack machine, an expression is evaluated in reverse polish (postfix) form: each operand is pushed onto the stack, and each binary operator pops its operands from the top of the stack, combines them and leaves the result on top.
The postfix form of \((A * B) + (C * D/E)\) is \(A\,B * C\,D\,E / * +\) (or \(A\,B * C\,D * E / +\)); either way it has 5 operands and 4 operators.
Each operand needs one PUSH: A, B, C, D, E give 5 PUSH operations.
Each operator performs one POP step that takes its operands off the stack: the multiplications \(A*B\) and the one with C, the division by E and the final addition give 4 POP operations, after which only the result remains.
Hence, the answer is 5 PUSH and 4 POP instructions.
What is the maximum number of parenthesis that will appear on the stack at any one time for parenthesis expression given by
( ( ) ( ( ) ) ( ( ) ) )
Single array a[0: MAXSIZE - 1] is used to implement two stacks. The two stacks grow from apposite ends of the array. Variables top 1 and top 2 (top1 < 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____________.
| (1) PUSH | (a) STACK |
| (2) FIFO | (b) Stack insertion |
| (3) POP | (c) QUEUE |
| (4) LIFO | (d) Stack deletion |