3,438 views
0 0 votes
Result for evaluating the following post fix

105+606/*8-

I'm confused whether it is correct postfix expression.

1 Answer

1 1 vote

It is indeed a correct postfix expression. Visualize it as an input sequence which begins with 10 and the input comes in the order:- 

10, 5, +, 60, 6, /, *, 8, -

as soon as 10 is seen it is pushed onto the stack. 

 
 
 
  10

after 10 the next input is 5 which is again pushed onto the stack:

 
 
   5
  10

 The next input is a + operator, whenever a binary operator is seen, the top two values on the stack are popped and the expression formed by the operator and the operand is evaluated: 10+5, the result of this expression( which in this case is 15) will be pushed back onto the stack. Now the stack should look like:

 
 
 
  15

the next inputs 60 and then 6 are similarly pushed onto the stack :

 
   6
  60
  15

The next operator seen is /, which will be evaluated as: 60/6=10 and 10 will be pushed onto the stack;

 
 
  10
  15

Similarly for the * operator: 15*10=150

 
 
 
  150

 The next input is 8 which will be pushed onto stack:

 
 
    8
  150

Now the final input is a subtraction operator: 150-8=142

 
 
 
  142

This value left on the stack is the evaluation of your postfix expression.

I guess this should have cleared your doubt. If the confusion still persists, feel free to ask for clarification.

Position:
Show:

Related questions

1 1 vote
1 1 answer
3.6k
3.6k views
JaiKumar Guwalani asked May 6, 2018
3,647 views
What is time and space complexity to evaluate postfix expression ?
0 0 votes
2 2 answers
7.3k
7.3k views
tiger asked Dec 15, 2015
7,323 views
The following post-fix expression with single digit operands is evaluated using stack, $16\;2\;4\;\wedge \; / \;4\;3\;*\;+\;6\;2\;*\;-$Note that $\wed...
2 2 votes
1 answers 1 answer
7.5k
7.5k views
tbhaxor asked Nov 24, 2023
7,530 views
According to my knowledge, it should be AB+CD*E-*F*G/And, here is the step-wise explanation of itConverting the bracket of (A+B) – AB+There is operator but the next opera...
2 2 votes
1 1 answer
1.9k
1.9k views