recategorized
6,542 views
4 votes
4 votes

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)$? 

  1. $4$ PUSH and $3$ POP instructions
  2. $5$ PUSH and $4$ POP instructions 
  3. $6$ PUSH and $2$ POP instructions
  4. $5$ PUSH and $3$ POP instructions
recategorized

4 Answers

4 votes
4 votes
ab* cde /* +

push a push b

encounter *

pop b  pop a push a*b

push c push d push e

encounter /

pop d pop e push d/e

encounter *

pop c pop d/e push c*d/e

enounter +

pop a*b pop c*d/e push a*b + c*d/e

9 push 8 pop

 

theres no option
1 votes
1 votes
Reverse polish notation is a system of formula notation without brackets or special punctuation. To evaluate (A ∗ B) + (C ∗ D / E): First avoid brackets and punctuation and convert it into postfix form i.e. AB+CDE/*+ Now push AB On * pop AB and perform A * B. Now push back the result(say it X). Push CDE. On / pop DE and push back the result(say it Y). On * Pop CY and perform * operation and push the result(say it z). On + pop XZ and perform + opeeration and and push back the final answer. Above computation include 5 PUSH and 4 POP instructions. So, option (B) is correct.
0 votes
0 votes

The algorithm for evaluating any postfix expression is fairly straightforward:

  • While there are input tokens left
    • Read the next token from input.
    • If the token is a value
      • Push it onto the stack.
    • Otherwise, the token is an operator (operator here includes both operators and functions).
      • It is already known that the operator takes n arguments.
      • If there are fewer than n values on the stack
        • (Error) The user has not input sufficient values in the expression.
      • Else, Pop the top n values from the stack.
      • Evaluate the operator, with the values as arguments.
      • Push the returned results, if any, back onto the stack.
  • If there is only one value in the stack
    • That value is the result of the calculation.
  • Otherwise, there are more values in the stack
    • (Error) The user input has too many values Here

 

5 push and 4 pop (B)

0 votes
0 votes
It is B

5 variable so 5 Pushes

4 operators so 4 pops
Answer:

Related questions

2 votes
2 votes
2 answers
1
makhdoom ghaya asked Jul 21, 2016
6,130 views
Convert the following infix expression into its equivalent post fix expression $ (A + B$^$ D) / (E – F) + G $$ABD$^ $+EF – / G+$$ABD + $^$EF – / G+$$ABD +$ ^$EF / �...
4 votes
4 votes
3 answers
2
makhdoom ghaya asked Jul 15, 2016
15,868 views
A certain tree has two vertices of degree $4$, one vertex of degree $3$ and one vertex of degree $2$. If the other vertices have degree $1$, how many vertices are there i...
4 votes
4 votes
3 answers
3
2 votes
2 votes
1 answer
4
makhdoom ghaya asked Jul 24, 2016
1,565 views
Match the following $:$ $\begin{array}{clcl} & \textbf{List – I} && \textbf{List – II} \\ \text{a.} & \text{Call Control protocol} &\text{i.} & \text{Interface b...