in DS retagged by
16,461 views
33 votes
33 votes

The following postfix expression with single digit operands is evaluated using a stack:

$$8 \ 2 \ 3 \  {}^\hat{}  ∕  \ 2 \ 3 * + 5 \ 1 * -$$

Note that $^\hat{}$ is the exponentiation operator. The top two elements of the stack after the first $*$ is evaluated are

  1. $6, 1$
  2. $5, 7$
  3. $3, 2$
  4. $1, 5$
in DS retagged by
16.5k views

4 Comments

edited by

@Arjun sir , this question is still not corrected in go hardcopy 2020.

2
2
missed it. Will check next time as nothing is wrong in HTML. May be an unknown issue.
2
2
It is fixed now.
0
0

4 Answers

43 votes
43 votes
Best answer
  • $8:$ $\textsf{PUSH}.$  Stack becomes $:8$
  • $2:$ $\textsf{PUSH}.$  Stack becomes $:8\;2$
  • $3:$ $\textsf{PUSH}.$  Stack becomes $:8\;2\;3$
  • $^\hat{}:$ $\textsf{POP}$ $3$ and $2$ and perform the operation $2\; ^\hat{}\; 3$ and push the result to stack. Stack becomes $:8\;8$
  • $∕:$ $\textsf{POP}$ $8$ and $8$ and perform the operation $8 ∕8$ and push the result to stack. Stack becomes $:1$
  • $2:$ $\textsf{PUSH}.$  Stack becomes $:1\;2$
  • $3:$ $\textsf{PUSH}.$  Stack becomes $:1\;2\;3$
  • $*:$ $\textsf{POP}$ $3$ and $2$ and perform the operation $2 * 3$ and push the result to stack. Stack becomes $:1\;6$

Hence, answer is A.

edited by

4 Comments

after 823 we've ^ in TOS , so we'll pop last two element & perform the operation that's fine.but my query is that why 2^3 not 3^2 & in case there is ' - ' in place of ' ^ ' then in which order it will be performed.

I mean sometimes for some operator order of the elelment will matter( e.g:' - ' & ' ^ ' as 3-2 or 2-3  and  2^3 or 3^2) Is there any general concept to remove this confusion???

0
0

@MRINMOY_HALDER......bottom of the element is 1st and top element 2nd......i.e    2-3=-1

better take any infix operation solve first then convert that postfix evaluate using postfix evaluation...you will get ans

0
0
what if 1,6 and 6,1 both were in options...
0
0
I guess 6,1 must be the answer.

Since stack elements, in the end, are 1,6 with 6 being at the top. So when popped off, 6 will come first. Then, 1.
3
3
11 votes
11 votes
Operation   Expression   Stack 
   823 ^ /23 * 51 * -   Empty 
Push  23 ^ /23 * 51 * -  8
Push  3 ^ /23 * 51 * -  8 2
Push  ^ /23 * 51 * -  8 2 3
Pop  /23 * 51 * -  8 (2^3)
Pop  23 * 51 * -  8/8
Push   3 * 51 * -  1 2
Push  * 51 * -  1 2 3
Pop  51 * -  1 (2*3)

So top two elements after 1st * is 6 , 1

0 votes
0 votes

Postfix evaluation

The single important thing is, when you pop two elements, first one goes on right side.

–1 vote
–1 vote
Ans is (A) 6 ,1
Answer:

Related questions