GateAI
Regular and Context-Free Languages

GATE CSE 2020 · Q32

MCQ2 marksHard

Time

Consider the following languages. L1={wxyx∣w,x,y∈(0+1)+}L_1 = \{wxyx \mid w, x, y \in (0 + 1)^+\} L2={xy∣x,y∈(a+b)∗,∣x∣=∣y∣,x≠y}L_2 = \{xy \mid x, y \in (a + b)^*, |x| = |y|, x \neq y\} Which one of the following is TRUE?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) L1 is regular and L2 is context-free.

Regular and Context-Free Languages

### Analysis of L1L_1: L1={wxyx∣w,x,y∈(0+1)+}L_1 = \{wxyx \mid w, x, y \in (0 + 1)^+\}

Notice that if xx is chosen to be a single character c∈{0,1}c \in \{0, 1\}, the string has the form wcycw c y c where w,y∈(0+1)+w, y \in (0+1)^+. Any string in L1L_1 has xx ending in either 00 or 11. Let x=x′cx = x^{\prime}c with c∈{0,1}c \in \{0, 1\}, then:

wxyx=w(x′c)y(x′c)=(wx′)c(yx′)cwxyx = w(x^{\prime}c)y(x^{\prime}c) = (wx^{\prime})c(yx^{\prime})c

Since w,y∈(0+1)+w, y \in (0+1)^+, wx′∈(0+1)+wx^{\prime} \in (0+1)^+ and yx′∈(0+1)+yx^{\prime} \in (0+1)^+. Thus, any string in L1L_1 matches the regular expression:

(0+1)+0(0+1)+0+(0+1)+1(0+1)+1(0+1)^+ 0 (0+1)^+ 0 + (0+1)^+ 1 (0+1)^+ 1

Conversely, any string matching this regular expression belongs to L1L_1 by setting x=cx = c. Because L1L_1 can be expressed by a regular expression, L1L_1 is regular.

### Analysis of L2L_2: L2={xy∣x,y∈(a+b)∗,∣x∣=∣y∣,x≠y}L_2 = \{xy \mid x, y \in (a + b)^*, |x| = |y|, x \neq y\}

L2L_2 consists of all even-length strings where the first half is not equal to the second half. x≠yx \neq y implies there is some position ii (1≤i≤∣x∣1 \le i \le |x|) such that the ii-th character of xx differs from the ii-th character of yy.

This can be generated by a Context-Free Grammar (CFG):

  • S→AB∣BAS \to AB \mid BA

  • A→CAC∣aA \to CAC \mid a

  • B→CBC∣bB \to CBC \mid b

  • C→a∣bC \to a \mid b

Here, AA generates strings of odd length with 'a' in the middle, and BB generates strings of odd length with 'b' in the middle. The concatenation ABAB or BABA generates strings of even length 2n2n where the ii-th character from the start and the (n+i)(n+i)-th character from the start differ. Since a CFG exists, L2L_2 is context-free (non-deterministic CFL, not regular).

Therefore, L1L_1 is regular and L2L_2 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.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

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 in GATE CSE

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 Languages

More from GATE CSE 2020

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2020 · Q32 · MCQ

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.