---
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-abcde-fgh"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/postfix-abcde-fgh
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: 2073 Bhadra, 5 marks
- Video: [Infix to Postfix conversion in Stack of Data Structure](https://www.youtube.com/watch?v=gwzB-X9BkkI) — Richa Handa
- 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-abcde-fgh
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-2

## Question

Show status of stack while converting the following infix expression to postfix expression: A+B-(C*D/E+F)-G*H.

## Short answer

Converting A+B-(C*D/E+F)-G*H yields postfix AB+CD*E/F+-GH*-. Stack: operands outputted; operators popped when equal/higher precedence appears.

## Answer

Infix: `A + B - ( C * D / E + F ) - G * H`. Equal-precedence operators are popped before pushing the new one (left-to-right).

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

**Answer:** `AB+CD*E/F+-GH*-`

## 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+CD*E/F+GH*--
   B. ABCD*E/F+-+GH*-
   C. AB+CD*E/F+-GH*-
   D. AB+CDE*/F+-GH*-
   Answer: C. Per the stack table. (Key point: Final postfix)

2. When '/' arrives with '*' on top (inside brackets), then:
   A. '/' is pushed above '*'
   B. '*' is discarded
   C. '(' is popped
   D. '*' is popped to output, '/' pushed
   Answer: D. Equal precedence pops left to right. (Key point: Equal precedence * and /)

3. At ')' the stack was -(+ . Result?
   A. Stack cleared
   B. '-' appended too
   C. '+' appended to output, '(' discarded, '-' remains
   D. '(' stays
   Answer: C. Pop until '(' then discard it. (Key point: Closing bracket)

## Related in Data Structure and Algorithm

- [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
- [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%3Ainfix-prefix-postfix-tabular) — 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-convert-abcdefgh) — Data Structure and Algorithm, chapter 2, asked 3×
