34 34 votes Consider the CFG with $\left\{S, A, B\right\}$ as the non-terminal alphabet, $\{a, b\}$ as the terminal alphabet, $S$ as the start symbol and the following set of production rules:$S \rightarrow aB$ $S \rightarrow bA$$B \rightarrow b$ $A \rightarrow a$$B \rightarrow bS$ $A \rightarrow aS$$B \rightarrow aBB$ $A \rightarrow bAA$For the string $aabbab$, how many derivation trees are there?$1$$2$$3$$4$ Compiler Design gatecse-2007 compiler-design grammar normal + – go_editor 14.9k views answer comment Share Follow Print See all 8 Comments 8 8 Comments reply Show 5 previous comments harshitraj12 commented Oct 1, 2024 reply Follow flag There is No method to find Derivation Tree of given Grammar G. If it would have been possible, then problem whether a CFG G is ambiguous would be decidable, which is already proven to be undecidable. 0 0 replyShare razvardhan commented Dec 31, 2024 reply Follow flag The ans to the previous question is given in this question itself. 2 2 replyShare js__ commented Nov 2, 2025 reply Follow flag this one :- https://gateoverflow.in/1272/gate-cse-2007-question-78 1 1 replyShare Please log in or register to add a comment.
Best answer 44 44 votes $S \rightarrow aB$ $ \rightarrow aaBB$ $ \rightarrow aabB$ $ \rightarrow aabbS$ $ \rightarrow aabbaB$ $ \rightarrow aabbab$ $S \rightarrow aB$ $ \rightarrow aaBB$ (till now, only $1$ choice possible) $ \rightarrow aabSB$ $($last time we took $B \rightarrow b$, now taking $B \rightarrow bS)$ $ \rightarrow aabbAB$ $ \rightarrow aabbaB$ $ \rightarrow aabbab$ So, totally $2$ possible derivation trees. Correct Answer: $B$ Arjun answered Apr 29, 2016 • edited Jun 7, 2021 by Lakshman Bhaiya Arjun comment Share Follow See all 5 Comments 5 5 Comments reply Show 2 previous comments subhamoy1988 commented Apr 27, 2020 reply Follow flag In case anyone looking for the graphical derivation trees - below is how 'aabbab' can be generated. 9 9 replyShare s_dr_13 commented Oct 31, 2020 reply Follow flag I think it is correctly pointed out if there had been a procedure for knowing no of parse trees possible for a string ‘w’ using a CFG, then the ambiguity problem of CFG would become decidable. Just fed the algorithm with proper input, and yeep !! you know if its ambiguous or not. We know ambiguity of CFG is undecidable 2 2 replyShare Parikhit_Kurmi commented Mar 22 reply Follow flag in less time in exam hour how we can find out all possible tree like it will take lots of time 0 0 replyShare Please log in or register to add a comment.
2 2 votes we can see that 2 diagrams are possible. ankit3009 answered Nov 4, 2021 ankit3009 comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote the given grammer will generate equal numbee rof a's and b's .The 1st production will generate an extraa a then lead to other production that generate an extraa b thus equalizing number of a's and b's. and vice versa. To see all possible derivations just try to cnstruct parse tree by taking decision each time the derivation is as follows: S->aB;B->aBB; now 1we can derive the given string by choosing 1st B to derive a b so that other B can derive S which then give ab(since the rest part contains equal number of a's and b;s we generaate it by moving to the starting symbol) uniquely similarly you can give values interchange. so 2 parse tree. Radha mohan answered Nov 18, 2018 Radha mohan comment Share Follow See 1 comment 1 1 comment reply anon1 commented Oct 28, 2021 reply Follow flag No the given grammar will not generate equal number of a’s and b’s always. ex S → bAA → baa 1 1 replyShare Please log in or register to add a comment.
0 0 votes clearly see that there are two possible trees possible and first I have taken inthe string as you can see. shashankrustagi answered Nov 14, 2020 shashankrustagi comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Here is the answer Skyquake._ answered Jul 1 Skyquake._ comment Share Follow 0 reply Please log in or register to add a comment.