edited by
15,553 views
24 votes
24 votes
Q- Which one of following languages is inherently ambiguous?

(A) The set of all strings of the form $\left\{a^nb^n,n>0 \right\}$

(B) $\left\{a^nb^nc^md^m,n,m>0 \right\}$

(C) $\left\{a^nb^nc^md^m,n,m>0 \right\}\;\cup \;\left\{a^nb^mc^md^n,n,m>0 \right\}$

(D) Both (B) and (C)

Plz explain..

..........Is there any criteria on the basis of which we could identify inherently ambiguous grammar
related to an answer for: ambiguity in grammar
edited by

2 Answers

Best answer
47 votes
47 votes

Answer is C

Yes, there is some criteria to check inherent ambiguity

First of all , Inherent ambiguity term is used for language, not for grammar.

A language for which every grammar (you can design ) is ambiguous. 

There may be many grammar for one language 

say $L$ is $a^n \;,\;n> 0$ mean $a^+$ , $L =\left\{a,aa,aaa,aaaa,..\right\}$

There is  a CFG $S \rightarrow aS|Sa|a$ , which is ambiguous as we can derive one word say ,$aa$, using different ways and having different tree also. This CFG is ambiguous but language is not inherent ambiguous.

 because we have a CFG $S \rightarrow aS|a$ for same language that is unambiguous.

So you can say, for a language for which no unambiguous grammar is possible is inherent ambiguous language 

As in option C , language is two different language for which CFG cannot be designed without using 

$S\rightarrow S_1 | S_2$

where $S_1\rightarrow XY$

$X\rightarrow aXb | ab$

$Y \rightarrow cYd | cd$

and $S_2 \rightarrow aSd |aZd$

$Z\rightarrow bZc| bc$

This is only and only way to design CFG for Language. 

and This language is ambiguous also 

you can derive word $abcd$  using $S\rightarrow S_1$  and also Using $S\rightarrow S_2$ 

So Language is Inherent Ambiguous .

[other words you can check $aabbccdd$ or $aaabbbcccddd$ ..i,e common in both parts of language]

selected by
8 votes
8 votes

till DCFL a language must be unambiguous. i.e there must be exist a unambiguous grammar for dcfl language.

so at first we check a grammar is dcfl or not. if it is dcfl then we can easylly say it is unambiguous language.in this question option a and b is dfcl so it is unambiguous language. 

but for option c it is cfl . but not dcfl so we need to check there exist a grammar which is unambiguous.

edited by

Related questions