UNIHIVE

Study Hub UNIPORT CSC 396

CSC 396 · Automata theory, Computability and Formal Languages

Pushdown automata

Adding a stack to a finite automaton, the formal definition, a PDA for aⁿbⁿ, and the equivalence with context-free grammars.

Our notes

2 min read

The idea

A pushdown automaton (PDA) is a finite automaton with a stack of unlimited size. It can push and pop symbols as it reads input, which gives it memory enough to match brackets or count a's against b's.

Formal definition

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

  • Q states, Σ input alphabet, Γ stack alphabet,
  • δ: Q × (Σ ∪ {ε}) × Γ → finite sets of (state, string to push),
  • q₀ start state, Z₀ initial stack symbol, F accepting states.

A transition is written a, X / γ: read a with X on top, replace X by γ.
Acceptance by final state or by empty stack (the two give the same class of languages).

Example: {aⁿbⁿ : n ≥ 1}

  • q0: on a, push A (a, Z₀ / AZ₀ and a, A / AA).
  • On the first b with A on top, pop and go to q1 (b, A / ε).
  • q1: on b with A on top, pop (b, A / ε).
  • q1: on ε with Z₀ on top, go to q2 (accept).

Trace aabb: push A, push A (stack AAZ₀); b pops (AZ₀); b pops (Z₀); ε → q2: accepted. Trace aab: ends with A still on the stack: rejected. Trace abb: the second b finds Z₀, no move: rejected.

Example: even-length palindromes wwᴿ

Push symbols while reading w; guess (nondeterministically) the middle; then pop and compare with the rest. This needs nondeterminism: no deterministic PDA can find the middle without a marker.

PDAs and grammars

A language is context-free if and only if some PDA accepts it. A grammar can be turned into a PDA that simulates leftmost derivations on its stack; parsers are deterministic versions of this.

Deterministic PDAs

DPDAs accept the deterministic context-free languages, a smaller class that includes the syntax of most programming languages (which is why LR parsers work in linear time).

Limits: the pumping lemma for CFLs

Context-free languages have their own pumping lemma (w = uvxyz, pumping v and y together). It shows {aⁿbⁿcⁿ} is not context-free: one stack cannot match three counts.

Closure

CFLs are closed under union, concatenation and star, but not under intersection or complement.

Exams usually ask

  • Define a PDA and explain acceptance by final state and by empty stack.
  • Design a PDA for aⁿbⁿ or balanced brackets and trace strings.
  • State the equivalence of PDAs and CFGs; give a non-context-free language.

Common mistake

Thinking a PDA can read its stack freely. It sees only the top symbol; anything below is reached only by popping.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 396 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.