2082 6

BIT201 · 2082 · 5 marks

Convert the infix expression 7 * 8 + 10 - 2 to postfix using stack.

Convert the infix expression 7 * 8 + 10 - 2 to postfix using stack. [5]

Data Structures and AlgorithmsChapter 3: Linear Data Structures: Stacks and QueuesInfix to postfix conversion using stackNumerical: infix to postfix conversion

Given Data

Infix expression to convert: $$7 * 8 + 10 - 2$$

Operator precedence:

  • *, / : higher
  • +, - : lower

Associativity: left to right.


Conversion Rules (Stack Method)

  1. Scan tokens left to right.
  2. Operand → append to output.
  3. Operator → pop operators from stack with precedence greater than or equal to the current one (for left-associative operators), append them to output, then push the current operator.
  4. End → pop all remaining operators to output.

Step-by-Step Trace

StepTokenActionStack (bottom→top)Output
17operand → output(empty)7
2*push*7
38operand → output*7 8
4+* ≥ + so pop *; push ++7 8 *
510operand → output+7 8 * 10
6-+ ≥ - so pop +; push --7 8 * 10 +
72operand → output-7 8 * 10 + 2
8Endpop -(empty)7 8 * 10 + 2 -

Verification (evaluate postfix)

Given values: $7,8,+,*$ etc. Compute $7 \times 8 = 56$; $56 + 10 = 66$; $66 - 2 = 64$. Infix: $7 \times 8 + 10 - 2 = 56 + 10 - 2 = 64$. ✓ Matches.


Result

$$\boxed{7\ 8\ *\ 10\ +\ 2\ -}$$

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.