• recategorized by
49,633 views
63 63 votes

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

  1. $AB + CD + *F/D +E*$
  2. $ABCD + *F/DE* ++$

  3. $A * B + CD/F *DE ++$

  4. $A + *BCD/F* DE ++$

8 Answers

Best answer
87 87 votes

Thus before considering + which has the least priority, we get  $A + (BCD+*F/) + (DE*)$

Now if we assume left associativity for $+$ (default), we get $ABCD+*F/ + DE*+$ but this is not among the options.

So, considering right associativity for $+$ we get $ABCD+*F/DE*++$

Correct Answer: $B$

• edited by
19 19 votes

it is 4 level stak and postfix is: ABCD+*F/+DE*+
 

• edited by
12 12 votes

Infix to Postfix using Stack :

If (  ‘(‘  ) 

  push in stack 


If (  ‘)‘  ) 

  pop until left parenthesis is popped  
 

If ( operator ) 

    1. Lower priority (w.r.t to Stack Top ) is in input then pop 
    2. Higher priority input in input then push
    3. Same priority then pop


If ( operand ) 

     ignore 

 

Now using the above algorithm , let us evaluate   A + B * (C + D) / F + D * E  :

 

Steps          Stack Element                  Output

Step 1 : Ignore A (as it’s operand ) 

 

                       A

Step 2: Since Stack is empty push ‘+’ 

 

                  +                      A

Step 3: Ignore B (as it’s operand )

 

                      AB

Step 4 : * has Higher priority than + so push

 

                 * +                     AB

Step 5 : push ‘ ( ‘ in stack 

 

                ( * +                     AB

Step 6 : Ignore C (as it’s operand )

 

                ( * +                    ABC

Step 7 : push ‘+’ in stack 

 

               + ( * +                    ABC

Step 8 : Ignore D (as it’s operand )

 

              + ( * +                   ABCD

Step 9 : pop until left parenthesis is popped  

 

                 *+                  ABCD+

Step 10 : ‘/’  has same priority as ‘*’  , so pop ‘*’ and push ‘/’  into stack as ‘/’ has higher priority than ‘+’

 

                  /+                  ABCD+*

Step 11 : Ignore F (as it’s operand )

 

                 /+                  ABCD+*F

Step 12 : ‘+’ has lower priority than ‘/’ , so pop ’/’ and push ’+’ 

 

                 ++                  ABCD+*F/

Step 13 : Ignore D (as it’s operand )

 

                 ++                  ABCD+*F/D

Step 14 : push ‘*’ as it has higher preceedence than ‘+’ 

 

                 *++                  ABCD+*F/D

Step 15 : Ignore E (as it’s operand )

 

                 *++                 ABCD+*F/DE

Step 16 : We have ‘*’ , ‘+’ , ‘+’ in the stack . Just empty the stack 

 

                                  ABCD+*F/DE*++

 

 

Correct Ans : Option ( B )  ABCD+*F/DE*++

 

 

 

 

 

 

 

 

 

 

 

 

9 9 votes
$Top\ of\ stack$ $Next$  
$Low\ priority$ $High\ priority$ $PUSH$
$High\ priority$ $Low\ priority$ $POP$
 $Same\ priority\ (Left-to-Right\ associativity)$ $POP$
 $Same\ priority\ (Right-to-Left\ associativity)$ $PUSH$

According to this answer should be : $ABCD+*F/+DE*+$

We are getting this answer because in the operator stack when $+$ is on the top of the stack and the next symbol is $+$ we are doing a pop operation which has to be done.

But in order to get one of the options as an answer we need to change the associativity of $+$ and when $+$ is on the top of the stack and the next symbol is $+$ we will do a push operation and hence we will get an expression :  $ABCD+*F/DE*++$  which is leading to option $B$

• edited by
6 6 votes
It will be B.

It will use a maximum 4 level stack.
0 0 votes
B is the answer if you want to verify just push the symbols into the stack whenever you get an operator just pop last two symbols and operate them with the oprator and then check with the infix.You will get your answer.
Answer:
Position:
Show:

Related questions

32 32 votes
6 answers 6 answers
20.8k
20.8k views
Kathleen asked Oct 8, 2014
20,790 views
Let $\Sigma=\left\{0,1\right\}, L = \Sigma^*$ and $R=\left\{0^n1^n \mid n 0\right\} $ then the languages $L \cup R$ and $R$ are respectivelyregular, regularnot regular, ...
45 45 votes
10 answers 10 answers
16.3k
16.3k views
Kathleen asked Oct 8, 2014
16,308 views
Which of the following definitions below generate the same language as $L$, where $L=\{x^ny^n \text{ such that } n\geq 1 \}$?$E \rightarrow xEy\mid xy$$x y \mid (x^+xyy^+...
39 39 votes
6 answers 6 answers
11.7k
11.7k views
Kathleen asked Oct 8, 2014
11,689 views
What values of $A, B, C$ and $D$ satisfy the following simultaneous Boolean equations?$\overline{A} + AB =0, AB=AC, AB+A\overline{C}+CD=\overline{C}D$$A=1, B=0, C=0, D=1$...
15 15 votes
7 7 answers
10.9k
10.9k views
Kathleen asked Oct 8, 2014
10,889 views
What is the value of $X$ printed by the following program?program COMPUTE (input, output); var X:integer; procedure FIND (X:real); begin X:=sqrt(X); end; begin X:=2 FIND(...