- Asked 2/14
- 2068 Magh · 6 marks
Convert and evaluate (A+B)*(C-D)
Short answer
Postfix: AB+CD-*. Evaluating with A=5, B=7, C=9, D=4 yields 60.
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.
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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Convert and evaluate A/B-(C+D)*E · Data Structure and Algorithm, chapter 2 · asked 2×
- Convert expression to prefix and postfix · Data Structure and Algorithm, chapter 2
- Importance of postfix; convert expression · Data Structure and Algorithm, chapter 2
- Evaluate postfix expression 574-*8/4+ · Data Structure and Algorithm, chapter 2
- Infix to postfix and evaluation · Data Structure and Algorithm, chapter 2
- Convert expression to prefix and postfix · Data Structure and Algorithm, chapter 2
- Algorithm for infix to postfix conversion · Data Structure and Algorithm, chapter 2 · asked 3×