Automata Theory Nfa
Automata Theory Nfa
CS411-2015F-04
Non-Determinisitic Finite Automata
David Galles
a
0 1
04-2: NFA Example
Example: L = {w ∈ {a, b} : w starts with a}
a(a+b)*
a,b
a
0 1
a a
0 1 2
a a
0 1 2
a,b a,b
a a
0 1 2
(q1, ε) reject
crash
(q1, baa) reject
(q1, a)
(q2, ε) accept
a a
0 1 2
All strings over {a, b} that start with a and end with
b
04-13: Fun with NFA
Create an NFA for:
All strings over {a, b} that start with a and end with
b
a,b
a b
0 1 3
(example compuational paths for ababb, abba, bbab)
04-14: Fun with NFA
Create an NFA for:
0,1 1 1 0,1
1 1 1 0
0
0 3
1 1
0 0
1 1 1
04-16: ǫ-Transitions
ǫ transition consumes no input
NFA (with ǫ transitions) for (ab)*(aab)*
a
1 1
b
ε
a a
1 1 1
b
04-17: ǫ-Transitions
Create an NFA (with ǫ-transitions) for:
ε ε ε
1 2 3
ε a
0 1 2
a b c ε
ε b
3 4 5 6
ε ε a
(quick review: What is L[M]?)
04-21: ǫ-closure
ǫ-closure examples
ε a
0 1 2
a b c ε
ε b
3 4 5 6
ε ε a
L[M] = {a, aa, ba, ca, aba}
04-22: ǫ-closure
ǫ-closure examples
ε a
0 1 2
a b c ε
ε b
3 4 5 6
ε ε a
ǫ-closure(q0 ) =
ǫ-closure(q3 ) =
ǫ-closure(q2 ) =
ǫ-closure(q5 ) =
04-23: ǫ-closure
ǫ-closure examples
ε a
0 1 2
a b c ε
ε b
3 4 5 6
ε ε a
ǫ-closure(q0 ) = {q0 , q1 , q4 , q5 }
ǫ-closure(q3 ) = {q3 , q4 , q5 }
ǫ-closure(q2 ) = {q2 , q6 }
ǫ-closure(q5 ) = {q5 }
04-24: ǫ-closure – Sets
ǫ-closure
ǫ-closure(q ) = set of all states that can be
reached following zero or more ǫ-transitions
from state q .
Can extend ǫ-closure to a set of states
S
ǫ-closure(S ) = {A : q ∈ S ∧ ǫ-closure(q) = A}
04-25: NFA Definition (revised)
A NFA is a 5-tuple M = (K, Σ, ∆, s, F )
K Set of states
Σ Alphabet
∆ : (K × (Σ ∪ {ǫ})) × K is a Transition relation
s ∈ K Initial state
F ⊆ K Final states
04-26: NFA ⊢M
Binary relation ⊢M : What machine M yields in one
step
⊢M ⊆ (K × Σ∗ ) × (K × Σ∗ )
⊢M = {((q1 , aw), (q2 , w)) : q1 , q2 ∈ KM , w ∈
Σ∗M , a ∈ ΣM ∪ {ǫ}, ((q1 , a), q2 ) ∈ ∆M }
Binary relation ⊢∗M : Transitive, reflexive closure of
⊢M
04-27: NFA Languages
L[M ] – Language defined by NFA M
L[M ] = {w : (sM , w) ⊢∗M (f, ǫ) for some
f ∈ FM ∗}
LN F A = {L : ∃N F A M, L[M ] = L}
04-28: NFA Examples
Create an NFA for the language
Give an NFA for the language L = All strings
over {0,1} that contain two pairs of adjacent 0’s
separated by an even number of symbols. So,
0100110011, 01100101100101, and 01001000
are in the language, but 0100100, 1011001,
and 0111011 are not in the language.
04-29: NFA Examples
Create an NFA for the language
Give an NFA for the language L = All strings
over {0,1} that contain two pairs of adjacent 0’s
separated by an even number of symbols. So,
0100110011, 01100101100101, and 01001000
are in the language, but 0100100, 1011001,
and 0111011 are not in the language.
0,1 0,1
0 0 0 0
0,1 0,1
04-30: NFA Examples
Create an NFA for the language
L = All strings over {a,b} that have an a as one
of the last 3 charaters in the string. So, a, baab,
bbbab, aabbaaabb ∈ L, but bb, baabbb,
bbabbbbb 6∈ L
04-31: NFA Examples
Create an NFA for the language
L = All strings over {a,b} that have an a as one
of the last 3 charaters in the string. So, a, baab,
bbbab, aabbaaabb ∈ L, but bb, baabbb,
bbabbbbb 6∈ L
a,b
a b b