complexity and computability theory i lecture #11 instructor: rina zviel-girshin lea epstein

44
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel- Girshin Lea Epstein

Upload: tabitha-walsh

Post on 17-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Complexity and Computability Theory I

Lecture #11

Instructor: Rina Zviel-Girshin

Lea Epstein

Page 2: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 2

Overview

• Models and limitations

• Examples

• Nondeterministic PDA

• Examples

• Equivalence of PDA’s models

Page 3: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 3

Finite automata

• A finite automaton has a huge limitation.

• It can count only by changing states.

• So the highest number FA can remember is not more than number of it's states.

• This limitation confined the class of languages that FA can recognize to a rather small category - that of regular languages.

Page 4: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 4

Turing machine

• Infinite memory can allow us recognition of larger class of languages.

• If we put no constrains on the use of this memory, i.e. the automaton can read and write in any location in the memory, then we have the most potent automaton

- Turing machine.

Page 5: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 5

Power of TM

• We claim that Turing machine (TM) can perform any computation the most powerful computer can.

Page 6: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 6

The stack model • If we add to FA an unlimited memory but

limit the use of it we get a machine which is stronger than FA but less powerful than TM.

• Our limitation - the memory will be a stack.

• We can read/write only at the top of the stack, obliterating the previous content.

Page 7: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 7

The stack model (cont.)

• We still have states to remember the previous contents (if we wish to do so).

• But as the number of states is finite we can remember only finite contents while our stack is infinite.

Page 8: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 8

Pushdown automata

• Informally a pushdown automata (PDA) is a FA+stack.

• To remember or to count we write to the stack and read afterwards when we need the information.

Page 9: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 9

Example• For example the following language can be

recognized by PDA but not FA.

L = {aibi | i>0}

• The basic idea of recognition:

• remembering a's by pushing it to the stack

• comparing the number of b's to the number of a's by popping one a for each b.

Page 10: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 10

Example (cont.)

• If the stack was emptied before the end of input - we had more b's than a's.

• If the stack was not emptied at the end of input - we had more a's than b's.

• The automaton will accept a word if at exactly the end of input the stack is emptied for the first time.

Page 11: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 11

Example (cont.)

• It gets stuck and rejects the word if the two events - – end of input and – the first time stack becomes empty

- are not simultaneous.

Page 12: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 12

Acceptance by PDA

• There are several models of PDA with different acceptance policies.

• All are equivalent.– acceptance by an empty stack – acceptance using accepting states – acceptance by an empty stack and accepting

states

Page 13: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 13

Acceptance by an empty stack

• The automaton will accept a word if exactly at the end of input the stack is emptied for the first time.

• All states are the same, there are no accepting states.

Page 14: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 14

Acceptance using accepting states

• The automaton will accept a word if at exactly the end of input the automaton is in accepting state.

• Whether the stack is empty or not at that time has no relevance.

Page 15: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 15

Acceptance by an empty stack and accepting states

• The automaton will accept a word if three events happen simultaneously: – the end of input – the stack is emptied for the first time– automaton is in accepting state.

Page 16: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 16

Transition function in PDA• There are two differences between the

transition functions of PDA and FA.• In PDA we move using

– A state, – A letter of input and – A letter of stack

• The transition function output is a state and a letter or string to be written into the stack.

Page 17: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 17

Formal definition of PDA• A pushdown automaton is a 6-tuple (Q, ,

, , q0, F) where:• Q – a finite set of states - a finite input alphabet - a finite stack alphabet: Q (U) P(Q *)• q0 Q the start state • F – a finite set of accepting states.

Page 18: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 18

The possible stack transformations

• Consider different possibilities of transition function:

(q,,X) = (q', Y)• where

(q - current state, - input letter, X - top of the stack) = (q' - next state, Y - string to write into the stack)

Page 19: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 19

Popping the stack

• Popping the stack:(q,,X) = (q', )

• write an empty word to the stack, i.e. deleting the X at the top of the stack and moving the top pointer one cell down.

Page 20: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 20

No change

• No change:(q,,X) = (q', X)

• write the same letter to the stack, i.e. not changing the X at the top of the stack and not moving the top pointer

Page 21: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 21

Add to the stack

• Add to the stack:(q,,X) = (q', W1..WnX)• write the same letter to the stack and above

it write a string, i.e. not changing the X at the top of the stack, but adding any number of letters above in the same one transition and moving the top pointer as needed

Page 22: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 22

Change the stack

• Change the stack:(q,,X) = (q', W1..Wn)

• delete the letter X in the stack and instead write a string, i.e. changing the X at the top of the stack into any number of letters above in the same one transition and moving the top pointer as needed

Page 23: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 23

Bottom of the stack symbol

• The acceptance model we will use will be by emptying the stack.

• In this model of acceptance the PDA is stuck immediately if the stack is empty.

• Therefore the PDA can't start with an empty stack.

Page 24: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 24

Bottom of the stack symbol• Therefore we will assume that at the

commencement of the computation, the stack already includes one symbol - a special "bottom of the stack symbol".

• There are many possible notations for the symbol, such as $, ┤.

• We will use the letter Z for the "bottom of the stack symbol".

Page 25: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 25

Example

Construct a PDA to recognize: L = {aibi | i>0}We will use the empty stack model.

q1q0 b,A;

a,Z;A a,A;AA b,A;

Page 26: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 26

Example• Construct a PDA to recognize: L = {wcwR |w{a,b}*}• We will use the empty stack model.

q1q0 c,Z; c,A; A c,B; B

a,Z; A b,Z; Ba,A; AA b,A; BAa,B; AB b,B; BB

b,B;a,A;

Page 27: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 27

ExampleL = {aibj | i >0 and j=i+5}

• Construct a PDA to recognize: • We will use the empty stack model.

q1q0 b,A;

a,Z; AAAAAAa,A; AA b,A;

Page 28: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 28

Deterministic PDA

• A PDA is called deterministic if”f it holds the following two conditions:

• for each qQ, a{} and X– |(q,a,X)| 1

• for each qQ and X– if (q,,X)– then for each (q, ,X)=

Page 29: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 29

Deterministic PDA

Informally

• A PDA is called non-deterministic if there exist at least two transitions from the current state q and stack top X:– one with (-transition) and – another with .

Page 30: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 30

Example of ND PDA• Construct a PDA to recognize:

L = {wwR |w{a,b}*}

We will use the empty stack model

q1q0 e,A; A e,Z; e e,B; B

a,Z; A b,Z; Ba,A; AA b,A; BAa,B; AB b,B; BB

b,B; ea,A; e

Page 31: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 31

Example of ND PDA

• Construct a PDA to recognize:

L = {aibjci+j | i,j0}

We will use the empty stack model.

The basic idea:

• push a’s and b’s to the stack and than pop the stack top symbol for each c letter.

Page 32: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 32

L = {aibjci+j | i,j0}

q1

q0

c,A; e

a,Z; Aa,A; AA

c,A; e

q2b,A; AAb,Z; A

e ,Z; e

q3

b,A; AA

c ,A; e

Page 33: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 33

Example • Construct a PDA to recognize:

L = {aibj | i,j>0}

• We will use a finite state model.

qfq0 b,A; A

a,Z; Aa,A; A b,A; A

q4q1

Page 34: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 34

Equivalent form of acceptance

• The empty stack PDA equivalent to the final state PDA

The basic idea:

• We will use the empty stack PDA model during the computation and on the last stage we will produce -transition to the final state.

Page 35: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 35

Algorithm

• Given PDA=(Q, , , , q0, ∅)

• Convert it to

FS PDA=(QU{s,f}, , U{Y}, , s, F={f})

1.Create a new start state s and a new final state f.

2.Create a new bottom of the stack symbol: Y.

Page 36: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 36

Algorithm(cont.)

3.Connect a new start state s to the old start state q0 by an edge labeled ,Y; ZY that means (s,,Y)=(q0,ZY)

4.Connect each state of the PDA to the new final state f and label the edges with the expression ,Y; Y.

Page 37: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 37

L={a}

• Given an empty stack automaton:

Construct an equivalent final-state automaton.

Page 38: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 38

L={a}

•The resulting finite-state automaton:

Page 39: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 39

Equivalent form of acceptance

• The final-state PDA is equivalent to the empty stack PDA

The basic idea:• We will use a finite state PDA model during

the computation and on the last stage we will produce -transition to empty the stack state - by popping everything from the stack.

Page 40: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 40

Algorithm• Given PDA=(Q, , , , q0, F)• Convert it to ESPDA=(QU{s,f}, , U{Y},

, s, ∅)

1. Create a new start state s and a new “empty state” f.

2. Create a new bottom of the stack symbol: Y.

Page 41: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 41

Algorithm(cont.)3. Connect a new start state s to the old start state q0

by an edge labeled ,Y; ZY that means (s,,Y)=(q0,ZY)

4. Connect each final state of the PDA to the new empty state f and label the edges with the expression ,A; where A means any symbol of the stack, including Z and Y.

5. Add new edges from f to f labeled as in step 4:(f,,A)=(f, ) for every A in .

Page 42: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 42

L={a}

• Given a finite-state automaton:

Construct an equivalent empty stack automaton.

Page 43: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 43

L={a}

•The resulting automaton:

Page 44: Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC 44

Any Questions?