---
title: "Polish notation and postfix conversion"
subject: "Data Structure and Algorithm"
chapter: 2
key: "semester_4/data_structure_and_algorithm:polish-notation-postfix"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/polish-notation-postfix
site: BCT Engineering
---

# Polish notation and postfix conversion

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

- Asked in: 2071 Magh, 2+3 marks
- Video: [Infix, Prefix and Postfix](https://www.youtube.com/watch?v=jos1Flt21is) — mycodeschool
- 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/polish-notation-postfix
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-2

## Question

What is polish notation and reverse polish notation? Convert the following expression to postfix expression using Stacks: P: (a + b * c + (d * e + f) * g)

## Short answer

Polish (prefix) places operator before operands; reverse Polish (postfix) places after, removing brackets. Postfix of (a+b*c+(d*e+f)*g) is abc*+de*f+g*+.

## Answer

#### Polish and reverse Polish notation

- **Polish notation (prefix)**: the operator is written *before* its operands, e.g. `+ab`. It was introduced by the Polish logician Jan Łukasiewicz.
- **Reverse Polish notation (postfix)**: the operator is written *after* its operands, e.g. `ab+`.
- The usual form `a+b` (operator between operands) is **infix**.

Both prefix and postfix need no brackets and no precedence rules, because the order of operators already fixes the order of evaluation. Example: `(a+b)*c` → prefix `*+abc`, postfix `ab+c*`.

#### Conversion of P: (a + b * c + (d * e + f) * g)

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 | ( | ( | - |
| 2 | a | ( | a |
| 3 | + | (+ | a |
| 4 | b | (+ | ab |
| 5 | \* | (+\* | ab |
| 6 | c | (+\* | abc |
| 7 | + | (+ | abc\*+ |
| 8 | ( | (+( | abc\*+ |
| 9 | d | (+( | abc\*+d |
| 10 | \* | (+(\* | abc\*+d |
| 11 | e | (+(\* | abc\*+de |
| 12 | + | (+(+ | abc\*+de\* |
| 13 | f | (+(+ | abc\*+de\*f |
| 14 | ) | (+ | abc\*+de\*f+ |
| 15 | \* | (+\* | abc\*+de\*f+ |
| 16 | g | (+\* | abc\*+de\*f+g |
| 17 | ) | (empty) | abc\*+de\*f+g\*+ |
| end | (pop all) | (empty) | abc\*+de\*f+g\*+ |

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

Check by the order of evaluation: `b*c`, then `a+(b*c)`, then `d*e`, `(d*e)+f`, `*g`, and the final `+`.

## Check yourself

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

1. Polish (prefix) notation writes the operator:
   A. Before its operands
   B. After its operands
   C. Between operands
   D. At the end only
   Answer: A. e.g. +ab. (Key point: Prefix definition)

2. (a+b)*c in postfix and prefix is:
   A. abc+* and +*abc
   B. ab+c* and +ab*c
   C. *ab+c and ab+c*
   D. ab+c* and *+abc
   Answer: D. Postfix puts operators after operands. (Key point: Example conversion)

3. P: (a + b * c + (d * e + f) * g) in postfix is:
   A. abc*+de*f+g*+
   B. abc*+de*f+g+*
   C. ab+c*de*f+g*+
   D. abc*+defg*+*+
   Answer: A. From the stack table. (Key point: Final postfix)

4. At step 7, '+' arrives with (+* on the stack. What happens?
   A. '+' is pushed above '*'
   B. '*' then '+' are popped to output; '+' is pushed
   C. Only '*' is popped
   D. '(' is popped
   Answer: B. Both have higher or equal precedence. (Key point: Precedence popping)

## 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%3Aprefix-postfix-abcdefgk) — Data Structure and Algorithm, chapter 2
- [Importance of postfix; convert expression](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Apostfix-importance-conversion) — 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%3Ainfix-prefix-postfix-tabular) — 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-convert-abcdefgh) — Data Structure and Algorithm, chapter 2, asked 3×
- [Evaluate postfix expression 574-*8/4+](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Apostfix-evaluate-574) — Data Structure and Algorithm, chapter 2
