Question 11: Convert the following infix to postfix expression: w+x y+(z a) Answer - Option...
TCS aptitude question, verified with a worked answer. Free to practise - no sign-up.
Convert the following infix to postfix expression: w+xy+(za) Answer - Option C - A) wxy*+(za)+ - B) w+xyza+* - C) wxy*+za*+ - D) wxy+za+
Show answer & explanation
Infix to postfix conversion follows the order of operations (PEMDAS/BODMAS). Multiplication has higher precedence than addition, and parentheses are processed first, resulting in the operators being placed after their respective operands.
Step-by-step Derivation:
Step 1: Analyze the expression w + x * y + (z * a).
Step 2: Handle the parentheses first: (z * a) becomes za*.
Step 3: The expression is now w + x * y + za*.
Step 4: Process the first multiplication x * y (higher precedence than addition): xy*.
Step 5: The expression is now w + xy* + za*.
Step 6: Process the first addition from left to right: w + xy* becomes wxy*+.
Step 7: The expression is now wxy*+ + za*.
Step 8: Process the final addition: wxy*+ and za* combined with + becomes wxy*+za*+.