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

# Convert and evaluate (A+B)*(C-D)

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

- Asked in: 2068 Magh, 6 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-evaluate-ab-cd
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-2

## Question

Convert the given infix expression (A+B)*(C-D) into equivalent postfix expression showing each step in tabular form and evaluate the obtained postfix expression showing STACK status each time when A=5, B=7, C=9 and D=4.

## Short answer

Postfix: AB+CD-*. Evaluating with A=5, B=7, C=9, D=4 yields 60.

## Answer

#### Conversion of (A + B) * (C − D)

| Step | Symbol | Stack (bottom → top) | Postfix output |
|---|---|---|---|
| 1 | ( | ( | - |
| 2 | A | ( | A |
| 3 | + | (+ | A |
| 4 | B | (+ | AB |
| 5 | ) | (empty) | AB+ |
| 6 | \* | \* | AB+ |
| 7 | ( | \*( | AB+ |
| 8 | C | \*( | AB+C |
| 9 | - | \*(- | AB+C |
| 10 | D | \*(- | AB+CD |
| 11 | ) | \* | AB+CD- |
| end | (pop all) | (empty) | AB+CD-\* |

**Postfix:** `AB+CD-*`

#### Evaluation with A = 5, B = 7, C = 9, D = 4

| Step | Symbol | Action | Stack (bottom → top) |
|---|---|---|---|
| 1 | A | push 5 | 5 |
| 2 | B | push 7 | 5, 7 |
| 3 | + | pop 7 (right), 5 (left); 5 + 7 = 12; push | 12 |
| 4 | C | push 9 | 12, 9 |
| 5 | D | push 4 | 12, 9, 4 |
| 6 | - | pop 4 (right), 9 (left); 9 - 4 = 5; push | 12, 5 |
| 7 | \* | pop 5 (right), 12 (left); 12 \* 5 = 60; push | 60 |

**Answer: 60**. Check: (5+7) × (9−4) = 12 × 5 = 60.

## Check yourself

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

1. Why does the postfix of (A+B)*(C-D) have + and - before *?
   A. Because brackets make both sums happen first
   B. Because * has lowest precedence
   C. Because postfix always puts + first
   D. Because operators are sorted
   Answer: A. The bracketed operations are completed before the multiplication. (Key point: Bracket effect)

2. What is the postfix expression?
   A. AB+CD-*
   B. AB+C-D*
   C. ABCD+-*
   D. A+B*C-D
   Answer: A. (A+B) gives AB+, (C-D) gives CD-, then * gives AB+CD-*. (Key point: Postfix result)

3. Evaluating CD- with C=9, D=4, what is computed?
   A. 4 - 9 = -5
   B. 9 - 4 = 5
   C. 9 + 4 = 13
   D. 9 * 4 = 36
   Answer: B. The first popped (4) is the right operand and 9 is the left, so 9-4 = 5. (Key point: Operand order for -)

4. With A=5,B=7,C=9,D=4, what is the value of AB+CD-*?
   A. 17
   B. 35
   C. 60
   D. 12
   Answer: C. (5+7)*(9-4) = 12*5 = 60. (Key point: Final value)

## Close variants set in other exams

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

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