IAE Academy

GATE 2023 CS Q.40: solution and answer

GATE 2023 · CSQ.40 · 2 marks · MCQ

Consider the pushdown automaton (PDA) below, which runs on the input alphabet , has stack alphabet , and has three states , with being the start state. A transition from state to state , labelled , where is an input symbol or , is a stack symbol, and is a string of stack symbols, represents the fact that in state , the PDA can read from the input, with on the top of its stack, pop from the stack, push in the string on the stack, and go to state . In the initial configuration, the stack has only the symbol in it. The PDA accepts by empty stack. Which one of the following options correctly describes the language accepted by ?

GATE 2023 CS question 40: State diagram with three states s, p, q.Tap to open full size
Figure from the GATE 2023 CS paper. It is part of the question.
Figure description

State diagram with three states s, p, q. s is the start state (arrow entering from the left). Self-loop on s with two labels: a/⊥/A⊥ and a/A/AA. Self-loop on p with label b/A/ε. Self-loop on q with two labels: ε/A/ε and ε/⊥/ε. Edge s to p labelled b/A/ε. Edge s to q labelled ε/A/ε. Edge p to q labelled ε/A/ε. No state is marked accepting (acceptance is by empty stack).

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution

ANSWER

The language accepted by is , which is option A.

Official answer: ASource: Official answer key, GATE 2023 CS (IIT Kanpur)

  1. In with on top, the only move is , so the first symbol must be . The empty string and any string starting with are rejected, so . This rules out B, C and D, each of which accepts .

  2. Reading a's in leaves the stack , because each adds one . No transition outside reads , so every comes before every .

  3. Path 1: by pops one and reads no input. State reads no input, so the remaining input must be empty, which gives . In , the loops and pop the remaining 's and then . So with is accepted.

  4. Path 2: by reads the first and pops one . In , each further pops one (loop ). After b's, A's have been popped and remain.

  5. To leave we need the move (), which pops one more . This needs , that is . Then pops the remaining A's and , so the stack becomes empty.

  6. If , the A's run out before can fire. is then on top, has no move on , and the stack cannot be emptied, so the string is rejected.

  7. Combining the two paths, the language is , which is option A.

KEY IDEA

Acceptance is by empty stack, and the only way to empty it is to get to . Every pops an , and the move into needs one more plus input already used up. So at least one must be left after the b's, which gives .

WATCH OUT FOR

Choosing B () by thinking each simply cancels an . The exit from to pops one extra , so strands on top. Also forgetting that is rejected, since the first move needs an .

From the GATE 2023 CS paper. Every question of this paper · Download the full paper · All 9 CFG & PDA questions, with notes

More CFG & PDA questions