what can be computed with finite memory? input tape 0 1 1 0 ···...
TRANSCRIPT
Finite Automata
What can be computed with finite memory?
state
0 1 1 0 · · ·input tape
Finite Automata
What can be computed with finite memory?
state
0 1 1 0 · · ·input tape
Finite Automata
What can be computed with finite memory?
state
0 1 1 0 · · ·input tape
A “Wild” Finite Automaton
The input is the numbers pressed by theuser
The correct code is 1234
Actually the door is opened if{0, . . . ,9}∗1234{0, . . . ,9}∗ is entered
The machine needs to remember if theinput given so far contains thesubsequence 1234
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:
States: q1 and q2
Start state: q1 (arrow from nowhere)
Accept state: q2 (double circle)
State transitions: arrows
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input string s = s1s2 · · · sn, M operates as follows:
Begins in start state q1 and reads the string s from left torightWhen reading symbol si it follows the transition labeled si
from the current stateAfter reading sn, the last symbol in the string, it
accepts s if it is in an accept staterejects s if it is not in an accept state
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input:011
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input:011 ACCEPT
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input:011 ACCEPT10
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input:011 ACCEPT10 REJECT
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input:011 ACCEPT10 REJECT110
Finite Automata: Informal Definition
q1 q2
1
0
0 1
The machine M:On input:011 ACCEPT10 REJECT110 REJECT
A “Wild” Finite Automaton
The input is the numbers pressed by theuser
The correct code is 1234
Actually the door is opened if{0, . . . ,9}∗1234{0, . . . ,9}∗ is entered
The machine needs to remember if theinput given so far contains thesubsequence 1234
A “Wild” Finite Automaton
The input is the numbers pressed by theuser
The correct code is 1234
Actually the door is opened if{0, . . . ,9}∗1234{0, . . . ,9}∗ is entered
The machine needs to remember if theinput given so far contains thesubsequence 1234
qs q1 q12 q123 q12341 2 3 4
0,2, . . . ,9
1
0,3, . . . ,9
0, . . . ,90,2,4, . . . ,9
0,2,3,5, . . . ,9
1
1
Representation of finite automata
State diagram
q1 q2
1
0
0 1
Transition table0 1
→ q1 q1 q2
F q2 q1 q2
Definition of DFAs
Definition
A deterministic finite automaton (DFA) is a 5-tuple(Q,Σ, δ,q0,F ) where
Q is a finite set called the states
Σ is a finite set called the alphabet
δ : Q × Σ → Q is the transition function
q0 ∈ Q is the start state
F ⊆ Q is the set of accept states
The language recognized by a DFA
Definition
Let M = (Q,Σ, δ,q0,F ) be a DFA and s = s1s2 · · · sn a stringover Σ. M accepts s if there is a sequence of states r0, r1, . . . rn
from Q such that
r0 = q0,
δ(ri , si+1) = ri+1 (i = 0, . . . ,n − 1), and
rn ∈ F
The language recognized by a DFA
Definition
Let M = (Q,Σ, δ,q0,F ) be a DFA and s = s1s2 · · · sn a stringover Σ. M accepts s if there is a sequence of states r0, r1, . . . rn
from Q such that
r0 = q0,
δ(ri , si+1) = ri+1 (i = 0, . . . ,n − 1), and
rn ∈ F
Definition
M recognizes language L if L = {s | M accepts s}
L(M) denotes the language recognized by M
Regular Languages
DefinitionA language is a regularlanguage if some DFArecognizes it
Nondeterminism
The machines we have seen so far have beendeterministic. The next state follows uniquely from thecurrent state and the input symbol
In a nondeterministic machine several possible next statesmay follow from the current state and input symbol. Thesepossibilities can be thought of as being explored in parallel
Understanding the power of nondeterminism is a centraltopic in the theory of computation (and this course)
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
An NFA accepts a string s if, after reading the last symbolof s, at least one of its active states is an accept state
An NFA rejects a string s if, after reading the last symbol ofs, none if its active states is an accept state
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
0101 REJECT
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110
Example of a nondeterminstic finite automaton (NFA)
p q r1 0,1
0,1
110 ACCEPT
Example of a NFA with ε transitions
p q r1 0,1
0,1
q1 q2
1
0
0 1
Example of a NFA with ε transitions
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
Example of a NFA with ε transitions
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
01
Example of a NFA with ε transitions
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
01
Example of a NFA with ε transitions
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
01
Example of a NFA with ε transitions
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
01 ACCEPT
Definition of NFAs
The power set of Q, written P(Q), is the set of all subsets of Q
Example
If A = {1,2} then P(A) = {∅, {1}, {2}, {1,2}}
Definition of NFAs
Definition
A nondeterministic finite automaton (NFA) is a 5-tuple(Q,Σ, δ,q0,F ) where
Q is a finite set called the states
Σ is a finite set called the alphabet
δ : Q × (Σ ∪ {ε}) → P(Q) is the transition function
q0 ∈ Q is the start state
F ⊆ Q is the set of accept states
The language recognized by a NFA
Definition
Let N = (Q,Σ, δ,q0,F ) be a NFA and s = s1s2 · · · sm a stringover Σ. N accepts s if there is a sequence of states r0, r1, . . . rn
from Q and s can be written as s = s1, s2 . . . , sn where eachsi ∈ Σ ∪ {ε} such that
r0 = q0,
ri+1 ∈ δ(ri , si+1) (i = 0, . . . ,n − 1), and
rn ∈ F
Equivalence of DFAs and NFAs
Definition
Two machines are equivalent if they recognize the samelanguage
Equivalence of DFAs and NFAs
TheoremEvery NFA has an equivalent DFA
Equivalence of DFAs and NFAs
TheoremEvery NFA has an equivalent DFA
Proof idea.
Given a NFA we need to construct a DFA that simulate the NFA
The DFA need to keep track of the set of active states ofthe NFA at each step
If k is the number of states of the NFA, then the DFA mightneed up to 2k states (one for each subset of states of theNFA)
So, the states of the DFA should be P(Q) where Q is thestates of the NFA
Equivalence of DFAs and NFAs
TheoremEvery NFA has an equivalent DFA
Notation: Let E(R) be the set of states that can be reachedfrom R using 0 or more ε transitions.
Equivalence of DFAs and NFAs
Theorem
Every NFA has an equivalent DFA
Notation: Let E(R) be the set of states that can be reachedfrom R using 0 or more ε transitions.
Proof.
The subset construction: Given a NFA N = (Q,Σ, δ,q0,F ) weconstruct an equivalent DFA M = (Q′,Σ, δ′,q′
0,F′) where
Q′ = P(Q)
q′
0 = E({q0})
F ′ = {R ∈ Q′ | R ∩ F 6= ∅}
Equivalence of DFAs and NFAs
TheoremEvery NFA has an equivalent DFA
Notation: Let E(R) be the set of states that can be reachedfrom R using 0 or more ε transitions.
Proof.
The subset construction: Given a NFA N = (Q,Σ, δ,q0,F ) weconstruct an equivalent DFA M = (Q′,Σ, δ′,q′
0,F′) where
For R ∈ Q′ and a ∈ Σ,δ′(R,a) = {q ∈ Q | q ∈ E(δ(r ,a)) for some r ∈ R}
δ′(R,a) is the set of all states that can be reached (in theNFA) by first following a transition labeled a from a state inR and then following 0 or more ε transitions
Equivalence of DFAs and NFAs: Example
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
0 1→ {s,q1,p} {q1,p} {q2,p,q}
Equivalence of DFAs and NFAs: Example
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
0 1→ {s,q1,p} {q1,p} {q2,p,q}{q1,p} {q1,p} {q2,p,q}
Equivalence of DFAs and NFAs: Example
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
0 1→ {s,q1,p} {q1,p} {q2,p,q}{q1,p} {q1,p} {q2,p,q}F {q2,p,q} {q1,p, r} {q2,p,q, r}
Equivalence of DFAs and NFAs: Example
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
0 1→ {s,q1,p} {q1,p} {q2,p,q}{q1,p} {q1,p} {q2,p,q}F {q2,p,q} {q1,p, r} {q2,p,q, r}F {q1,p, r} {q1,p} {q2,p,q}
Equivalence of DFAs and NFAs: Example
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
0 1→ {s,q1,p} {q1,p} {q2,p,q}{q1,p} {q1,p} {q2,p,q}F {q2,p,q} {q1,p, r} {q2,p,q, r}F {q1,p, r} {q1,p} {q2,p,q}F {q2,p,q, r} {q1,p, r} {q2,p,q, r}
Equivalence of DFAs and NFAs: Example
p q r1 0,1
0,1
q1 q2
s
ε
ε
1
0
0 1
{q1,p} {q2,p,q, r}0
{q2,p,q} {q1,p, r}
{s,q1,q}
0
1 1
1
0
0
1
0
1
Equivalence of DFAs and NFAs
TheoremEvery NFA has an equivalent DFA
Corollary
Every language recognized by a NFA can be recognized by aDFA