22
Theory of Computation Lecture 7: Push Down Automata (PDA) Cairo University FCI Dr. Hussien Sharaf Computer Science Department [email protected]

Theory of computation Lec7 pda

Embed Size (px)

DESCRIPTION

Theory of computation PDA

Citation preview

Page 1: Theory of computation Lec7 pda

Theory of Computation

Lecture 7: Push Down Automata (PDA)

Cairo UniversityFCI

Dr. Hussien SharafComputer Science [email protected]

Page 2: Theory of computation Lec7 pda

2

p.434: Regular Languages and non-regular languages

Dr. Hussien M. Sharaf

Language Defined by

Corresponding Accepting Machine

Nondeter-minism=Determinism

Language Closed Under

What Can Be Decided?

Examples of Applications

Regular expression

Finite automaton, transition graph

Yes Union,productKleene star, intersection, complement

Equivalence, emptiness, finiteness, membership

Text editors, sequential circuits, verification

Context-free grammar

Pushdown automaton

No Union, product, Kleene star

Emptiness, finiteness, membership

Parsing, compilers

Type 0 grammar

Turing machine, Post machine, Pushdown automaton

Yes Union, product, Kleene star

Not much Computers

Page 3: Theory of computation Lec7 pda

3

PDAA Pushdown Automata (PDA ) is a DFA

equipped with a single stack.

Dr. Hussien M. Sharaf

1

4

3

2

1 2 3 4

Input Tape

Tape cells

Page 4: Theory of computation Lec7 pda

4

PDA

Dr. Hussien M. Sharaf

1. Q : A finite set of states (Q).2. Σ : A set of input alphabet.3. Γ (capital Gammma): A set of stack alphabet.4. (delta): A transition function represents the set

of transitions that moves PDA to the next states.

: Q x Σ x Γ →Q.5. q0 Q : start state.

6. F ⊆ Q is the set of final states.

ε Γ and Σ : start symbol for the stack and end symbol for the Input Tape.

Page 5: Theory of computation Lec7 pda

5

FA = “a 5-tuple “ (Q, Σ, , q0, F)

1. Q: {q0, q1, q2, …} is set of states.

2. Σ: {a, b, …} set of alphabet.3. (delta): represents the set of transitions

that FA can take between its states.: Q x Σ→Q

4. q0 Q is the start state.

5. F Q is the set of final/accepting states.

Dr. Hussien M. Sharaf

Remember and compare FA

Page 6: Theory of computation Lec7 pda

6

PDA as a deterministic machine

Its inputs are1. The current state (of its “NFA”),2. The current input symbol (or Λ),

and 3. The current symbol on top of its

stack.

Dr. Hussien M. Sharaf

1

4

3

2

Its actions are:1. Change state.2. Change stack if needed.

Page 7: Theory of computation Lec7 pda

7

Power of PDA

Dr. Hussien M. Sharaf

Page 8: Theory of computation Lec7 pda

8

Ex1 P.295 cohen Edition 2:Consider the following PDA for anbn

Dr. Hussien M. Sharaf

Page 9: Theory of computation Lec7 pda

9

Ex1 P.295:Consider the following Input

Dr. Hussien M. Sharaf

Δ

a a

Input Tape

a b b b Δ

Start

Read

Push Δa

b

Page 10: Theory of computation Lec7 pda

10

Ex1 P.295:Consider the following PDA

Dr. Hussien M. Sharaf

aa a

Input Tape

a b b b Δ

Start

Read

Push Δa

b

Δ

Page 11: Theory of computation Lec7 pda

11

Ex1 P.295:Consider the following PDA

Dr. Hussien M. Sharaf

a

a a

Input Tape

a b b b Δ

Start

Read

Push Δa

b

Δ

a

a

Page 12: Theory of computation Lec7 pda

12

Ex1 P.295:Consider the following PDA

Dr. Hussien M. Sharaf

aa a

Input Tape

a b b b Δ

POP ab, Δ

a

Δ

a

Read

Δ

b b

Reject

Reject

Page 13: Theory of computation Lec7 pda

13

Ex1 P.295:Consider the following PDA

Dr. Hussien M. Sharaf

aa a

Input Tape

a b b b Δ

POP ab, Δ

a

Δ

Read

Δ

b b

Reject

Reject

Page 14: Theory of computation Lec7 pda

14

Ex1 P.295:Consider the following PDA

Dr. Hussien M. Sharaf

a a

Input Tape

a b b b Δ

POP ab, Δ

a

Δ

Read

Δ

b b

Reject

Reject

Page 15: Theory of computation Lec7 pda

15

Ex1 P.295:Consider the following PDA

Dr. Hussien M. Sharaf

a a

Input Tape

a b b b Δ

Read

Δ Pop a,b

Accept

Δ

Reject

Page 16: Theory of computation Lec7 pda

16

Ex2: Even Palindrome P.304Can you list samples of words in even palindrome?

Dr. Hussien M. Sharaf

PUSH a READ2READ1

POP3

POP2

POP1START

ACCEPT

PUSH b

a

b

a

a

a

b b

b

Δ

Δ

Δ

Page 17: Theory of computation Lec7 pda

17

Ex2: Even Palindrome

Dr. Hussien M. Sharaf

Consider babbab

Page 18: Theory of computation Lec7 pda

18

Ex2: Even Palindrome

Dr. Hussien M. Sharaf

Jump to the right part

Page 19: Theory of computation Lec7 pda

19

Ex2: Even Palindrome

Dr. Hussien M. Sharaf

We have just read first many blanks on the TAPE

Page 20: Theory of computation Lec7 pda

20

Assignment #5Read Example P.308 in Cohen’s book and

hand in a stack table for input 4 * 4 + 4.

The assignment must be hand written.

Dr. Hussien M. Sharaf

Page 21: Theory of computation Lec7 pda

21

PDA for Balanced strings

State diagram for

L = {0n 1n | n >= 0} Dr. Hussien M. Sharaf

0 ,ε0

q4

q1

(delta) is shown in the state diagram"ε“ or “” means ignore or don’t care for both input and stack.$ means end for both input or stack

q3

q2

0 ,00

1 ,0pop

1 ,0pop

$ ,   $no   Action

$ ,   $no   Action

Page 22: Theory of computation Lec7 pda

22

Thank you

Dr. Hussien M. Sharaf