Question

Consider the following languages:

I. {ambncpdq∣m+p=n+q, where m,n,p,q≥0}\{a^m b^n c^p d^q \mid m + p = n + q, \text{ where } m, n, p, q \ge 0\}
II. {ambncpdq∣m=n and p=q, where m,n,p,q≥0}\{a^m b^n c^p d^q \mid m = n \text{ and } p = q, \text{ where } m, n, p, q \ge 0\}
III. {ambncpdq∣m=n=p and p≠q, where m,n,p,q≥0}\{a^m b^n c^p d^q \mid m = n = p \text{ and } p \neq q, \text{ where } m, n, p, q \ge 0\}
IV. {ambncpdq∣mn=p+q, where m,n,p,q≥0}\{a^m b^n c^p d^q \mid mn = p + q, \text{ where } m, n, p, q \ge 0\}

Which of the languages above are context-free?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2018 answer key

Solution

Test each language using pushdown automaton mechanics and closure properties.

Evaluate each language:

  • I. {ambncpdq∣m+p=n+q}\{a^m b^n c^p d^q \mid m + p = n + q\}: Rewrite as m−n=q−pm - n = q - p. A PDA can push aa's onto the stack, pop an aa for each bb (or push bb's if n>mn > m), then push cc's (or cancel bb's), and finally match with dd's. Since a single stack suffices to verify the balance condition across the entire string, language I is context-free.
  • II. {ambncpdq∣m=n and p=q}\{a^m b^n c^p d^q \mid m = n \text{ and } p = q\}: This language is the concatenation of two independent CFLs: L1={ambm∣m≥0}L_1 = \{a^m b^m \mid m \ge 0\} and L2={cpdp∣p≥0}L_2 = \{c^p d^p \mid p \ge 0\}. Since CFLs are closed under concatenation, language II is context-free.
  • III. {ambncpdq∣m=n=p and p≠q}\{a^m b^n c^p d^q \mid m = n = p \text{ and } p \neq q\}: Requiring three independent counts to be equal (m=n=pm = n = p) cannot be checked by a pushdown automaton (analogous to the classic non-CFL {anbncn}\{a^n b^n c^n\}). Language III is not context-free.
  • IV. {ambncpdq∣mn=p+q}\{a^m b^n c^p d^q \mid mn = p + q\}: Involves multiplication of counts, which cannot be recognized by any pushdown automaton. Language IV is not context-free.

Hence, only I and II are context-free, matching option B.

Final answer

B

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

Source

Paper
GATE 2018 Computer Science and Information Technology (CS)
Question
45 of 65, printed as CS Q.35
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.