Question

Consider the following languages.

L1={wxyx∣w,x,y∈(0+1)+}L2={xy∣x,y∈(a+b)∗,∣x∣=∣y∣,x≠y}\begin{aligned} L_1 &= \{w x y x \mid w, x, y \in (0 + 1)^+\} \\ L_2 &= \{x y \mid x, y \in (a + b)^*, |x| = |y|, x \ne y\} \end{aligned}

Which one of the following is TRUE?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2020 answer key

Solution

Demonstrate that L1 can be simplified to a regular expression and L2 is generated by a context-free grammar.

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

  • Notice that xx is non-empty (∣x∣≥1|x| \ge 1). In particular, xx can be chosen to be a single symbol: x=0x = 0 or x=1x = 1.
  • If x=0x = 0: the pattern becomes w0y0w 0 y 0, where w,y∈(0+1)+w, y \in (0+1)^+.
  • If x=1x = 1: the pattern becomes w1y1w 1 y 1, where w,y∈(0+1)+w, y \in (0+1)^+.
  • Any string that matches wxyxw x y x with ∣x∣>1|x| > 1 also matches either w′0y′0w' 0 y' 0 or w′1y′1w' 1 y' 1 by taking the first and last bits of xx.
  • Thus, L1=(0+1)+0(0+1)+0  ∪  (0+1)+1(0+1)+1L_1 = (0+1)^+ 0 (0+1)^+ 0 \;\cup\; (0+1)^+ 1 (0+1)^+ 1.
  • Since L1L_1 can be expressed by a regular expression, L1L_1 is regular.

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

  • L2L_2 contains even-length strings where the first half xx differs from the second half yy in at least one position ii.
  • That is, for some kk, the string has the form uav⋅u′bv′u a v \cdot u' b v' or ubv⋅u′av′u b v \cdot u' a v' with ∣u∣=∣u′∣|u| = |u'| and ∣v∣=∣v′∣|v| = |v'|.
  • This language can be generated by the following context-free grammar:
    S→AB∣BAS \to A B \mid B A
    A→CAC∣aA \to C A C \mid a
    B→CBC∣bB \to C B C \mid b
    C→a∣bC \to a \mid b
  • Here AA generates strings where the middle character is aa, and BB generates strings where the middle character is bb. ABA B produces an even-length string whose first half has aa at the same relative position where the second half has bb.
  • Thus, L2L_2 is context-free (though non-deterministic).

Therefore, L1L_1 is regular and L2L_2 is context-free.

Final answer

A

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2020 Computer Science and Information Technology (CS)
Question
42 of 65, printed as CS Q.32
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.