Skip to content
Official PYQ · 2021

GATE CS 2021 Set 1 Q51 — Context-free Grammars and Push-down Automata

Explain with AI

In a  pushdown automaton P=(Q,Σ,Γ,δ,q0,F)P=(Q, \Sigma, \Gamma, \delta, q_0, F), a transition of the form,

where p,q∈Qp,q \in Q, a∈Σ∪{ϵ}a \in \Sigma \cup \{ \epsilon \}, and X,Y∈Γ∪{ϵ}X,Y \in \Gamma \cup \{ \epsilon \}, represents (q,Y)∈δ(p,a,X).(q,Y) \in \delta(p,a,X).Consider the following pushdown automaton over the input alphabet Σ={a,b}\Sigma = \{a,b\} and stack alphabet Γ={#,A}\Gamma = \{ \#, A\}.

The number of strings of length 100100 accepted by the above pushdown automaton is ___________

View worked solution

Answer: 50 : 50

By analyzing the transitions of the given pushdown automaton (PDA), we can determine the language it accepts:

  1. State q0q_0 (Push Phase): For every symbol aa read, an AA is pushed onto the stack. Thus, reading ana^n (where n≥1n \ge 1) results in nn AA's on the stack above the initial symbol #\#.
  2. State q1q_1 (Pop Phase): The transition from q0q_0 to q1q_1 occurs on the first bb, popping one AA. Subsequent bb's are read in q1q_1, each popping one AA. If mm bb's are read in total (m≥1m \ge 1), then mm AA's are popped.
  3. State q2q_2 (Acceptance Phase): The PDA transitions to the final state q2q_2 on ϵ\epsilon input if:
    • The stack has only #\# left (i.e., n=mn = m), via transition ϵ,#/#\epsilon, \# / \#.
    • The stack still has AA's left (i.e., n>mn > m), via transition ϵ,A/A\epsilon, A / A.

Thus, the language accepted by the PDA is:

L={anbm∣n≥m≥1}L = \{ a^n b^m \mid n \ge m \ge 1 \}

We need to find the number of strings in LL of length 100100:

n+m=100subject ton≥m≥1n + m = 100 \quad \text{subject to} \quad n \ge m \ge 1

Substituting n=100−mn = 100 - m into the inequality:

100−m≥m  ⟹  2m≤100  ⟹  m≤50100 - m \ge m \implies 2m \le 100 \implies m \le 50

Since m≥1m \ge 1, the possible integer values for mm are:

m∈{1,2,3,…,50}m \in \{1, 2, 3, \dots, 50\}

Each value of mm uniquely determines n=100−mn = 100 - m. Therefore, there are exactly 50 such strings.

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

Published
Report a correction
Keep exploringMore Context-free Grammars and Push-down Automata questions