Context free languages and Push-down automata
Question 1 |
L2 is context-free. | |
L1 intersection L2 is context-free. | |
Complement of L2 is recursive. | |
Complement of L1 is context-free but not regular. |
Discuss it
Question 2 |
Deterministic finite automata(DFA) and Non-deterministic finite automata(NFA) | |
Deterministic push down automata(DPDA)and Non-deterministic push down automata(NPDA) | |
Deterministic single-tape Turing machine and Non-deterministic single-tape Turing machine | |
Single-tape Turing machine and multi-tape Turing machine |
Discuss it
NDPDA can handle languages or grammars with ambiguity, but DPDA cannot handle languages with ambiguity and any context-free grammar.
Question 3 |
Let P be a regular language and Q be context-free language such that Q P. (For example, let P be the language represented by the regular expression p*q* and Q be {pnqn|n
N}). Then which of the following is ALWAYS regular? (A) P
Q (B) P - Q (C)
* - P (D)
* - Q
A | |
B | |
C | |
D |
Discuss it
1. P ∩ Q would be Q, due to the given fact that Q ⊆ P, hence context free but not regular. 2. P − Q = P ∩ Q might not even be a context free language, due to the closure properties of context free languages. 3. Σ∗ − P is equivalently complement of P, hence regular. Refer to closure laws of regular languages. 4. Σ∗ − Q is equivalently complement of Q, hence it might not even be a context free language. Refer to closure laws of CFLs. Reference: https://www.geeksforgeeks.org/closure-properties-of-context-free-languages/ See http://www.geeksforgeeks.org/automata-theory-set-4/ This solution is contributed by Vineet Purswani.
Question 4 |






Push Down Automata (PDA) can be used to recognize L1 and L2 | |
L1 is a regular language | |
All the three languages are context free | |
Turing machine can be used to recognize all the three languages |
Discuss it
L2 is not regular, can be proved using pumping lemma (refer to Ullman). But L2 is CFL.
S → AB A → 0A|ε B → 1B|εL3 is not CFL, can be proved using pumping lemma (refer to Ullman). But L3 is Recursive.

S → AB A → 0A|ε B → 1B|εL3 is not CFL, can be proved using pumping lemma (refer to Ullman). But L3 is Recursive. Every regular language is also a CFL. So PDA can be used to recognised L1 and L2. As a CFL and Regular language is algo a Recursive language. Hence, turing machine can be used to recognise L1, L2 and L3. Source: http://clweb.csa.iisc.ernet.in/rahulsharma/gate2011key.html
Question 5 |
Only L2 is context free | |
Only L2 and L3 are context free | |
Only L1 and L2 are context free | |
All are context free |
Discuss it
Question 6 |
All palindromes | |
All odd length palindromes. | |
Strings that begin and end with the same symbol | |
All even length palindromes |
Discuss it

Question 7 |
L1 = {Then L is| m, n >= 0 } L2 = {
| i, j, k >= 0 }
Not recursive | |
Regular | |
Context free but not regular | |
Recursively enumerable but not context free. |
Discuss it

Question 8 |
not recursive | |
is recursive and is a deterministic CFL. | |
is a regular language. | |
is not a deterministic CFL but a CFL. |
Discuss it
- For each occurrence of ‘0’ , we PUSH X in the stack.
- When ‘2’ appears, no stack operation is performed. But, state of the automata is changed.
- For each occurrence of ‘1’ , we POP X from the stack.
- If at the end Z0 is on the stack top then input string is accepted
- When ‘0’ appears in the input string , we replace it with X .Then, traverse to the rightmost corner and replace ‘1’ with Y.
- We go back to the leftmost ‘0’ and repeat the above process.
- While traversing rightwards from the beginning of the input string, if after X, ‘2’ appears and after ‘2’, Y appears then we reach the HALT state. Thus, the given language is recursive. Every recursive language is a CFL. Thus, option (B) is the answer. Please comment below if you find anything wrong in the above post.
Question 9 |
S --> aB S --> bA B --> b A --> a B --> bS A --> aS B --> aBB A --> bAAWhich of the following strings is generated by the grammar?
aaaabb | |
aabbbb | |
aabbab | |
abbbba |
Discuss it
S --> aB S --> bA B --> b A --> a B --> bS A --> aS B --> aBB A --> bAAWe can derive aabbab using below sequence
S -> aB [Using S --> aB] -> aaBB [Using B --> aBB] -> aabB [Using B --> b] -> aabbS [Using B --> bS] -> aabbaB [Using S --> aB] -> aabbab [Using B --> b]
Question 10 |
For the correct answer strings to above question, how many derivation trees are there?
1 | |
2 | |
3 | |
4 |
Discuss it
When it asks about the no of derivations tree, we should consider either left most derivation(LMD) or right most derivations(RMD), but not both. Here two left most derivations are possible for the correct string of the previous question "aabbab" from the given grammar. LMD-1 S -> aB [Using S --> aB] -> aaBB [Using B --> aBB] -> aabB [Using B --> b] -> aabbS [Using B --> bS] -> aabbaB [Using S --> aB] -> aabbab [Using B --> b] LMD-2 S -> aB [Using S --> aB] -> aaBB [Using B --> aBB] -> aabSB [Using B --> bS] -> aabbAB [Using S --> bA] -> aabbaB [Using A --> a] -> aabbab [Using B --> b] The Derivation tress are shown below :