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

Best answer
65 votes
65 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
9 votes
9 votes

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

8 votes
8 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$

5 votes
5 votes
It will be B.

It will use a maximum 4 level stack.
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,727 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^+...