Pushdown Automata (PDA) state control 00011111000 input a a b a stack Pushdown Automata (PDA) If the input symbol is a and the top stack symbol is x then q1 to q2, pop x, push y, advance read head q1 a, x → y q2 If a = ℇ do not advance read head If x = ℇ do not read from stack If y = ℇ do not write to stack When does a PDA accept a string? input: w1w2…wn q0 w1 r1 w2 r2 w3 … accept if any branch accepts wn qf Pushdown Automata (PDA) (Q, Σ, Γ, δ, q0, F) δ: Q × Σℇ × Γℇ → 𝒫(Q × Γℇ) q1 a, x → y a, x → q2 z q3 Theorems Not every nondeterministic PDA has an equivalent deterministic PDA A language is context-free iff some PDA recognizes it CFL vs. Regular Languages CFL vs. Regular Languages PDA to NFA CFL vs. Regular Languages NFA to PDA q1 a q2 CFL vs. Regular Languages NFA to PDA q1 a, ℇ → ℇ q2 PDA Design Examples PDA Design n n {0 1 | n ≥ 0} input: 000111 n n {0 1 | n ≥ 0} stack input: 000111 q2 n n {0 1 | n ≥ 0} stack 0, ℇ → 0 input: 000111 q2 n n {0 1 | n ≥ 0} stack 0 0, ℇ → 0 input: 000111 q2 n n {0 1 | 0 0 n ≥ 0} stack 0, ℇ → 0 input: 000111 q2 n n {0 1 | n ≥ 0} 0 0 0 stack 0, ℇ → 0 input: 000111 q2 n n {0 1 | n ≥ 0} 1, 0 → ℇ q3 0 0 0 stack 0, ℇ → 0 1, 0 → ℇ input: 000111 q2 n n {0 1 | n ≥ 0} 1, 0 → ℇ q3 0 0 stack 0, ℇ → 0 1, 0 → ℇ input: 000111 q2 n n {0 1 | n ≥ 0} 1, 0 → ℇ q3 stack 0 0, ℇ → 0 1, 0 → ℇ input: 000111 q2 n n {0 1 | n ≥ 0} 1, 0 → ℇ q3 stack 0, ℇ → 0 1, 0 → ℇ input: 000111_ q2 n n {0 1 | n ≥ 0} 1, 0 → ℇ q3 stack 0, ℇ → 0 1, 0 → ℇ Does this work? n n {0 1 | n ≥ 0} q2 0, ℇ → 0 1, 0 → ℇ q3 1, 0 → ℇ n n {0 1 | q1 n ≥ 0} ℇ, ℇ → $ q2 0, ℇ → 0 1, 0 → ℇ q4 ℇ, $ → ℇ q3 1, 0 → ℇ PDA Design R * {ww | w ∈ {0, 1} } R {ww | q1 w ∈ {0, ℇ, ℇ → $ * 1} } q2 0, ℇ → 0 1, ℇ → 1 ℇ, ℇ → ℇ q4 ℇ, $ → ℇ q3 0, 0 → ℇ 1, 1 → ℇ PDA Design i j k {a b c | i, j, k ≥ 0 and i = j or j = k} i j k {a b c | q1 i, j, k ≥ 0 and i = j} ℇ, ℇ → $ q2 a, ℇ → a ℇ, ℇ → ℇ q4 c, ℇ → ℇ ℇ, $ → ℇ q3 b, a → ℇ {aibjck | i, j, k ≥ 0 and j = k} r1 ℇ, ℇ → $ r2 a, ℇ → ℇ ℇ, ℇ → ℇ r3 b, ℇ → b ℇ, ℇ → ℇ r5 ℇ, $ → ℇ r4 c, b → ℇ {aibjck | i, j, k ≥ 0 and i=j or j = k} ℇ, ℇ → $ a, ℇ → a ℇ, ℇ → $ q2 r2 a, ℇ → ℇ ℇ, ℇ → ℇ q1 r1 r3 b, ℇ → b ℇ, ℇ → ℇ ℇ, ℇ → ℇ q3 b, a → ℇ r4 c, b → ℇ ℇ, $ → ℇ ℇ, $ → ℇ q4 c, ℇ → ℇ r5 {aibjck | i, j, k ≥ 0 and i=j or j = k} a, ℇ → ℇ q2 ℇ, ℇ → $ a, ℇ → a ℇ, ℇ → $ q2 ℇ, ℇ → ℇ q1 b, ℇ → b q3 ℇ, ℇ → ℇ ℇ, ℇ → ℇ q3 b, a → ℇ q3 c, b → ℇ ℇ, $ → ℇ ℇ, $ → ℇ q4 c, ℇ → ℇ q4 Pumping Lemma: Regular Languages If A is a regular language, then there is a pumping length p st if s ∈ A with |s| ≥ p then we can write s = xyz so that • ∀i ≥ 0 xyiz ∈ A • |y| > 0 • |xy| ≤ p n n To prove {0 1 | n ≥ 0} is not regular using the Pumping Lemma 1. 2. 3. 4. Suppose {0n1n | n ≥ 0} is regular Call its pumping length p Find string s ∈ A with |s| ≥ p. Let s = 0p1p The pumping lemma says that for some split 0p1p = xyz all the following conditions hold • ∀i ≥ 0 xyiz ∈ A • |y| > 0 y is a non-empty string of 0s • |xy| ≤ p To prove A is not regular using the Pumping Lemma 1. 2. 3. 4. Suppose A is regular Call its pumping length p Find string s ∈ A with |s| ≥ p The pumping lemma says that for some split s = xyz all the following conditions hold • ∀i ≥ 0 xyiz ∈ A • |y| > 0 • |xy| ≤ p