# GATE | GATE CS 2020 | Question 42

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 ?
(A) L1 is regular and L2 is context- free
(B) L1 context- free but not regular and L2 is context-free
(C) Neither L1 nor L2 is context- free
(D) L1 context- free but L2 is not context-free

Explanation:

`L1 = { wxyx ∣ w,x,y ∈ (0+1)+ } `

In L1 putting x as 0 and 1 we get a subset,

```L1 = w0y 0 + w1y1
L1 = (0 + 1)+0(0 + 1)+0 + (0 + 1)+1(0 + 1)+1 ```

So, L1 is regular language.

`L2 = { xy ∣ x,y ∈ (a+b)*, ∣x∣=∣y∣, x≠y } is CFL`

We observe that a string is in L2 if and only if it can be written as xy with |x| = |y| such that for some i, the ith character of x is different from the ith character of y. To obtain such a string, we start generating the corresponding ith characters, and fill up the remaining characters.

Based on the above idea, we define the CFG for C is as follows:

```S → AB | BA
A → XAX | 0
B → XBX | 1
X → 0 | 1 ```

Option (A) is correct.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.