---
title: "Importance of postfix; convert expression"
subject: "Data Structure and Algorithm"
chapter: 2
key: "semester_4/data_structure_and_algorithm:postfix-importance-conversion"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/postfix-importance-conversion
site: BCT Engineering
---

# Importance of postfix; convert expression

Data Structure and Algorithm · Chapter 2: The Stack and Queue

- Asked in: 2071 Bhadra, 2+3 marks
- Video: [Infix, Prefix and Postfix Expressions | Data Structures](https://www.youtube.com/watch?v=M2c8D-MCAck) — Learn Coding
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/postfix-importance-conversion
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-2

## Question

What is the importance of postfix expression? Convert the given infix expression (a+b*c+(d/e*f)-g) into equivalent postfix expression showing the status of stack in each steps.

## Short answer

Postfix eliminates parentheses and precedence, enabling O(n) evaluation with a single stack pass. Converting (a+b*c+(d/e*f)-g) yields abc*+de/f*+g-.

## Answer

#### Importance of postfix expression

1. **No brackets needed**: the order of operations is fully decided by the position of operators.
2. **No precedence or associativity rules** at evaluation time; a compiler need not look back or ahead.
3. **Easy evaluation with a stack**: scan once from left to right, push operands, and on an operator pop two operands and push the result. Time is O(n).
4. **Used by compilers and calculators**: expressions are converted to postfix, then to machine code or evaluated (e.g., stack-based machines, HP calculators).
5. Simple to generate and store: the postfix form is a linear string which is easy to process.

#### Conversion of (a + b * c + (d / e * f) - g)

The outer brackets of the given expression do not change the result and are omitted in the table. Rules used:

1. Scan the infix expression left to right.
2. **Operand**: copy it to the output.
3. **`(`**: push it.
4. **`)`**: pop operators to the output until `(`; discard both brackets.
5. **Operator**: pop operators of higher or equal precedence from the stack top (for `^` only higher) to the output, then push the scanned operator.
6. At the end, pop all remaining operators to the output.

Precedence: `^` > `* /` > `+ -`.

| Step | Symbol | Stack (bottom → top) | Postfix output |
|---|---|---|---|
| 1 | a | (empty) | a |
| 2 | + | + | a |
| 3 | b | + | ab |
| 4 | \* | +\* | ab |
| 5 | c | +\* | abc |
| 6 | + | + | abc\*+ |
| 7 | ( | +( | abc\*+ |
| 8 | d | +( | abc\*+d |
| 9 | / | +(/ | abc\*+d |
| 10 | e | +(/ | abc\*+de |
| 11 | \* | +(\* | abc\*+de/ |
| 12 | f | +(\* | abc\*+de/f |
| 13 | ) | + | abc\*+de/f\* |
| 14 | - | - | abc\*+de/f\*+ |
| 15 | g | - | abc\*+de/f\*+g |
| end | (pop all) | (empty) | abc\*+de/f\*+g- |

**Postfix:** `abc*+de/f*+g-`

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. A key advantage of postfix expressions is:
   A. It uses more memory
   B. It needs two scans
   C. No brackets or precedence rules needed at evaluation
   D. It requires queues
   Answer: C. Order is fixed by operator position. (Key point: Importance)

2. Postfix evaluation with a stack takes:
   A. Two scans, O(n^2)
   B. One left-to-right scan, O(n)
   C. Right-to-left scan
   D. A queue
   Answer: B. Push operands, on operator pop two and push result. (Key point: Evaluation)

3. (a+b*c+(d/e*f)-g) in postfix is:
   A. abc*+de/f*g-+
   B. abc*+de/f*+g-
   C. abc*+def/*+g-
   D. ab+c*de/f*+g-
   Answer: B. Per the table. (Key point: Final postfix)

4. On '*' with +(/ on the stack:
   A. '*' pushed above '/'
   B. '+' popped
   C. '(' popped
   D. '/' is popped to output, '*' pushed
   Answer: D. Equal precedence pops first. (Key point: Equal precedence inside bracket)

## Related in Data Structure and Algorithm

- [Convert expression to prefix and postfix](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Ainfix-prefix-postfix-tabular) — Data Structure and Algorithm, chapter 2
- [Infix to postfix and evaluation](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Ainfix-postfix-explain-evaluate) — Data Structure and Algorithm, chapter 2
- [Convert expression to prefix and postfix](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aprefix-postfix-abcdefgk) — Data Structure and Algorithm, chapter 2
- [Algorithm for infix to postfix conversion](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Ainfix-postfix-algorithm) — Data Structure and Algorithm, chapter 2, asked 3×
- [Convert A+B-(C*D/E+F)-G*H to postfix](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Apostfix-abcde-fgh) — Data Structure and Algorithm, chapter 2
- [Convert and evaluate A/B-(C+D)*E](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Apostfix-evaluate-ab-slash-cd-e) — Data Structure and Algorithm, chapter 2, asked 2×
