CSCI 2670 Introduction to Theory of Computing

September 21, 2005

Agenda

- Yesterday
- Pushdown automata
- Today
- Quiz
- More on pushdown automata
- Pumping lemma for CFGs

Finite automata and PDA schematics

State control

FA

State control

PDA

Stack Infinite LIFO (last in first out) device

Definition of pushdown automaton

- A pushdown automaton is a 6-tuple (Q,?,?,?,q0,F),

where Q,?,?, and F are all finite sets, and - Q is the set of states
- ? is the input alphabet
- ? is the stack alphabet
- ? Q ? ?e ? ?e ? P(Q ? ?e) is the transition

function - q0 ? Q is the start state, and
- F ? Q are the accept states.

Strings accepted by a PDA

- Let w be a string in ? and P a PDA. w is in

L(P) iff w can be written ww1w2wn, where each

wi??e, and there exist r0,r1,,rn?Q and

s0,s1,,sn?? satisfying the following - r0q0 and s0e
- M starts in the start state with an empty stack
- (ri1,b)??(ri,wi1,a), where siat and si1bt

for some a,b??e and t?? - M moves according to transition rules for the

state, input and stack - rm?F
- accept state occurs at input end

A closer look at the transition rule

- (ri1,b)??(ri,wi1,a), where siat and si1bt

for some a,b??e and t?? - The top symbol is
- Pushed if ae and b?e
- Popped if a?e and be
- Changed if a?e and b?e
- Unchanged if ae and be
- Symbols below the top of the stack may be

considered, but not changed - This is ts role

Example

- Find ? for the PDA that accepts all strings in

0,1 with the same number of 0s and 1s - Need to keep track of equilibrium point with a

on the stack - If stack top is not , it contains the symbol

currently dominating in the string

Example

- Find ? for the PDA that accepts all strings in

0,1 with the same number of 0s and 1s - Push a symbol on the stack as its read if
- It matches the top of the stack, or
- The top of stack is
- Pop the symbol off the top of the stack if you

read a 0 and the top of stack is 1 or vice versa

Example

Example

This PDA is equivalent to the one on the previous

slide

Example

- Nested parentheses

Equivalence of PDAs and CFGs

- Theorem A language is context free if and only

if some pushdown automaton recognizes it - Proved in two lemmas one for the if direction

and one for the only if direction

CFGs are recognized by PDAs

- Lemma If a language is context free, then some

pushdown automaton recognizes it - Proof idea Construct a PDA following CFG rules

Constructing the PDA

- You can read any symbol in ? when that symbol is

at the top of the stack - Transitions of the form a,a?e
- The rules will be pushed onto the stack when a

variable A is on top of the stack and there is a

rule A?w, you pop A and push w - You can go to the accept state only if the stack

is empty