CUET PG 2021 — Computer PYQ
CUET PG | Computer | 2021To evaluate an expression without any embedded function calls
Choose the correct answer:
- A.
one stack is enough
- B.
two stacks are needed
(Correct Answer) - C.
as many stacks as the height of the expression tree are needed
- D.
a Turing machine is needed in the general case
two stacks are needed
Explanation
Solving: Expression Evaluation Logic
Jab hum kisi normal (Infix) expression ko bina function calls ke solve karte hain, toh computer use Stack Data Structure ki madad se process karta hai.
1. Expression Conversion:
Computer sabse pehle standard expression (Infix) ko computer-friendly format (Postfix) mein badalta hai:
2. Stack Evaluation Rule:
Bina function call ke expression ko solve karne ka rule niche diya gaya hai:
-
Agar Operand (number) mile ⟹ Stack mein Push karein.
-
Agar Operator (+,−,×,÷) mile ⟹ Do operands ko Pop karein, solve karein aur result wapas Push karein.
Step-by-Step Mathematical Example
Expression: 3+4×2 (Infix)
Postfix equivalent: 3,4,2,×,+
| Step | Symbol | Action | Stack State |
| 1 | 3 | Push 3 | [3] |
| 2 | 4 | Push 4 | [3, 4] |
| 3 | 2 | Push 2 | [3, 4, 2] |
| 4 | × | Pop 2, 4 → 4×2=8 | [3, 8] |
| 5 | + | Pop 8, 3 → 3+8=11 | [11] |
Final Result:
Final Answer
Bina function calls wale expression ko evaluate karne ke liye Stack Data Structure aur Postfix Notation ka upyog kiya jata hai. Is technique ko Stack-based evaluation kehte hain.

