Skip to content
Official PYQ · 2009

GATE CS 2009 Q40 — Regular and Context-free Languages

Explain with AI

Let L=L1∩L2L = L_1 \cap L_2, where L1L_1 and L2L_2 are languages as defined below:

L1={ambmcanbn∣m,n≥0}L_1= \left \{ a^m b^mca^nb^n \mid m,n \geq 0 \right \}

L2={aibjck∣i,j,k≥0}L_2=\left \{ a^i b^j c^k \mid i,j,k \geq 0 \right \}

Then LL is

Choose one option
View worked solution

Answer: C

To find the nature of the language L=L1∩L2L = L_1 \cap L_2, let us analyze the two given languages:

  • L1={ambmcanbn∣m,n≥0}L_1 = \left\{ a^m b^m c a^n b^n \mid m, n \geq 0 \right\}
  • L2={aibjck∣i,j,k≥0}L_2 = \left\{ a^i b^j c^k \mid i, j, k \geq 0 \right\}

Note that L2L_2 is a regular language represented by the regular expression a∗b∗c∗\mathbf{a^* b^* c^*}. This means any string in L2L_2 must have all aa's first, followed by all bb's, and then all cc's.

For a string w∈L1w \in L_1 to also belong to L2L_2, it must satisfy the character ordering of a∗b∗c∗a^* b^* c^*:

  • The general form of a string in L1L_1 is w=ambmcanbnw = a^m b^m c a^n b^n.
  • If n>0n > 0, the string contains aa's and bb's after the character cc, which violates the pattern a∗b∗c∗a^* b^* c^*.
  • Therefore, we must have n=0n = 0 for the string to be in L2L_2.

Substituting n=0n = 0 into the expression for L1L_1, we get:

L=L1∩L2={ambmc∣m≥0}L = L_1 \cap L_2 = \left\{ a^m b^m c \mid m \geq 0 \right\}

Now, let us analyze the language LL:

  1. Not Regular: It requires matching the number of aa's and bb's (mm of each), which requires infinite memory (a stack) and cannot be recognized by a Finite Automaton.
  2. Context-Free: It can be generated by the following Context-Free Grammar (CFG):
    S→XcS \to X c
    X→aXb∣ϵX \to a X b \mid \epsilon
    It can also be easily accepted by a Pushdown Automaton (PDA) by pushing aa's onto the stack and popping them for each bb, then reading cc.

Thus, LL is context-free but not regular.

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

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