retagged by
16,419 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$
retagged by

4 Answers

Best answer
43 votes
43 votes
  • $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
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

Answer:

Related questions

64 votes
64 votes
15 answers
1
Arjun asked Jul 6, 2016
36,739 views
Consider the following segment of C-code:int j, n; j = 1; while (j <= n) j = j * 2;The number of comparisons made in the execution of the loop for any $n 0$ is:$\lceil \...
27 votes
27 votes
4 answers
2
Kathleen asked Sep 21, 2014
33,744 views
The message $11001001$ is to be transmitted using the CRC polynomial $x^3 +1$ to protect it from errors. The message that should be transmitted is:$11001001000$$110010010...