Consider the following languages:
Note that is the reversal of the string . Which of the following is/are TRUE?
- (A)
and are regular.
- (B)
and are context-free.
- (C)
is regular and is context-free.
- (D)
and are context-free but not regular.
Consider the following languages:
Note that is the reversal of the string . Which of the following is/are TRUE?
and are regular.
and are context-free.
is regular and is context-free.
and are context-free but not regular.
ANSWER
A, B and C are true; D is false.
Official answer: A, B, CSource: Official answer key, GATE 2022 CS (IIT Kharagpur)
: here is arbitrary (it may be empty). Taking gives every string . A larger gives nothing new, because already has the form . Hence , the strings of length at least 2 that start and end with . If is also allowed, . Either way is regular.
: take , say . Then with non-empty, which gives every string of length at least 3 that starts and ends with the same symbol.
A longer gives nothing new. The string starts with the first symbol of and ends with that same symbol. Its length is at least 3 because . Writing for the first symbol, the string is with non-empty. So , which is regular.
So both and are regular. The reversal in looks as if it needs a stack. But the free middle part means a finite automaton only has to compare the first and last symbols.
Every regular language is context-free, so and are both context-free.
Check the options. (A) true. (B) true, since regular implies context-free. (C) true, since is regular and , being regular, is context-free. (D) false, because neither language is non-regular.
KEY IDEA
The free middle part ( in , in ) absorbs everything except the first and last symbols. So both languages reduce to a check on the end symbols, and both are regular. Every regular language is context-free.
WATCH OUT FOR
Reading as a palindrome-like language that needs a stack and so is non-regular. The non-empty free between and means only the first and last symbols matter, so this is not the language .
From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 8 Context-free languages questions, with notes