Consider the following languages. L1 = {wxyx w, x, y ∈ (0 + 1)+} L2 = {xy x, y ∈ (a + b)*, |x| = |y|, x ≠ y} Which one of the following is TRUE?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2020 · Q32
Time
Select one answerSingle correct
Solution
Official answer: A) L1 is regular and L2 is context-free.
Regular and Context-Free Languages### Analysis of :
Notice that if is chosen to be a single character , the string has the form where . Any string in has ending in either or . Let with , then:
Since , and . Thus, any string in matches the regular expression:
Conversely, any string matching this regular expression belongs to by setting . Because can be expressed by a regular expression, is regular.
### Analysis of :
consists of all even-length strings where the first half is not equal to the second half. implies there is some position () such that the -th character of differs from the -th character of .
This can be generated by a Context-Free Grammar (CFG):
Here, generates strings of odd length with 'a' in the middle, and generates strings of odd length with 'b' in the middle. The concatenation or generates strings of even length where the -th character from the start and the -th character from the start differ. Since a CFG exists, is context-free (non-deterministic CFL, not regular).
Therefore, is regular and is context-free, making A the correct option.
*(Note: Option D was printed on the succeeding page and is omitted as per partial extraction rules.)*
Try the question first, then check your work.
Examiner trap
For , consider setting to a single character and rewriting the condition as a regular expression. For , consider two halves differing at least at one corresponding position and construct a CFG.
This Regular and Context-Free Languages previous year question is Q32 of the GATE CSE 2020 paper. Find more GATE CSE PYQs on Regular and Context-Free Languages in Theory of Computation, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Regular and Context-Free Languages PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Regular and Context-Free Languages has 21 GATE CSE PYQs across 13 papers from 2011 to 2026. 9 of them are 2-mark MCQs like this one, and GATE CSE 2020 has 2.
How GATE tests Regular and Context-Free LanguagesIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.