Skip to content
Official PYQ · 2016

GATE CS 2016 Set 2 Q17 — Regular and Context-free Languages

Explain with AI

Language L1L_{1} is defined by the grammar: S1→aS1b∣εS_{1} \rightarrow a S_{1} b \mid \varepsilon

Language L2L_{2} is defined by the grammar: S2→abS2∣εS_{2} \rightarrow a b S_{2} \mid \varepsilon

Consider the following statements:

  • P: L1L_{1} is regular
  • Q: L2L_{2} is regular

Which one of the following is TRUE?

Choose one option
View worked solution

Answer: C

To determine the correctness of statements P and Q, let us analyze the languages generated by the two grammars.

1. Analysis of Language L1L_1

The grammar for L1L_1 is given by:

S1→aS1b∣εS_1 \rightarrow a S_1 b \mid \varepsilon

By repeatedly applying the production rules, we generate strings with nested, matching pairs of aa's and bb's:

  • S1⇒εS_1 \Rightarrow \varepsilon
  • S1⇒aS1b⇒abS_1 \Rightarrow a S_1 b \Rightarrow ab
  • S1⇒aS1b⇒aaS1bb⇒aabbS_1 \Rightarrow a S_1 b \Rightarrow aa S_1 bb \Rightarrow aabb

In general, the language generated is:

L1={anbn∣n≥0}L_1 = \{a^n b^n \mid n \ge 0\}

Since recognizing L1L_1 requires keeping track of the exact count of aa's to match with the same number of bb's, it requires infinite memory. Thus, L1L_1 is a non-regular context-free language. Therefore, statement P is false.

2. Analysis of Language L2L_2

The grammar for L2L_2 is given by:

S2→abS2∣εS_2 \rightarrow a b S_2 \mid \varepsilon

This is a right-linear grammar where the non-terminal S2S_2 always appears at the rightmost end of the production. Let's trace the derivations:

  • S2⇒εS_2 \Rightarrow \varepsilon
  • S2⇒abS2⇒abS_2 \Rightarrow ab S_2 \Rightarrow ab
  • S2⇒abS2⇒ababS2⇒ababS_2 \Rightarrow ab S_2 \Rightarrow abab S_2 \Rightarrow abab

In general, the language generated consists of any number of repetitions of the string "abab":

L2={(ab)n∣n≥0}=(ab)∗L_2 = \{(ab)^n \mid n \ge 0\} = (ab)^*

Since L2L_2 can be defined by the regular expression (ab)∗(ab)^*, it is a regular language. Therefore, statement Q is true.

Conclusion

Since P is false and Q is true, the correct option is C.

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

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