GateAI
Context-Free Grammars and PDAs

GATE CSE 2016 Set 1 · Q43

MCQ2 marksMedium

Time

Consider the transition diagram of a PDA given below with input alphabet Σ={a,b}\Sigma = \{a,b\} and stack alphabet Γ={X,Z}\Gamma = \{X, Z\}. ZZ is the initial stack symbol. Let LL denote the language accepted by the PDA. Which one of the following is TRUE?

GATE CSE 2016 Set 1 Q43 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) L = {an n ≥ 0} ∪ {an bn n ≥ 0} and is deterministic context-free

Context-Free Grammars and PDAs

Let us analyze the given PDA:

  1. Initial State (Start and Final State):

    • The start state is also an accepting (final) state.

    • On reading nothing (ε\varepsilon), it accepts the empty string ε\varepsilon.

    • On input aa, it pushes XX onto the stack for every aa read (a,Z/XZa, Z / XZ and a,X/XXa, X / XX). Since this state is an accepting state, all strings consisting solely of aa's (ana^n for n≥0n \ge 0) are accepted by staying in the first state.

  2. Transition to Second State:

    • On reading bb while the top of the stack is XX, it pops an XX (b,X/εb, X / \varepsilon) and moves to the second state.

    • In the second state, it continues to pop an XX for each subsequent bb read (b,X/εb, X / \varepsilon).

  3. Transition to Third State (Final State):

    • From the second state, on ε\varepsilon input when the stack top is ZZ, it transitions to the third (accepting) state with stack unchanged (ε,Z/Z\varepsilon, Z / Z).

    • This path accepts strings where the number of bb's matches the number of aa's pushed, i.e., anbna^n b^n for n≥1n \ge 1.

    • Including n=0n = 0 (which is ε\varepsilon), all strings of the form anbna^n b^n for n≥0n \ge 0 are accepted.

Combining both accepting conditions:

L={an∣n≥0}∪{anbn∣n≥0}L = \{a^n \mid n \ge 0\} \cup \{a^n b^n \mid n \ge 0\}
  1. Determinism:

    • For any state, input symbol, and stack top, there is at most one valid move and no conflicting ε\varepsilon-transitions.

    • Specifically, from the first state, the transitions on aa and bb are mutually exclusive, and there is no ε\varepsilon-move from the start state.

    • Therefore, the PDA is a Deterministic Pushdown Automaton (DPDA), which means LL is a Deterministic Context-Free Language (DCFL).

Thus, option (D) is correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Context-Free Grammars and PDAs previous year question is Q43 of the GATE CSE 2016 Set 1 paper. Find more GATE CSE PYQs on Context-Free Grammars and PDAs in Theory of Computation, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Context-Free Grammars and PDAs PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Context-Free Grammars and PDAs in GATE CSE

Context-Free Grammars and PDAs has 26 GATE CSE PYQs across 17 papers from 2011 to 2026. 9 of them are 2-mark MCQs like this one, and GATE CSE 2016 Set 1 has 3.

How GATE tests Context-Free Grammars and PDAs

More from GATE CSE 2016 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 1 · Q43 · MCQ

Consider the transition diagram of a PDA given below with input alphabet = {a,b} and stack alphabet = {X, Z}. Z is the initial stack symbol. Let L denote the language accepted by the PDA. Which one of the following is TRUE?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.