Consider the following context-free grammars: G1:S→aS|B,B→b|bB G2:S→aA|bB,A→aA|B|ε,B→bB|ε WhichoneofthefollowingpairsoflanguagesisgeneratedbyG1andG2,respectively?
A
{ambn|m>0andn>0}and{ambn|m>0orn≥0}
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
{ambn|m≥0andn>0}and{ambn|m>0orn>0}
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
{ambn|m>0orn>0}and{ambn|m>0andn>0}
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
{ambn|m≥0orn>0}and{ambn|m>0andn>0}
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution
The correct option is B{ambn|m≥0andn>0}and{ambn|m>0orn>0} G1:S→aS|B B→b|bB G2:S→aA|bB A→aA|B|ε B→bB|ε G:B→b|bB⇒B→b+ NowsubstituteinS→aS|B WegetS→aS|b+⇒S→a∗b+ So,L(G1)={ambn|m≥0andn>0} G2=B→bB|ε⇒B→b∗
Substitute in A →aA|B|ε⇒A→aA|b∗|ε ⇒A→aA|b∗ ⇒A→a∗b∗ NowsubstituteAandBinS→aA|bB ⇒S→aa∗b∗|bb∗ S→aa∗b∗+bb∗ So,L(G2)={ambn|m>0orn>0}
So correct answer is choice (d).