---
title: "Convert A+B-C*(D-E+F/G)/H to postfix"
subject: "Data Structure and Algorithm"
chapter: 2
key: "semester_4/data_structure_and_algorithm:postfix-convert-abcdefgh"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/postfix-convert-abcdefgh
site: BCT Engineering
---

# Convert A+B-C*(D-E+F/G)/H to postfix

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

- Asked in: 2074 Bhadra, 10 marks
- Video: [Lec-40: Infix to postfix Conversion using Stack | Infix➡️Postfix Conversion with examples](https://www.youtube.com/watch?v=N1Sr-j-cf4c) — Gate Smashers
- 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-convert-abcdefgh
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-2

## Question

Convert A + B - C * (D - E + F/G) / H expression into postfix expression using stack.

## Short answer

Scanning A+B-C*(D-E+F/G)/H with stack and precedence rules (pop higher/equal) gives postfix AB+CDE-FG/+*H/-.

## Answer

Rules: operand → output; `(` → push; `)` → pop to output until `(`; operator → pop operators of higher or equal precedence, then push; at the end pop everything. Precedence: `* /` above `+ -`; equal precedence is evaluated left to right.

Infix: `A + B - C * (D - E + F / G) / H`

| Step | Symbol | Stack (bottom → top) | Postfix output |
|---|---|---|---|
| 1 | A | (empty) | A |
| 2 | + | + | A |
| 3 | B | + | AB |
| 4 | - | - | AB+ |
| 5 | C | - | AB+C |
| 6 | \* | -\* | AB+C |
| 7 | ( | -\*( | AB+C |
| 8 | D | -\*( | AB+CD |
| 9 | - | -\*(- | AB+CD |
| 10 | E | -\*(- | AB+CDE |
| 11 | + | -\*(+ | AB+CDE- |
| 12 | F | -\*(+ | AB+CDE-F |
| 13 | / | -\*(+/ | AB+CDE-F |
| 14 | G | -\*(+/ | AB+CDE-FG |
| 15 | ) | -\* | AB+CDE-FG/+ |
| 16 | / | -/ | AB+CDE-FG/+\* |
| 17 | H | -/ | AB+CDE-FG/+\*H |
| end | (pop all) | (empty) | AB+CDE-FG/+\*H/- |

**Answer:** `AB+CDE-FG/+*H/-`

Check with a tree: the expression is `(A+B) − ((C * (…)) / H)`, where the bracket is `(D−E) + (F/G)`. Post-order of this tree gives `AB+CDE-FG/+*H/-`.

## Check yourself

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

1. The postfix of A + B - C * (D - E + F/G) / H is:
   A. AB+CDE-FG/+*H/-
   B. AB+CDE-FG/+*H-/
   C. ABCDE-FG/+*H/+-
   D. AB+CD-E+FG/*H/-
   Answer: A. Matches the stack table. (Key point: Final postfix)

2. When '+' arrives in (D - E + ...), the stack top is '-'. What happens?
   A. '-' is popped to output, then '+' is pushed
   B. '+' is pushed above '-'
   C. '(' is popped
   D. '+' goes to output
   Answer: A. Equal precedence is evaluated left to right. (Key point: Equal precedence)

3. At ')' the output becomes AB+CDE-FG/+. What is left on the stack?
   A. -*(
   B. (+/
   C. -*
   D. Empty
   Answer: C. Operators back to '(' are popped and '(' is discarded. (Key point: Closing bracket)

4. After the last symbol H, the stack holds -/ . What is appended at the end?
   A. - then /
   B. Nothing
   C. * then -
   D. / then -
   Answer: D. Pop all from top: / first, then -. (Key point: Final steps)

## Close variants set in other exams

- [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×

## 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
- [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
- [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
- [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
