Question
For a string , we define to be the reverse of . For example, if then .
Which of the following languages is/are context-free?
Official answer and solution
- Official answer
- B, C and D
- From
- Official GATE 2021 answer key
Solution
Examine the matching structure (nesting vs. cross-serial) for each language to see whether it can be recognized by a Pushdown Automaton (PDA).
A language is context-free if and only if it can be recognized by a pushdown automaton (PDA), which uses a single LIFO stack and can verify nested (last-in, first-out) dependencies.
Analyze each language:
- Option A: .
Here is matched with and is matched with , but they overlap in cross-serial fashion: starts first, then , then finishes before . This requires matching two independent pairs in an interleaved order, which cannot be handled by a single stack. This language is not context-free.
- Option B: .
This is the concatenation of two even-length palindrome languages: , where . Since is context-free and CFLs are closed under concatenation, this language is context-free. Option B is correct.
- Option C: .
This is the set of all odd-length or general palindromes with an arbitrary center . A PDA can push nondeterministically, read without touching the stack, and then pop and verify against . This language is context-free. Option C is correct.
- Option D: .
Notice that . Letting , this is simply , which is the standard language of even-length palindromes. Hence it is context-free. Option D is correct.
B, C, D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 51 of 65, printed as CS Q.41
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.