Prefix-Postfix-Expression

Question 1

The result evaluating the postfix expression  10  5 +  60 6 /  * 8 -   is

A
284
B
213
C
142
D
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.
Question 2

The postfix expression for the infix expression
A + B*(C + D)/F + D*E is:

A
AB + CD + *F/D + E*
B
ABCD + *F/DE*++
C
A *B + CD/F *DE++
D
A + *BCD/F* DE++
E
None of the above
Question 2 Explanation: 
The postfix expression will be,
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
* +a − bc /− de − +fgh
B
* +a −bc − /de − +fgh
C
* +a − bc /− ed + −fgh
D
* +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
A+B−C∗D
B
+A∗−BCD
C
ABC−D∗+
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  
A
abc x + def ^ ^ −
B
abc x + de ^ f ^ −
C
ab + c × d − e^f^
D
− + 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.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access