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 26–30 of 41
Let , where and are languages as defined below:
Then L is
Then L is
Answer: (C)
is context-free: it is , then one , then . is regular: it is .
A string in both must have the form and also fit . After the , allows only s, so the part must be empty, which means .
So .
This is not regular, because it needs the number of a's to equal the number of b's (pumping lemma: pumping the a's of breaks the equality). It is context-free: a PDA pushes for each a, pops for each b, then reads one c. This also follows from the fact that a CFL intersected with a regular language is always a CFL.
Answer: (C)
A string in both must have the form and also fit . After the , allows only s, so the part must be empty, which means .
So .
This is not regular, because it needs the number of a's to equal the number of b's (pumping lemma: pumping the a's of breaks the equality). It is context-free: a PDA pushes for each a, pops for each b, then reads one c. This also follows from the fact that a CFL intersected with a regular language is always a CFL.
Answer: (C)
Consider the following languages.
Which of the following is true?
Which of the following is true?
Answer: (B)
Every string of ends with at least one (). No string of contains a . So .
is not regular. If it were, = would be regular too, but pumping the a's of gives more a's than b's, which leaves the language. So option (B) is true.
Why the others are false:
- (A): is a CFL. A PDA pushes for each , pops for each , then reads one or more s.
- (C): is a CFL, since CFLs are closed under union (add a new start state that moves by to the machine for or the one for ).
- (D): has a DPDA. It pushes two symbols for each and pops one for each .
Answer: (B)
is not regular. If it were, = would be regular too, but pumping the a's of gives more a's than b's, which leaves the language. So option (B) is true.
Why the others are false:
- (A): is a CFL. A PDA pushes for each , pops for each , then reads one or more s.
- (C): is a CFL, since CFLs are closed under union (add a new start state that moves by to the machine for or the one for ).
- (D): has a DPDA. It pushes two symbols for each and pops one for each .
Answer: (B)
Which of the following is true for the language{ |p is a prime} ?
Answer: (D)
A Turing machine can test whether a given number is prime (try all divisors from 2 to ). So it accepts , and the language is recursive, which rules out (A).
It is not regular. Suppose it were, with pumping length . Take a prime and write with . Then has length , which is composite because and . So the pumped string is not in the language.
It is not context-free either. Every context-free language over a one-letter alphabet is regular (Parikh's theorem). Since this language is not regular, it cannot be context-free. This rules out (B) and (C).
Answer: (D)
It is not regular. Suppose it were, with pumping length . Take a prime and write with . Then has length , which is composite because and . So the pumped string is not in the language.
It is not context-free either. Every context-free language over a one-letter alphabet is regular (Parikh's theorem). Since this language is not regular, it cannot be context-free. This rules out (B) and (C).
Answer: (D)
The two grammars given below generate a language over the alphabet
G1 :
G2 :
Which one of the following choices describes the properties satisfied by the strings in these languages?
G1 :
G2 :
Which one of the following choices describes the properties satisfied by the strings in these languages?
Answer: (A)
Read each grammar as a regular expression.
G1: builds a string of x's and z's, which stops with the last x or z, or is followed by . B gives , so . After the first y only y and z can appear, so no x comes after a y, that is, no y appears before any x. A y can come after an x, for example xyy, so "No y appears after any x" is wrong.
G2: gives y's and z's, and the only way to get an x is with . So each x is immediately followed by a y, and then the string goes on as S or ends: . So every x is followed by at least one y. "No x appears before any y" is wrong (xy is in the language), and "Every y is followed by at least one x" is wrong (y alone is in the language).
Answer: (A)
G1: builds a string of x's and z's, which stops with the last x or z, or is followed by . B gives , so . After the first y only y and z can appear, so no x comes after a y, that is, no y appears before any x. A y can come after an x, for example xyy, so "No y appears after any x" is wrong.
G2: gives y's and z's, and the only way to get an x is with . So each x is immediately followed by a y, and then the string goes on as S or ends: . So every x is followed by at least one y. "No x appears before any y" is wrong (xy is in the language), and "Every y is followed by at least one x" is wrong (y alone is in the language).
Answer: (A)
The language over the alphabet {0,1,2} is:
Answer: (B)
Deterministic CFL. A DPDA pushes a 0 for each 0 it reads. The symbol 2 marks the middle, so it switches state on 2 without guessing, pops one 0 for each 1, and accepts if the stack is empty at the end. So is a DCFL.
Recursive. Every CFL is recursive (a decider that always halts exists), so is recursive.
Not regular. By the pumping lemma on , the pumped part lies inside the 0s, and pumping it gives with , which is not in . So (C) is false. (A) is false because is recursive, and (D) is false because is deterministic.
Answer: (B)
Recursive. Every CFL is recursive (a decider that always halts exists), so is recursive.
Not regular. By the pumping lemma on , the pumped part lies inside the 0s, and pumping it gives with , which is not in . So (C) is false. (A) is false because is recursive, and (D) is false because is deterministic.
Answer: (B)
Keep practising