Tuesday 23 June 2015

Q8,p2,d14. 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) ?



(A) 4 PUSH and 3 POP instructions
(B) 5 PUSH and 4 POP instructions
(C) 6 PUSH and 2 POP instructions
(D) 5 PUSH and 3 POP instructions




Answer B.

5 comments:

  1. can anyone explian please....am not understanding

    ReplyDelete
  2. Reverse Polish Notation==> 1. Avoid Brackets
    2. Convert into post fix
    Therefore,
    Normal Expression is (A*B)+(C*D/E)
    Post fix notation without brackets AB*CDE/*+

    When an operand or operands appear push it or them on the top of stack.
    When a binary operator appears pop two operands from the stack. Compute the result and push the result on the top of stack.
    According to given expression:

    1. Push A,B
    2. * operator appears so Pop A,B
    3. Push the result of above computation, say R1, on top of stack.
    4. Push C,D,E.
    5. / operator appears so Pop D,E.
    6. Push the result R2 on the top of stack.
    7. * operator appears so Pop R2,C.
    8. Push the result R3 on the top of stack.
    9. + operator appears so Pop R3, R1.

    Hence 5 push and 4 pop operations.

    ReplyDelete
  3. For other topics of Computer Science

    http://graspandsprout.blogspot.in/

    ReplyDelete
  4. i think it is only talking about operator stack
    for that
    6 push ( * + ( + /
    2 pop second * and +

    ReplyDelete

Note: only a member of this blog may post a comment.