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 36–40 of 41
Consider the languages:
and
Which one of the following statements is FALSE?
and
Which one of the following statements is FALSE?
Answer: (A)
is a CFL. [Push the 's on the stack, and pop one for each .]
is a CFL. [Push the 's on the stack, and pop one for each .]
C) is True.
B) is True. CFL is closed under union. [ where is the grammar for and is the grammar for .]
CFL is not closed under intersection, so the intersection of two CFLs may or may not be a CFL. Let us check:
This is context sensitive but not context free. [One stack cannot match the 's, 's and 's together.]
So, A) is False.
D) is True.
The language {} is
Answer: (B)
Not regular: the machine must compare the number of s with , which has no bound. By the pumping lemma, take and pump a part of the first a's. The number of a's changes while the number of c's stays fixed, so the string leaves the language.
Context-free: write . A grammar is
, .
A PDA does the same job. Start with a bottom marker on the stack. Push one symbol for each , then one for each (a state change ensures the b's come after the a's). On move to a popping state (again by state change, so no a or b comes after a c) and pop one symbol for each . Accept only when the input ends and the stack shows only , so the number of c's equals exactly.
So the language is context-free but not regular.
Answer: (B)
Context-free: write . A grammar is
, .
A PDA does the same job. Start with a bottom marker on the stack. Push one symbol for each , then one for each (a state change ensures the b's come after the a's). On move to a popping state (again by state change, so no a or b comes after a c) and pop one symbol for each . Accept only when the input ends and the stack shows only , so the number of c's equals exactly.
So the language is context-free but not regular.
Answer: (B)
If the strings of a language L can be effectively enumerated in lexicographic (i.e. alphabetic) order, which of the following statements is true?
Answer: (D)
Here "lexicographic order" means shorter strings first, and strings of equal length in alphabetical order, so every string has only finitely many strings before it.
is recursive: if L is finite, it is regular and so recursive. If L is infinite, to test a word w, run the enumeration. If w comes out, accept. If a word later than w comes out first, reject, because w has been passed and will not appear. An infinite L always produces such a later word, so this always halts.
need not be context-free or regular. Take . Its strings can be enumerated in this order (test each candidate string), but it is not a CFL (pumping : the pumped part cannot contain both a's and c's). So (B) and (C) are wrong. (A) is wrong because can be enumerated in order and is infinite.
Answer: (D)
is recursive: if L is finite, it is regular and so recursive. If L is infinite, to test a word w, run the enumeration. If w comes out, accept. If a word later than w comes out first, reject, because w has been passed and will not appear. An infinite L always produces such a later word, so this always halts.
need not be context-free or regular. Take . Its strings can be enumerated in this order (test each candidate string), but it is not a CFL (pumping : the pumped part cannot contain both a's and c's). So (B) and (C) are wrong. (A) is wrong because can be enumerated in order and is infinite.
Answer: (D)
The C language is :
Answer: (B)
C needs checks that a pushdown automaton cannot make:
- a variable must be declared before it is used, which needs a comparison of the name used with the whole list of names declared (like matching the string with a copy of that comes later), and
- the formal parameters and the actual parameters of a function must match in number (and type).
These are context-sensitive conditions, not context-free ones, so the language of valid C programs is a context-sensitive language. It is not regular, since it has nested brackets which need a stack. It does not need a full Turing machine: a linear bounded automaton is enough to parse it.
Answer: (B)
- a variable must be declared before it is used, which needs a comparison of the name used with the whole list of names declared (like matching the string with a copy of that comes later), and
- the formal parameters and the actual parameters of a function must match in number (and type).
These are context-sensitive conditions, not context-free ones, so the language of valid C programs is a context-sensitive language. It is not regular, since it has nested brackets which need a stack. It does not need a full Turing machine: a linear bounded automaton is enough to parse it.
Answer: (B)
Which of the following statements true ?
Answer: (B)
- (B) is true: if and have grammars with start symbols and , add . This is a grammar for .
- (A) is false: a CFL may need a non-deterministic PDA. For example, needs a guess of where the middle is, and no DPDA can accept it.
- (C) is false: , and both are CFLs but the intersection is not.
- (D) is false: if CFLs were closed under complement, then with union they would be closed under intersection (since ), and (C) shows they are not.
Answer: (B)
- (A) is false: a CFL may need a non-deterministic PDA. For example, needs a guess of where the middle is, and no DPDA can accept it.
- (C) is false: , and both are CFLs but the intersection is not.
- (D) is false: if CFLs were closed under complement, then with union they would be closed under intersection (since ), and (C) shows they are not.
Answer: (B)
Keep practising