csci 2670 introduction to theory of computing september 21, 2005

14
CSCI 2670 Introduction to Theory of Computing September 21, 2005

Upload: phebe-white

Post on 28-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CSCI 2670 Introduction to Theory of Computing September 21, 2005

CSCI 2670Introduction to Theory of

Computing

September 21, 2005

Page 2: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 2

Agenda

• Yesterday– Pushdown automata

• Today– Quiz– More on pushdown automata– Pumping lemma for CFG’s

Page 3: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 3

Finite automata and PDA schematics

State control

a a b b

State control

a a b b

xyz

FA

PDA

Stack: Infinite LIFO (last in first out) device

Page 4: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 4

Definition of pushdown automaton

A pushdown automaton is a 6-tuple (Q,,,,q0,F), where Q,,, and F are all finite sets, and

1. Q is the set of states2. is the input alphabet 3. is the stack alphabet 4. : Q ε ε P(Q ε) is the

transition function5. q0 Q is the start state, and

6. F Q are the accept states.

Page 5: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 5

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 w=w1w2…wn, where each wiε, and there exist r0,r1,…,rnQ and s0,s1,…,sn* satisfying the following:

1. r0=q0 and s0=ε - M starts in the start state with an empty stack

2. (ri+1,b)(ri,wi+1,a), where si=at and si+1=bt for some a,bε and t* - M moves according to transition rules for the

state, input and stack

3. rmF - accept state occurs at input end

Page 6: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 6

A closer look at the transition rule

• (ri+1,b)(ri,wi+1,a), where si=at and

si+1=bt for some a,bε and t* – The top symbol is

• Pushed if a=ε and bε• Popped if aε and b=ε• Changed if aε and bε• Unchanged if a=ε and b=ε

– Symbols below the top of the stack may be considered, but not changed• This is t’s role

Page 7: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 7

Example

• Find for the PDA that accepts all strings in {0,1}* with the same number of 0’s and 1’s

1. Need to keep track of “equilibrium point” with a $ on the stack

2. If stack top is not $, it contains the symbol currently dominating in the string

Page 8: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 8

Example

• Find for the PDA that accepts all strings in {0,1}* with the same number of 0’s and 1’s

3. Push a symbol on the stack as its read if1. It matches the top of the stack, or2. The top of stack is $

4. Pop the symbol off the top of the stack if you read a 0 and the top of stack is 1 or vice versa

Page 9: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 9

Example

ε,ε$

0,$0$0,0 000,11 1 0,1$ $

1,$1$1,1 111,00 0 1,0$ $

ε,$ ε

Page 10: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 10

Example

ε,ε$

0,$0$0,0 000,1 ε

1,$1$1,1 111,0 ε

ε,$ ε

This PDA is equivalent to the one on the previous slide

Page 11: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 11

Example

• Nested parentheses

ε,ε$

(, ε(

ε,$ ε

),( ε

Page 12: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 12

Equivalence of PDA’s and CFG’s

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

Page 13: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 13

CFG’s are recognized by PDA’s

Lemma: If a language is context free, then some pushdown automaton recognizes it

Proof idea: Construct a PDA following CFG rules

Page 14: CSCI 2670 Introduction to Theory of Computing September 21, 2005

September 23, 2004 14

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ε

• The rules will be pushed onto the stack – when a variable A is on top of the stack and there is a rule Aw, you pop A and push w

• You can go to the accept state only if the stack is empty