recategorized by
38,083 views
49 votes
49 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 ++$

recategorized by

7 Answers

4 votes
4 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*++

 

 

 

 

 

 

 

 

 

 

 

 

0 votes
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:

Related questions

10 votes
10 votes
3 answers
1
Arjun asked Feb 18, 2021
8,224 views
Consider the following sequence of operations on an empty stack.$$\textsf{push}(54);\textsf{push}(52);\textsf{pop}();\textsf{push}(55);\textsf{push}(62);\textsf{s}=\texts...
26 votes
26 votes
3 answers
2
26 votes
26 votes
5 answers
3
Kathleen asked Oct 8, 2014
15,731 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, ...
32 votes
32 votes
8 answers
4
Kathleen asked Oct 8, 2014
10,424 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^+...