GATE Exam  >  GATE Questions  >  Consider the following languages over the alp... Start Learning for Free
Consider the following languages over the alphabet ∑= {a,b,c}. Let L1 = {an bncm | m, n >= 0 } and L2 = {ambncn| m, n >= 0}. 

Q. Which of the following are context-free languages? 
I. L1 ∪ L2 
II. L1 ∩ L2 
  • a)
    I only
  • b)
    II only
  • c)
    I and II
  • d)
    Neither I nor II
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Consider the following languages over the alphabet ∑= {a,b,c}. L...
Union of context free language is also context free language.
L1 = { an bn cm| m >= 0 and n >= 0 } and
L2 = { am bncn| n >= 0 and m >= 0 }
L3 = L1 ∪ L2 = { anbncm∪ ambncn| n >= 0, m >= 0 } is also context free.
L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. Their union says either of two conditions to be true. So it is also context free language.
Intersection of CFG may or may not be CFG.
L3 = L1 ∩ L2 = { anbncn| n >= 0 } need not be context free. 
View all questions of this test
Most Upvoted Answer
Consider the following languages over the alphabet ∑= {a,b,c}. L...
To determine whether the given languages L1 and L2 are context-free languages, we need to check if there exists a context-free grammar (CFG) that generates these languages.

L1 = {anbncm | m, n = 0 }
L2 = {ambncn | m, n = 0}

Let's analyze each language separately:

L1:
The language L1 consists of strings of the form anbncm, where the number of 'a's is equal to the number of 'b's and the number of 'c's is arbitrary (m can be zero or more). This language can be generated by a context-free grammar as follows:

S -> ε (start symbol)
S -> aSb (produces an equal number of 'a's and 'b's)
S -> cS (produces zero or more 'c's)

This CFG generates all the strings in L1. Therefore, L1 is a context-free language.

L2:
The language L2 consists of strings of the form ambncn, where the number of 'a's is arbitrary (m can be zero or more) and the number of 'b's is equal to the number of 'c's. This language can be generated by a context-free grammar as follows:

S -> ε (start symbol)
S -> aS (produces zero or more 'a's)
S -> bSc (produces an equal number of 'b's and 'c's)

This CFG generates all the strings in L2. Therefore, L2 is a context-free language.

Combining L1 and L2:
Now, let's consider the combination of L1 and L2, i.e., L1 ∩ L2. In this case, we need to generate strings of the form anbncmambncn, where m and n can be zero or more. Notice that the languages L1 and L2 have different orders of 'a's, 'b's, and 'c's. It is not possible to generate such strings using a context-free grammar because the grammar would need to keep track of the number of 'a's and 'b's in two different places. Therefore, L1 ∩ L2 is not a context-free language.

Conclusion:
Based on the analysis above, we can conclude that L1 is a context-free language, L2 is a context-free language, but L1 ∩ L2 is not a context-free language. Therefore, option (a) "I only" is the correct answer.
Explore Courses for GATE exam
Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer?
Question Description
Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer?.
Solutions for Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer?, a detailed solution for Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following languages over the alphabet ∑= {a,b,c}. Let L1= {anbncm| m, n >= 0 } and L2= {ambncn| m, n >= 0}.Q. Which of the following are context-free languages?I.L1∪ L2II.L1∩ L2a)I onlyb)II onlyc)I and IId)Neither I nor IICorrect answer is option 'A'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev