Skip to content
Official PYQ · 2020

GATE CS 2020 Q10 — Regular and Context-free Languages

Explain with AI

Consider the language L={an∣n≥0}∪{anbn∣n≥0}L = \{a^{n}\mid n \geq 0\} \cup \{a^{n}b^{n}\mid n \geq 0\} and the following statements.

  1. LL is deterministic context-free.
  2. LL is context-free but not deterministic context-free.
  3. LL is not LL(k)LL(k) for any kk.

 Which of the above statements is/are TRUE?

Choose one option
View worked solution

Answer: C

To determine which statements are true, let us analyze the language L={an∣n≥0}∪{anbn∣n≥0}L = \{a^n \mid n \geq 0\} \cup \{a^n b^n \mid n \geq 0\}.

Statement I is TRUE (and Statement II is FALSE):

We can construct a Deterministic Pushdown Automaton (DPDA) that accepts LL by final state:

  • Start state q0q_0 is accepting (to accept ϵ\epsilon).
  • For each aa read, push aa onto the stack and transition to state q1q_1 (which is an accepting state). This ensures any string of the form ana^n is accepted.
  • If a bb is encountered while in q1q_1, transition to state q2q_2 (non-accepting) and pop aa from the stack.
  • For subsequent bb's, stay in q2q_2 and pop aa.
  • If the stack becomes empty (only Z0Z_0 remains) after reading all bb's, transition to state q3q_3 (accepting).

Since all transitions are deterministic, LL is a Deterministic Context-Free Language (DCFL).

Statement III is TRUE:

For any fixed lookahead kk, if the parser sees aka^k, it cannot determine whether the string is of the form ana^n (with no bb's) or anbna^n b^n (where bb's appear after n≥kn \ge k symbols). Since this ambiguity cannot be resolved with a finite lookahead of kk symbols, LL is not LL(k)LL(k) for any kk.

Thus, statements I and III only are TRUE.

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

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