Question

Language L1L_1 is defined by the grammar: S1→aS1b∣εS_1 \to a S_1 b \mid \varepsilon
Language L2L_2 is defined by the grammar: S2→abS2∣εS_2 \to a b S_2 \mid \varepsilon

Consider the following statements:
PP: L1L_1 is regular
QQ: L2L_2 is regular

Which one of the following is TRUE?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2016 answer key

Solution

Determine the formal language generated by each grammar and test for regularity.

  1. Analyze Grammar 1 (S1→aS1b∣εS_1 \to a S_1 b \mid \varepsilon):
  • Derivations:
    S1  ⟹  εS_1 \implies \varepsilon
    S1  ⟹  aS1b  ⟹  abS_1 \implies a S_1 b \implies a b
    S1  ⟹  aS1b  ⟹  a2S1b2  ⟹  a2b2S_1 \implies a S_1 b \implies a^2 S_1 b^2 \implies a^2 b^2
    In general: S1  ⟹  ∗anbnS_1 \implies^* a^n b^n for all n≥0n \ge 0.
  • Thus, L1={anbn∣n≥0}L_1 = \{a^n b^n \mid n \ge 0\}.
  • By the Pumping Lemma for regular languages, L1L_1 requires an unbounded stack to match the number of aa's and bb's. It cannot be accepted by any finite automaton. Hence, L1L_1 is not regular (statement PP is FALSE).
  1. Analyze Grammar 2 (S2→abS2∣εS_2 \to a b S_2 \mid \varepsilon):
  • Derivations:
    S2  ⟹  εS_2 \implies \varepsilon
    S2  ⟹  abS2  ⟹  abS_2 \implies ab S_2 \implies ab
    S2  ⟹  abS2  ⟹  (ab)2S2  ⟹  (ab)2S_2 \implies ab S_2 \implies (ab)^2 S_2 \implies (ab)^2
    In general: S2  ⟹  ∗(ab)nS_2 \implies^* (ab)^n for all n≥0n \ge 0.
  • Thus, L2={(ab)n∣n≥0}=(ab)∗L_2 = \{(ab)^n \mid n \ge 0\} = (ab)^*.
  • The regular expression (ab)∗(ab)^* describes L2L_2, which is accepted by a simple 2-state DFA. Hence, L2L_2 is regular (statement QQ is TRUE).

Therefore, PP is false and QQ is true, corresponding to option (C).

Final answer

C

Common trap

Assuming both grammars generate non-regular languages because both have recursive production rules.

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

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 2
Question
27 of 65, printed as CS Q.17
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.