ITPEC FE Morning October 2023 Question 5

Source exam: ITPEC FE Morning October 2023Topic: Basic Theory & Math

ITPEC FE Morning October 2023 — Question 5 of 80

Infix to Postfix Notation — convert 2+5×3+4 respecting operator precedence.

Step-by-step:

  • Original infix: 2 + 5 × 3 + 4
  • With precedence: (2 + (5 × 3)) + 4
  • Convert innermost first: 5 × 35 3 ×
  • Then 2 + result2 5 3 × +
  • Then result + 42 5 3 × + 4 +

Verification by stack execution of `2 5 3 × + 4 +`:
- Push 2, 5, 3

- ×: pop 5, 3 → push 15

- +: pop 2, 15 → push 17

- Push 4

- +: pop 17, 4 → push 21

Why not others:
- (a) 2 5 3 4 × + + — evaluates to 2+(5+(3×4)) = 19

- (b) 2 5 + 3 4 × + — evaluates to (2+5)+(3×4) = 19

- (c) 2 5 3 + × 4 + — evaluates to (2×(5+3))+4 = 20

Key rule: In postfix, higher-precedence operators appear earlier (closer to their operands). Always verify by stack-executing the result.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.