Skip to content
Official PYQ · 2015

GATE CS 2015 Set 2 Q51 — Regular and Context-free Languages

Explain with AI

Which of the following is/are regular languages?

L1:{wxwR∣w,x∈{a,b}∗ and ∣w∣,∣x∣>0},wR is the reverse of string wL_1: \left\{ wxw^R \mid w, x \in \{a, b\} ^* \text{ and } |w|, |x| > 0\right\}, w^R \text{ is the reverse of string } w

L2:{anbm∣m≠n and m,n≥0}L_2: \left\{ a^nb^m \mid m \neq n \text{ and } m, n \geq 0 \right\}

L3:{apbqcr∣p,q,r≥0}L_3: \left\{ a^pb^qc^r \mid p, q, r \geq 0 \right\}

Choose one option
View worked solution

Answer: A

To determine which of the languages are regular, we analyze each one individually:

  • Language L1L_1: We are given L1={wxwR∣w,x∈{a,b}∗ and ∣w∣,∣x∣>0}L_1 = \{ wxw^R \mid w, x \in \{a, b\}^* \text{ and } |w|, |x| > 0 \}.
    Let the first symbol of ww be c∈{a,b}c \in \{a, b\}, so w=cuw = c u for some string uu. Then wR=uRcw^R = u^R c.
    Substituting this, any string in L1L_1 can be written as: wxwR=(cu)x(uRc)=c(uxuR)cwxw^R = (cu) x (u^R c) = c (uxu^R) c Since ∣x∣>0|x| > 0, the middle portion x′=uxuRx' = uxu^R also has length ∣x′∣≥1|x'| \ge 1.
    Thus, L1L_1 is simply the set of all strings of length ≥3\ge 3 that start and end with the same symbol. This can be defined by the regular expression: a(a+b)+a+b(a+b)+ba(a+b)^+a + b(a+b)^+b Since we can write a regular expression for L1L_1, L1L_1 is regular.
  • Language L2L_2: L2={anbm∣m≠n and m,n≥0}L_2 = \{ a^nb^m \mid m \neq n \text{ and } m, n \ge 0 \}.
    This language requires comparing the count of aa's and bb's to ensure they are unequal. Since a finite automaton has finite memory, it cannot keep track of arbitrary counts. Thus, L2L_2 is not regular (it is a deterministic context-free language).
  • Language L3L_3: L3={apbqcr∣p,q,r≥0}L_3 = \{ a^pb^qc^r \mid p, q, r \ge 0 \}.
    This language consists of any number of aa's followed by any number of bb's followed by any number of cc's. It can be represented by the regular expression: a∗b∗c∗a^*b^*c^* Thus, L3L_3 is regular.

Therefore, only L1L_1 and L3L_3 are regular languages.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Regular and Context-free Languages questions