recategorized by
485 views
2 votes
2 votes

Which of the following expressions evaluates to the largest number?

  1. The prefix expression  $+ $*$ - 2 3 5 7$
  2. The postfix expression  $2 3 + 5 $*$ 7 -$
  3. The infix expression  $\left ( 2+3 \right )$ * $\left ( 5-7 \right )$
  4. The postfix expression  $2$ $3$ + $5$ $7$ $-$ *
recategorized by

2 Answers

Best answer
7 votes
7 votes

1)  The prefix expression + * - 2 3 5 7

scan from right to left

if operand comes push operand on stack

if operator comes evaluate operand1(top of stack) operator operand2

answer comes out to be 2

2)  The postfix expression  2 3 + 5 * 7 -

scan from left to right

if operand comes push operand on stack

if operator comes evaluate operand2 operator operand1(top of stack)

answer comes out to be 18

3) The infix expression  (2 + 3) * (5 - 7)

This is simple math calculation

answer comes out to be -10

4) The postfix expression  2 3 + 5 7 - *

Apply same procedure as mentioned above for point no 2

answer comes out to be -10

Ans is B

Please correct me if i am wrong

selected by
0 votes
0 votes
Choice A evaluates to ( (2 - 3) * 5) + 7 = (-1 * 5) + 7 = -5 + 7 = 2

Choice B evaluates to ((2 + 3) * 5) - 7 = (5 * 5) - 7 = 25 - 7 = 18

Choice C evaluates to (2 + 3) * (5 - 7) = 5 * (-2) = -10

Choice D evaluates to (2 + 3) * (5 - 7) = 5 * (-2) = -10

 So the largest of the five expressions is choice B.
edited by
Answer:

Related questions

1 votes
1 votes
1 answer
2
Bikram asked Jan 24, 2017
308 views
Suppose that six keys are inserted into an unbalanced binary search tree in the following order: $4, 6, 3, 8, 2$, and $5$.Then which of the following statements is/are co...