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

# Convert and evaluate A+(B*C-(D/E^F)*G)*H

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

- Asked in: 2070 Magh, 4+1 marks
- Video: [Infix to Postfix Conversion Using Stack (No Code)](https://www.youtube.com/watch?v=rBEmgYDgVIQ) — Engineers Time
- 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/infix-postfix-evaluate-abcdefgh
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-2

## Question

Convert the following infix expression into postfix and also evaluate it: A+(B*C-(D/E^F)*G)*H

## Short answer

Postfix: ABC*DEF^/G*-H*+. Evaluating with A=2, B=3, C=4, D=8, E=2, F=3, G=5, H=2 yields 16.

## Answer

#### Conversion of A + (B * C − (D / E ^ F) * G) * H

`^` has the highest precedence and is right-associative; then `* /`; then `+ -`.

| Step | Symbol | Stack (bottom → top) | Postfix output |
|---|---|---|---|
| 1 | A | (empty) | A |
| 2 | + | + | 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\*DEF |
| 14 | ) | +(- | ABC\*DEF^/ |
| 15 | \* | +(-\* | ABC\*DEF^/ |
| 16 | G | +(-\* | ABC\*DEF^/G |
| 17 | ) | + | ABC\*DEF^/G\*- |
| 18 | \* | +\* | ABC\*DEF^/G\*- |
| 19 | H | +\* | ABC\*DEF^/G\*-H |
| end | (pop all) | (empty) | ABC\*DEF^/G\*-H\*+ |

**Postfix:** `ABC*DEF^/G*-H*+`

#### Evaluation

No values are given, so assume A = 2, B = 3, C = 4, D = 8, E = 2, F = 3, G = 5, H = 2. Operands are pushed; an operator pops the right operand first, then the left.

| Step | Symbol | Action | Stack (bottom → top) |
|---|---|---|---|
| 1 | A | push 2 | 2 |
| 2 | B | push 3 | 2, 3 |
| 3 | C | push 4 | 2, 3, 4 |
| 4 | \* | pop 4 (right), 3 (left); 3 \* 4 = 12; push | 2, 12 |
| 5 | D | push 8 | 2, 12, 8 |
| 6 | E | push 2 | 2, 12, 8, 2 |
| 7 | F | push 3 | 2, 12, 8, 2, 3 |
| 8 | ^ | pop 3 (right), 2 (left); 2 ^ 3 = 8; push | 2, 12, 8, 8 |
| 9 | / | pop 8 (right), 8 (left); 8 / 8 = 1; push | 2, 12, 1 |
| 10 | G | push 5 | 2, 12, 1, 5 |
| 11 | \* | pop 5 (right), 1 (left); 1 \* 5 = 5; push | 2, 12, 5 |
| 12 | - | pop 5 (right), 12 (left); 12 - 5 = 7; push | 2, 7 |
| 13 | H | push 2 | 2, 7, 2 |
| 14 | \* | pop 2 (right), 7 (left); 7 \* 2 = 14; push | 2, 14 |
| 15 | + | pop 14 (right), 2 (left); 2 + 14 = 16; push | 16 |

**Answer: 16** for the assumed values. Check in infix: E^F = 8, D/8 = 1, 1 × G = 5, B × C = 12, 12 − 5 = 7, 7 × H = 14, A + 14 = 16.

## Check yourself

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

1. In A+(B*C-(D/E^F)*G)*H, which operator is evaluated first inside (D/E^F)?
   A. / because it comes first from the left
   B. ^ because it has the highest precedence
   C. Both together
   D. - because it is outside the bracket
   Answer: B. ^ has higher precedence than / so E^F is done before D is divided by it. (Key point: Operator precedence)

2. How is the associativity of ^ treated during infix to postfix conversion in this answer?
   A. Left-associative
   B. Not associative
   C. Right-associative
   D. Same as + and -
   Answer: C. ^ is right-associative, so an incoming ^ does not pop an ^ already on the stack. (Key point: Right associativity of ^)

3. What is the postfix form of A+(B*C-(D/E^F)*G)*H?
   A. ABC*DEF^/G*-H*+
   B. ABC*DEF^/G*H*-+
   C. ABC*DE/F^G*-H*+
   D. AB*CDEF^/G*-H*+
   Answer: A. Following the stack table gives ABC*DEF^/G*-H*+. (Key point: Final postfix)

4. When an operator is applied during postfix evaluation, how are the two popped values used?
   A. First popped is the left operand
   B. First popped is the right operand, second is the left
   C. Both are added first
   D. The operator is pushed onto the stack
   Answer: B. The first value popped is the right operand and the second is the left, so 8 / 2 means pop 2 then 8. (Key point: Postfix evaluation order)

5. With A=2,B=3,C=4,D=8,E=2,F=3,G=5,H=2, what is the value of the expression?
   A. 14
   B. 18
   C. 16
   D. 7
   Answer: C. E^F=8, D/8=1, 1*5=5, B*C=12, 12-5=7, 7*2=14, 2+14=16. (Key point: Evaluation result)

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