in DS edited by
12,860 views
27 votes
27 votes

The result evaluating the postfix expression $10  \ 5 + 60 \ 6 /  * 8 -$ is 

  1. $284$
  2. $213$
  3. $142$
  4. $71$
in DS edited by
12.9k views

6 Answers

51 votes
51 votes
Best answer
We have to keep symbol into stack and when we get two operands followed by operator. We will apply operator on last two operands.$$\begin{array}{|ll|}\hline \textbf{symbol}  &  \textbf{stack } \\\hline \text{10} & \text{10 $\quad$ (keep in stack)}\\\hline \text{5} & \text{10 $\quad$ 5 $\quad$ (keep in stack)}\\\hline
\text{+} & \text{10 $\quad$ 5 $\quad$ + $\quad$ (apply operator on last 2 operands $\implies 10+5=15)$}\\\hline \text{60} & \text{15 $\quad$ 60 $\quad$ (keep in stack)}\\\hline  \text{6} & \text{15 $\quad$ 60 $\quad$ 6 $\quad$ (keep in stack)}\\\hline  
\text{/} & \text{15 $\quad$ 60 $\quad$ 6 $\quad$ / $\quad$ (apply operator on last 2 operands $\implies 60/6=10)$}\\\hline  
\text{*} & \text{15 $\quad$ 10 $\quad$ * $\quad$ (apply operator on last 2 operands $\implies  10*15=150)$}\\\hline   \text{8} & \text{150 $\quad$ 8 $\quad$ (keep in stack)}\\\hline   - & \text{150 $\quad$ 8 $\quad -\quad$ (apply operator on last 2 operands $\implies 50-8=142)$}\\\hline  \end{array}$$

So, answer is $142$.
edited by

1 comment

This is just a woww explanation.

Read it once and you are just done,
3
3
18 votes
18 votes
(10 + 5) * (60 / 6) - 8 = 15 * 10 - 8 = 142
by
4 votes
4 votes

10 5 + 60 6 / * 8 -

Operation  Symbol Stack
  10 5 + 60 6 / * 8 - NULL
Push 5 + 60 6 / * 8 -   10
Push         + 60 6 / * 8 -   10 5
Pop 60 6 / * 8 - (10 + 5)
Push 6 / * 8 - (10 + 5) 60
Push / * 8 - (10 + 5) 60 6
Pop * 8 - (10 + 5) (60/6)
Pop 8- (10 + 5) * (60/6)
Push - [(10 + 5) * (60/6)]  8
Pop Null [(10 + 5) * (60/6)]  - 8

So after evaluation of    [(10 + 5) * (60/6)]  - 8 = 142 so option c is answer

2 votes
2 votes

This postfix expression can be evaluated using stack..

                                6

           5            60   60  10            8

    10  10    15  15   15  15   150   150     142

    10    5    +    60    6     /     *        8         -

Answer will be 142.

Answer:

Related questions