Pushdown Automata

COS2601 - Theoretical Computer Science II · Pushdown Automata Theory

Pushdown Automata

Pushdown automata (PDA) are a type of computational model that extends finite automata (FA) by adding a stack as an auxiliary memory. This stack allows PDAs to recognize a broader class of languages, specifically context-free languages (CFLs). In this lesson, you will learn about the structure and functioning of pushdown automata, as well as their significance in the theory of computation.

Structure of Pushdown Automata

A pushdown automaton consists of the following components:

  • States: A finite set of states including a start state and one or more accept states.
  • Input Alphabet: A finite set of symbols that the automaton can read from the input tape.
  • Stack Alphabet: A finite set of symbols that can be pushed onto or popped from the stack.
  • Transition Function: A function that defines the state transitions based on the current state, the input symbol being read, and the top symbol of the stack.
  • Initial Stack Symbol: A special symbol that is pushed onto the stack initially.

Formally, a pushdown automaton can be defined as a 7-tuple:

 PDA = (Q, Σ, Γ, δ, q₀, Z₀, F) 

where:

  • Q is the finite set of states.
  • Σ is the input alphabet.
  • Γ is the stack alphabet.
  • δ is the transition function: δ: Q × Σ∪{ε} × Γ → P(Q × Γ∗).
  • q₀ is the initial state.
  • Z₀ is the initial stack symbol.
  • F is the set of accept states.

Operation of Pushdown Automata

The operation of a PDA is similar to that of a finite automaton, but with the addition of stack operations. The automaton reads input symbols one at a time and can perform the following actions:

  • Read an input symbol: The PDA reads the next symbol from the input tape.
  • Push a symbol onto the stack: The PDA can push a symbol onto the top of the stack.
  • Pop a symbol from the stack: The PDA can remove the top symbol from the stack.
  • Transition to a new state: Based on the current state, the input symbol read, and the top symbol of the stack, the PDA transitions to a new state.

The PDA can make transitions based on the current state, the input symbol being read, and the symbol on the top of the stack. If the PDA reaches an accept state after reading the entire input string, it accepts the input string.

Example of a Pushdown Automaton

Consider a PDA that recognizes the language L = { anbn | n ≥ 0 }. This language consists of strings with an equal number of a's followed by an equal number of b's. The PDA can be designed as follows:

  • States: Q = {q₀, q₁, q_accept, q_reject}
  • Input Alphabet: Σ = {a, b}
  • Stack Alphabet: Γ = {A, Z₀}
  • Initial State: q₀
  • Initial Stack Symbol: Z₀
  • Accept States: F = {q_accept}

The transition function δ can be defined as follows:

δ(q₀, a, Z₀) = (q₀, A Z₀)  // Push A onto the stack
δ(q₀, a, A) = (q₀, AA)    // Push another A onto the stack
δ(q₀, b, A) = (q₁, ε)     // Pop A for each b
δ(q₁, b, A) = (q₁, ε)     // Continue popping A for b's
δ(q₁, ε, Z₀) = (q_accept, Z₀) // Accept if stack is back to Z₀

The PDA starts in state q₀, pushes an A onto the stack for each a read, and transitions to state q₁ when it encounters a b. In state q₁, it pops an A for each b. If the stack is empty and the input is fully read, the PDA transitions to the accept state.

Acceptance Criteria

A pushdown automaton can accept input strings in two ways:

  • Final State Acceptance: The input is accepted if the PDA reaches one of its accept states after reading the entire input string.
  • Empty Stack Acceptance: The input is accepted if the stack is empty after reading the entire input string, regardless of the current state.

These two methods of acceptance can be combined, allowing for flexibility in the design of PDAs.

Example of Acceptance by Empty Stack

Consider the PDA that recognizes the language L = { an | n ≥ 0 }. This language consists of strings with only a's. The PDA can be defined as follows:

  • States: Q = {q₀, q_accept}
  • Input Alphabet: Σ = {a}
  • Stack Alphabet: Γ = {Z₀}
  • Initial State: q₀
  • Initial Stack Symbol: Z₀
  • Accept States: F = {q_accept}

The transition function δ can be defined as:

δ(q₀, a, Z₀) = (q₀, Z₀) // Stay in q₀ and keep Z₀ on the stack
δ(q₀, ε, Z₀) = (q_accept, Z₀) // Accept if stack is empty

In this case, the PDA accepts by empty stack, allowing any number of a's to be read before transitioning to the accept state.

Relation Between Context-Free Grammars and Pushdown Automata

Every context-free grammar (CFG) can be converted into an equivalent pushdown automaton. This is important because it establishes a correspondence between grammars and automata. The languages generated by CFGs are exactly the languages accepted by PDAs.

Conversely, for every pushdown automaton, there exists a context-free grammar that generates the same language. This relationship is fundamental in the theory of computation and helps to understand the properties of context-free languages.

Common Mistakes

Watch out: A common mistake is to confuse the stack operations with the input operations. Remember that stack operations (push and pop) are independent of the input being read.

Summary

  • Pushdown automata extend finite automata by adding a stack.
  • PDAs can accept context-free languages through state transitions and stack operations.
  • Acceptance can occur via final states or empty stacks.
  • There is a correspondence between context-free grammars and pushdown automata.

Check your understanding

  1. What are the key components of a pushdown automaton?
  2. How does the operation of a PDA differ from that of a finite automaton?
  3. Explain the two methods of acceptance for a pushdown automaton.
  4. How can you convert a context-free grammar into a pushdown automaton?