ISRO Scientist/Engineer CSE 2020Data Structures › Stacks and Expression Evaluation
ISRO Scientist/Engineer CSE 2020 PYQ: Convert the pre-fix expression to in-fix $- ^{\ast} +ABC^{\ast} – DE+FG$
Convert the pre-fix expression to in-fix $- ^{\ast} +ABC^{\ast} – DE+FG$
- A$(A-B)^{\ast}C+(D^{\ast}E)-(F+G)$
- B$(A+B)^{\ast}C-(D-E)^{\ast}(F+G)$Correct answer
- C$(A+B-C)^{\ast}(D-E)^{\ast}(F+G)$
- D$(A+B)^{\ast}C-(D^{\ast}E)-(F+G)$
Answer
(B) $(A+B)^{\ast}C-(D-E)^{\ast}(F+G)$
Approach
Parse the prefix expression $- * + A B C * - D E + F G$ using a stack, scanning left to right. Each operator pops its two operands (left operand first, then right operand) and pushes the resulting infix sub-expression. The final stack content is the fully parenthesized infix expression, which matches option B.
Reviewed by ISRO IQ Editorial Team.