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 11–15 of 41
Consider the following languages.
Which one of the following is TRUE?
Which one of the following is TRUE?
Answer: (A)
is regular. Let a string be with non-empty, and let c be the last symbol of x, so . Then the string is , which is with and non-empty. Conversely, a string of this form is in with . So the length of x does not matter and is the set of strings of the form (non-empty) c (non-empty) c with one bit c:
.
is context-free. It consists of the even-length strings whose two halves are different, so some position i in the first half has a different symbol from position i in the second half. Such a string is (or the same with a and b swapped) with and ; the a and the b are then exactly half the length apart. A grammar for it: . (A PDA can do the same by guessing the mismatch.)
Answer: (A)
.
is context-free. It consists of the even-length strings whose two halves are different, so some position i in the first half has a different symbol from position i in the second half. Such a string is (or the same with a and b swapped) with and ; the a and the b are then exactly half the length apart. A grammar for it: . (A PDA can do the same by guessing the mismatch.)
Answer: (A)
Which one of the following languages over is NOT context-free?
Answer: (C)
- : even palindromes, so CFL.
- : nested, and on the outside and inside, so CFL: .
- : the union of , and , each a CFL, so CFL.
- : the pair has inside it, while the pair has inside it. The pairs cross instead of nesting, and one stack can only match nested pairs. So this is not a CFL.
Answer: (C)
- : nested, and on the outside and inside, so CFL: .
- : the union of , and , each a CFL, so CFL.
- : the pair has inside it, while the pair has inside it. The pairs cross instead of nesting, and one stack can only match nested pairs. So this is not a CFL.
Answer: (C)
Consider the following languages:
I.
II.
III.
IV.
Which of the languages above are context-free?
I.
II.
III.
IV.
Which of the languages above are context-free?
Answer: (B)
- I: means , so one signed counter is enough. Keep it on the stack: it holds either some A's (counter positive) or some B's (counter negative), never both. Each a or c adds one: pop a B if the top is B, else push A. Each b or d subtracts one: pop an A if the top is A, else push B. Accept if the stack is empty at the end. It is a CFL.
- II: is followed by : . It is a CFL.
- III: this is with . Erase the d's with a homomorphism (d to empty). For any n we can pick , so the image is , which is not context-free. CFLs are closed under homomorphism, so III is not a CFL.
- IV: intersect with the regular language (no d's, so ). This leaves . Take and . Then vxy cannot touch both a's and c's, since the b's between them number p. Pump up once more (i = 2); the pumped part adds a's, b's and c's, not all zero.
If : the c's stay at but , so the string is not in the language.
If : then , and we would need , that is . If this gives , a contradiction. If then , but , a contradiction.
So IV is not a CFL.
Answer: (B)
- II: is followed by : . It is a CFL.
- III: this is with . Erase the d's with a homomorphism (d to empty). For any n we can pick , so the image is , which is not context-free. CFLs are closed under homomorphism, so III is not a CFL.
- IV: intersect with the regular language (no d's, so ). This leaves . Take and . Then vxy cannot touch both a's and c's, since the b's between them number p. Pump up once more (i = 2); the pumped part adds a's, b's and c's, not all zero.
If : the c's stay at but , so the string is not in the language.
If : then , and we would need , that is . If this gives , a contradiction. If then , but , a contradiction.
So IV is not a CFL.
Answer: (B)
Consider the context-free grammars over the alphabet {a,b,c} given below. S and T are non-terminals
The language is
The language is
Answer: (B)
Here (S makes matching a's and b's around T, and T makes the c's) and .
A string of with starts with a. Every string of is empty or starts with b or c, so no such string is in both. So only is left in , giving , and each is also in (with ). So the intersection is , which is infinite and regular.
Answer: (B)
A string of with starts with a. Every string of is empty or starts with b or c, so no such string is in both. So only is left in , giving , and each is also in (with ). So the intersection is , which is infinite and regular.
Answer: (B)
Consider the following languages over the alphabet .
Let and
Which of the following are context-free languages ?
I.
II.
Let and
Which of the following are context-free languages ?
I.
II.
Answer: (A)
- and are each context-free: for and the mirror grammar for . CFLs are closed under union, so is a CFL. I is true.
- A string in has the form with (from ) and (from ). So . This is not context-free: in the pumped part cannot contain both a's and c's, so pumping up raises one letter's count and leaves another at p. II is false.
Answer: (A)
- A string in has the form with (from ) and (from ). So . This is not context-free: in the pumped part cannot contain both a's and c's, so pumping up raises one letter's count and leaves another at p. II is false.
Answer: (A)
Keep practising