Context Free Language · Theory of Computation
41 questions · asked in 24 of 27 years (2000–2026)
MCQ 36 · MSQ 51-mark 23 · 2-mark 18
2000Questions per year2026
Questions 1–5 of 41
Consider the following context-free grammar , where , , and are the variables (non-terminals), and are the terminal symbols, is the start variable, and the rules of are described as:
Which ONE of the languages is accepted by ?
Which ONE of the languages is accepted by ?
Answer: (A)
The rule produces only the strings , where (that is, one or more symbols). In the same way, the rule produces the strings , where .
So:
- gives followed by (). This is the set .
- gives () followed by . This is the set .
The language is the union of these two sets.
Answer:
So:
- gives followed by (). This is the set .
- gives () followed by . This is the set .
The language is the union of these two sets.
Answer:
Consider the following two languages over the alphabet , where and are natural numbers:
Which ONE of the following statements is CORRECT?
Which ONE of the following statements is CORRECT?
Answer: (C)
needs the number of a's to equal the number of b's, and the number of c's to be more than that number (). Use the pumping lemma on with , , . Since , it cannot touch both a's and c's.
- No c in : pump up (). Either the a's and b's become unequal, or both grow to while there are still only c's, so c's are no longer more than .
- No a in : pump down (). If has a b, the b's drop below the a's. Otherwise only c's are removed, leaving at most c's, which is not more than .
Every split fails, so is not context-free.
: the c's only need to match the total of a's and b's. One stack does this: push a symbol for each a and each b, then pop one for each c, and accept if the stack is empty exactly at the end of input. As a grammar: . is context-free.
Answer: (C)
- No c in : pump up (). Either the a's and b's become unequal, or both grow to while there are still only c's, so c's are no longer more than .
- No a in : pump down (). If has a b, the b's drop below the a's. Otherwise only c's are removed, leaving at most c's, which is not more than .
Every split fails, so is not context-free.
: the c's only need to match the total of a's and b's. One stack does this: push a symbol for each a and each b, then pop one for each c, and accept if the stack is empty exactly at the end of input. As a grammar: . is context-free.
Answer: (C)
Let be Context-Free Grammars (CFGs) and be a regular expression. For a grammar , let denote the language generated by .
Which ONE among the following questions is decidable?
Which ONE among the following questions is decidable?
Answer: (D)
Check each question:
- Is ? Undecidable. If generates , the question asks whether generates everything. That is undecidable.
- Is ? Undecidable. It can be reduced from the Post Correspondence Problem, using two CFGs that generate the solutions of the two sides of a PCP instance.
- Is ? Undecidable. Take . Then the question asks whether (universality of a CFG), which is undecidable. So a question that includes this case cannot be easier.
- Is ? Decidable. Mark every non-terminal that has a production whose right side has only terminals and already marked non-terminals. Repeat until nothing new is marked. The language is empty exactly when the start symbol is never marked.
Answer: (D)
- Is ? Undecidable. If generates , the question asks whether generates everything. That is undecidable.
- Is ? Undecidable. It can be reduced from the Post Correspondence Problem, using two CFGs that generate the solutions of the two sides of a PCP instance.
- Is ? Undecidable. Take . Then the question asks whether (universality of a CFG), which is undecidable. So a question that includes this case cannot be easier.
- Is ? Decidable. Mark every non-terminal that has a production whose right side has only terminals and already marked non-terminals. Repeat until nothing new is marked. The language is empty exactly when the start symbol is never marked.
Answer: (D)
Which of the following statements is/are CORRECT?
One or more options are correct.
Answer: (A), (C), (D)
Let us check each statement one by one:
- Regular languages are closed under intersection so this is TRUE.
- CFLs are not closed under intersection: so this is FALSE.
- Recursive languages: run both deciders and accept if both accept so this is TRUE.
- RE languages: run both recognizers and accept when both accept so this is TRUE.
Answer: Options 1, 3 and 4
- Regular languages are closed under intersection so this is TRUE.
- CFLs are not closed under intersection: so this is FALSE.
- Recursive languages: run both deciders and accept if both accept so this is TRUE.
- RE languages: run both recognizers and accept when both accept so this is TRUE.
Answer: Options 1, 3 and 4
Consider the following languages:
Note that is the reversal of the string . Which of the following is/are TRUE?
Note that is the reversal of the string . Which of the following is/are TRUE?
One or more options are correct.
Answer: (A), (B), (C)
- : n may be 0. With we get for every , so (every string is in it, and the language only has strings over a and b). This is regular.
- : and . The last symbol of is the first symbol of , so every string of starts and ends with the same symbol and has length at least 3. Conversely, such a string is with and a non-empty middle . So , which is regular.
Both languages are regular, so both are also context-free. (A), (B) and (C) are true. (D) is false because it says they are not regular.
Answer: (A), (B), (C)
- : and . The last symbol of is the first symbol of , so every string of starts and ends with the same symbol and has length at least 3. Conversely, such a string is with and a non-empty middle . So , which is regular.
Both languages are regular, so both are also context-free. (A), (B) and (C) are true. (D) is false because it says they are not regular.
Answer: (A), (B), (C)
Keep practising