Prefix-Postfix-Expression
Question 1 |
The result evaluating the postfix expression 10 5 + 60 6 / * 8 - is
284 | |
213 | |
142 | |
71 |
Question 1 Explanation:
→ '10' is pushed in the stack
→ '5' is pushed in the stack
→ '+' comes so addition will be done by popping the top two elements in the stackand the result is pushed back into the stack, i.e., 10+5 = 15
→ 60 pushed in the stack
→ 6 pushed in the stack
→ '/' comes. So, 60/6 = 10
→ '*' comes. So, 15 * 10 = 150
→ '8' comes, push in the stack
→ '-' comes. So, 150-8 = 142
So the final result is 142.
→ '5' is pushed in the stack
→ '+' comes so addition will be done by popping the top two elements in the stackand the result is pushed back into the stack, i.e., 10+5 = 15
→ 60 pushed in the stack
→ 6 pushed in the stack
→ '/' comes. So, 60/6 = 10
→ '*' comes. So, 15 * 10 = 150
→ '8' comes, push in the stack
→ '-' comes. So, 150-8 = 142
So the final result is 142.
Question 2 |
The postfix expression for the infix expression
A + B*(C + D)/F + D*E is:
AB + CD + *F/D + E* | |
ABCD + *F/DE*++ | |
A *B + CD/F *DE++ | |
A + *BCD/F* DE++ | |
None of the above |
Question 2 Explanation:
The postfix expression will be,
A B C D + * F / + D E * +
A B C D + * F / + D E * +
Question 3 |
Choose the equivalent prefix form of the following expression (a + (b − c))* ((d − e)/(f + g − h))
* +a − bc /− de − +fgh | |
* +a −bc − /de − +fgh | |
* +a − bc /− ed + −fgh | |
* +ab − c /− ed + −fgh |
Question 3 Explanation:
→ An expression is called the prefix expression if the operator appears in the expression before the operands.




Question 4 |
The infix expression A+(B–C)*D is correctly represented in prefix notation as
A+B−C∗D | |
+A∗−BCD | |
ABC−D∗+ | |
A+BC−D∗ |
Question 4 Explanation:
Given Expression = A + (B – C)* D
Prefix Notation:
A + (- B C) * D
A + (* - B C D)
+ A * - B C D
Question 5 |
Assume that the operators +, −, × are left associative and ^ is right associative. The order of precedence (from highest to lowest) is ^, ×, +, −. The postfix expression corresponding to the infix expression is
a + b × c − d ^ e ^ f
abc x + def ^ ^ − | |
abc x + de ^ f ^ − | |
ab + c × d − e^f^ | |
− + a × b c^^ def |
Question 5 Explanation:
The operators in the expression are +,x,- ^
First we will convert e^f ad ef^ (as highest precedence and right associativity) and later
d ^( e f ^ ) to def^^ and so on , you can find the same thing from the below steps.
The postfix expression:
a + b × c − ( d ^( e ^ f))
a + b × c − ( d ^( e f ^ ))
a + b × c − ( d e f ^ ^)
(a + (b × c)) − d e f ^ ^
(a + (b c x)) − d e f ^ ^
(a (b c x) +) − d e f ^ ^
(a b c x +) - (d e f ^ ^)
(a b c x +) - (d e f ^ ^)
a b c x + d e f ^ ^ -
There are 5 questions to complete.
