SlideShare a Scribd company logo
1 of 37
Download to read offline
1
Nondeterministic Finite
Automata
Nondeterminism
Subset Construction
2
Nondeterminism
A nondeterministic finite automaton
has the ability to be in several states at
once.
Transitions from a state on an input
symbol can be to any set of states.
3
Nondeterminism – (2)
Start in one start state.
Accept if any sequence of choices leads
to a final state.
Intuitively: the NFA always “guesses
right.”
4
Example: Moves on a
Chessboard
States = squares.
Inputs = r (move to an adjacent red
square) and b (move to an adjacent
black square).
Start state, final state are in opposite
corners.
5
Example: Chessboard – (2)
1 2
5
7 9
3
4
8
6
1
r b b
4
2 1
5
3
7
5
1
3
9
7
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
Accept, since final state reached
6
Formal NFA
A finite set of states, typically Q.
An input alphabet, typically Σ.
A transition function, typically δ.
A start state in Q, typically q0.
A set of final states F ⊆ Q.
7
Transition Function of an NFA
δ(q, a) is a set of states.
Extend to strings as follows:
Basis: δ(q, ε) = {q}
Induction: δ(q, wa) = the union over
all states p in δ(q, w) of δ(p, a)
8
Language of an NFA
A string w is accepted by an NFA if
δ(q0, w) contains at least one final
state.
The language of the NFA is the set of
strings it accepts.
9
Example: Language
of an NFA
For our chessboard NFA we saw that
rbb is accepted.
If the input consists of only b’s, the set
of accessible states alternates between
{5} and {1,3,7,9}, so only even-length,
nonempty strings of b’s are accepted.
What about strings with at least one r?
1 2
5
7 9
3
4
8
6
10
Equivalence of DFA’s, NFA’s
A DFA can be turned into an NFA that
accepts the same language.
If δD(q, a) = p, let the NFA have
δN(q, a) = {p}.
Then the NFA is always in a set
containing exactly one state – the state
the DFA is in after reading the same
input.
11
Equivalence – (2)
Surprisingly, for any NFA there is a DFA
that accepts the same language.
Proof is the subset construction.
The number of states of the DFA can
be exponential in the number of states
of the NFA.
Thus, NFA’s accept exactly the regular
languages.
12
Subset Construction
Given an NFA with states Q, inputs Σ,
transition function δN, state state q0, and
final states F, construct equivalent DFA
with:
 States 2Q (Set of subsets of Q).
 Inputs Σ.
 Start state {q0}.
 Final states = all those with a member of F.
13
Critical Point
The DFA states have names that are
sets of NFA states.
But as a DFA state, an expression like
{p,q} must be read as a single symbol,
not as a set.
Analogy: a class of objects whose
values are sets of objects of another
class.
14
Subset Construction – (2)
The transition function δD is defined by:
δD({q1,…,qk}, a) is the union over all i =
1,…,k of δN(qi, a).
Example: We’ll construct the DFA
equivalent of our “chessboard” NFA.
15
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1} {2,4} {5}
{2,4}
{5}
Alert: What we’re doing here is
the lazy form of DFA construction,
where we only construct a state
if we are forced to.
16
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1}
{2,4,6,8}
{5}
{2,4} {2,4,6,8} {1,3,5,7}
{1,3,5,7}
{2,4} {5}
17
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1}
* {1,3,7,9}
{2,4,6,8}
{2,4,6,8} {1,3,7,9}
{5}
{2,4} {2,4,6,8} {1,3,5,7}
{1,3,5,7}
{2,4} {5}
18
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1}
* {1,3,5,7,9}
* {1,3,7,9}
{2,4,6,8} {1,3,5,7,9}
{2,4,6,8}
{2,4,6,8} {1,3,7,9}
{5}
{2,4} {2,4,6,8} {1,3,5,7}
{1,3,5,7}
{2,4} {5}
19
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1}
* {1,3,5,7,9}
* {1,3,7,9}
{2,4,6,8} {1,3,5,7,9}
{2,4,6,8}
{2,4,6,8} {1,3,7,9}
{5}
{2,4} {2,4,6,8} {1,3,5,7}
{1,3,5,7}
{2,4} {5}
{2,4,6,8} {1,3,5,7,9}
20
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1}
* {1,3,5,7,9}
* {1,3,7,9} {2,4,6,8} {5}
{2,4,6,8} {1,3,5,7,9}
{2,4,6,8}
{2,4,6,8} {1,3,7,9}
{5}
{2,4} {2,4,6,8} {1,3,5,7}
{1,3,5,7}
{2,4} {5}
{2,4,6,8} {1,3,5,7,9}
21
Example: Subset Construction
r b
1 2,4 5
2 4,6 1,3,5
3 2,6 5
4 2,8 1,5,7
5 2,4,6,8 1,3,7,9
6 2,8 3,5,9
7 4,8 5
8 4,6 5,7,9
9 6,8 5
*
r b
{1}
* {1,3,5,7,9} {2,4,6,8} {1,3,5,7,9}
* {1,3,7,9} {2,4,6,8} {5}
{2,4,6,8} {1,3,5,7,9}
{2,4,6,8}
{2,4,6,8} {1,3,7,9}
{5}
{2,4} {2,4,6,8} {1,3,5,7}
{1,3,5,7}
{2,4} {5}
{2,4,6,8} {1,3,5,7,9}
22
Proof of Equivalence: Subset
Construction
The proof is almost a pun.
Show by induction on |w| that
δN(q0, w) = δD({q0}, w)
Basis: w = ε: δN(q0, ε) = δD({q0}, ε) =
{q0}.
23
Induction
Assume IH for strings shorter than w.
Let w = xa; IH holds for x.
Let δN(q0, x) = δD({q0}, x) = S.
Let T = the union over all states p in S of
δN(p, a).
Then δN(q0, w) = δD({q0}, w) = T.
 For NFA: the extension of δN.
 For DFA: definition of δD plus extension of δD.
• That is, δD(S, a) = T; then extend δD to w = xa.
24
NFA’s With ε-Transitions
We can allow state-to-state transitions
on ε input.
These transitions are done
spontaneously, without looking at the
input string.
A convenience at times, but still only
regular languages are accepted.
25
Example: ε-NFA
C
E F
A
B D
1
1 1
0
0
0
ε
ε ε
0 1 ε
A {E} {B} ∅
B ∅ {C} {D}
C ∅ {D} ∅
D ∅ ∅ ∅
E {F} ∅ {B, C}
F {D} ∅ ∅
*
26
Closure of States
CL(q) = set of states you can reach
from state q following only arcs labeled
ε.
Example: CL(A) = {A};
CL(E) = {B, C, D, E}.
Closure of a set of states = union of
the closure of each state.
C
E F
A
B D
1
1 1
0
0
0
ε
ε ε
27
Extended Delta
 Basis: (q, ε) = CL(q).
 Induction: (q, xa) is computed as
follows:
1. Start with (q, x) = S.
2. Take the union of CL(δ(p, a)) for all p in S.
 Intuition: (q, w) is the set of states
you can reach from q following a path
labeled w.
˄
δ
˄
δ
˄
δ
˄
δ
And notice that δ(q, a) is not
that set of states, for symbol a.
28
Example:
Extended Delta
 (A, ε) = CL(A) = {A}.
 (A, 0) = CL({E}) = {B, C, D, E}.
 (A, 01) = CL({C, D}) = {C, D}.
Language of an ε-NFA is the set of
strings w such that (q0, w) contains a
final state.
C
E F
A
B D
1
1 1
0
0
0
ε
ε ε
˄
δ
˄
δ
˄
δ
˄
δ
29
Equivalence of NFA, ε-NFA
Every NFA is an ε-NFA.
 It just has no transitions on ε.
Converse requires us to take an ε-NFA
and construct an NFA that accepts the
same language.
We do so by combining ε–transitions
with the next transition on a real input.
Warning: This treatment is a
bit different from that in the text.
30
Picture of ε-Transition Removal
Transitions
on ε
a
a
a
Transitions
on ε
31
Picture of ε-Transition Removal
Transitions
on ε
a
a
a
Transitions
on ε
Text goes
from here
To here, and performs
the subset construction
32
Picture of ε-Transition Removal
Transitions
on ε
a
a
a
Transitions
on ε
We’ll go
from here
To here, with no
subset construction
33
Equivalence – (2)
Start with an ε-NFA with states Q,
inputs Σ, start state q0, final states F,
and transition function δE.
Construct an “ordinary” NFA with states
Q, inputs Σ, start state q0, final states
F’, and transition function δN.
34
Equivalence – (3)
 Compute δN(q, a) as follows:
1. Let S = CL(q).
2. δN(q, a) is the union over all p in S of
δE(p, a).
 F’ = the set of states q such that
CL(q) contains a state of F.
 Intuition: δN incorporates ε–transitions
before using a but not after.
35
Equivalence – (4)
Prove by induction on |w| that
CL(δN(q0, w)) = E(q0, w).
Thus, the ε-NFA accepts w if and only if
the “ordinary” NFA does.
˄
δ
36
Example: ε-NFA-
to-NFA
0 1 ε
A {E} {B} ∅
B ∅ {C} {D}
C ∅ {D} ∅
D ∅ ∅ ∅
E {F} ∅ {B, C}
F {D} ∅ ∅
*
ε-NFA
0 1
A {E} {B}
B ∅ {C}
C ∅ {D}
D ∅ ∅
E {F} {C, D}
F {D} ∅
*
*
*
Since closure of
E includes B and
C; which have
transitions on 1
to C and D.
Since closures of
B and E include
final state D.
Interesting
closures: CL(B)
= {B,D}; CL(E)
= {B,C,D,E}
37
Summary
DFA’s, NFA’s, and ε–NFA’s all accept
exactly the same set of languages: the
regular languages.
The NFA types are easier to design and
may have exponentially fewer states
than a DFA.
But only a DFA can be implemented!

More Related Content

Similar to Nondeterministic Finite Automata AFN.pdf

@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdfFariyaTasneem1
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Srimatre K
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introductionNAMRATA BORKAR
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxamara jyothi
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxranjan317165
 
NFA DFA Equivalence theorem
NFA DFA Equivalence theorem NFA DFA Equivalence theorem
NFA DFA Equivalence theorem niveditJain
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdfshruti533256
 
Theory of automata
Theory of automataTheory of automata
Theory of automataArslan905905
 
Chapter 2 2 1 1
Chapter 2 2 1 1Chapter 2 2 1 1
Chapter 2 2 1 1bolovv
 
Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata parmeet834
 
1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automatonSampath Kumar S
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdfAbrar11535
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 

Similar to Nondeterministic Finite Automata AFN.pdf (20)

@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
 
5. NFA & DFA.pdf
5. NFA & DFA.pdf5. NFA & DFA.pdf
5. NFA & DFA.pdf
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3Formal Languages and Automata Theory unit 3
Formal Languages and Automata Theory unit 3
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introduction
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
Finite automata
Finite automataFinite automata
Finite automata
 
NFA DFA Equivalence theorem
NFA DFA Equivalence theorem NFA DFA Equivalence theorem
NFA DFA Equivalence theorem
 
6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf
 
Theory of automata
Theory of automataTheory of automata
Theory of automata
 
Fsa
FsaFsa
Fsa
 
Chapter 2 2 1 1
Chapter 2 2 1 1Chapter 2 2 1 1
Chapter 2 2 1 1
 
Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdf
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 

Recently uploaded

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 

Nondeterministic Finite Automata AFN.pdf

  • 2. 2 Nondeterminism A nondeterministic finite automaton has the ability to be in several states at once. Transitions from a state on an input symbol can be to any set of states.
  • 3. 3 Nondeterminism – (2) Start in one start state. Accept if any sequence of choices leads to a final state. Intuitively: the NFA always “guesses right.”
  • 4. 4 Example: Moves on a Chessboard States = squares. Inputs = r (move to an adjacent red square) and b (move to an adjacent black square). Start state, final state are in opposite corners.
  • 5. 5 Example: Chessboard – (2) 1 2 5 7 9 3 4 8 6 1 r b b 4 2 1 5 3 7 5 1 3 9 7 r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * Accept, since final state reached
  • 6. 6 Formal NFA A finite set of states, typically Q. An input alphabet, typically Σ. A transition function, typically δ. A start state in Q, typically q0. A set of final states F ⊆ Q.
  • 7. 7 Transition Function of an NFA δ(q, a) is a set of states. Extend to strings as follows: Basis: δ(q, ε) = {q} Induction: δ(q, wa) = the union over all states p in δ(q, w) of δ(p, a)
  • 8. 8 Language of an NFA A string w is accepted by an NFA if δ(q0, w) contains at least one final state. The language of the NFA is the set of strings it accepts.
  • 9. 9 Example: Language of an NFA For our chessboard NFA we saw that rbb is accepted. If the input consists of only b’s, the set of accessible states alternates between {5} and {1,3,7,9}, so only even-length, nonempty strings of b’s are accepted. What about strings with at least one r? 1 2 5 7 9 3 4 8 6
  • 10. 10 Equivalence of DFA’s, NFA’s A DFA can be turned into an NFA that accepts the same language. If δD(q, a) = p, let the NFA have δN(q, a) = {p}. Then the NFA is always in a set containing exactly one state – the state the DFA is in after reading the same input.
  • 11. 11 Equivalence – (2) Surprisingly, for any NFA there is a DFA that accepts the same language. Proof is the subset construction. The number of states of the DFA can be exponential in the number of states of the NFA. Thus, NFA’s accept exactly the regular languages.
  • 12. 12 Subset Construction Given an NFA with states Q, inputs Σ, transition function δN, state state q0, and final states F, construct equivalent DFA with:  States 2Q (Set of subsets of Q).  Inputs Σ.  Start state {q0}.  Final states = all those with a member of F.
  • 13. 13 Critical Point The DFA states have names that are sets of NFA states. But as a DFA state, an expression like {p,q} must be read as a single symbol, not as a set. Analogy: a class of objects whose values are sets of objects of another class.
  • 14. 14 Subset Construction – (2) The transition function δD is defined by: δD({q1,…,qk}, a) is the union over all i = 1,…,k of δN(qi, a). Example: We’ll construct the DFA equivalent of our “chessboard” NFA.
  • 15. 15 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} {2,4} {5} {2,4} {5} Alert: What we’re doing here is the lazy form of DFA construction, where we only construct a state if we are forced to.
  • 16. 16 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} {2,4,6,8} {5} {2,4} {2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5}
  • 17. 17 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} * {1,3,7,9} {2,4,6,8} {2,4,6,8} {1,3,7,9} {5} {2,4} {2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5}
  • 18. 18 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} * {1,3,5,7,9} * {1,3,7,9} {2,4,6,8} {1,3,5,7,9} {2,4,6,8} {2,4,6,8} {1,3,7,9} {5} {2,4} {2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5}
  • 19. 19 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} * {1,3,5,7,9} * {1,3,7,9} {2,4,6,8} {1,3,5,7,9} {2,4,6,8} {2,4,6,8} {1,3,7,9} {5} {2,4} {2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5} {2,4,6,8} {1,3,5,7,9}
  • 20. 20 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} * {1,3,5,7,9} * {1,3,7,9} {2,4,6,8} {5} {2,4,6,8} {1,3,5,7,9} {2,4,6,8} {2,4,6,8} {1,3,7,9} {5} {2,4} {2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5} {2,4,6,8} {1,3,5,7,9}
  • 21. 21 Example: Subset Construction r b 1 2,4 5 2 4,6 1,3,5 3 2,6 5 4 2,8 1,5,7 5 2,4,6,8 1,3,7,9 6 2,8 3,5,9 7 4,8 5 8 4,6 5,7,9 9 6,8 5 * r b {1} * {1,3,5,7,9} {2,4,6,8} {1,3,5,7,9} * {1,3,7,9} {2,4,6,8} {5} {2,4,6,8} {1,3,5,7,9} {2,4,6,8} {2,4,6,8} {1,3,7,9} {5} {2,4} {2,4,6,8} {1,3,5,7} {1,3,5,7} {2,4} {5} {2,4,6,8} {1,3,5,7,9}
  • 22. 22 Proof of Equivalence: Subset Construction The proof is almost a pun. Show by induction on |w| that δN(q0, w) = δD({q0}, w) Basis: w = ε: δN(q0, ε) = δD({q0}, ε) = {q0}.
  • 23. 23 Induction Assume IH for strings shorter than w. Let w = xa; IH holds for x. Let δN(q0, x) = δD({q0}, x) = S. Let T = the union over all states p in S of δN(p, a). Then δN(q0, w) = δD({q0}, w) = T.  For NFA: the extension of δN.  For DFA: definition of δD plus extension of δD. • That is, δD(S, a) = T; then extend δD to w = xa.
  • 24. 24 NFA’s With ε-Transitions We can allow state-to-state transitions on ε input. These transitions are done spontaneously, without looking at the input string. A convenience at times, but still only regular languages are accepted.
  • 25. 25 Example: ε-NFA C E F A B D 1 1 1 0 0 0 ε ε ε 0 1 ε A {E} {B} ∅ B ∅ {C} {D} C ∅ {D} ∅ D ∅ ∅ ∅ E {F} ∅ {B, C} F {D} ∅ ∅ *
  • 26. 26 Closure of States CL(q) = set of states you can reach from state q following only arcs labeled ε. Example: CL(A) = {A}; CL(E) = {B, C, D, E}. Closure of a set of states = union of the closure of each state. C E F A B D 1 1 1 0 0 0 ε ε ε
  • 27. 27 Extended Delta  Basis: (q, ε) = CL(q).  Induction: (q, xa) is computed as follows: 1. Start with (q, x) = S. 2. Take the union of CL(δ(p, a)) for all p in S.  Intuition: (q, w) is the set of states you can reach from q following a path labeled w. ˄ δ ˄ δ ˄ δ ˄ δ And notice that δ(q, a) is not that set of states, for symbol a.
  • 28. 28 Example: Extended Delta  (A, ε) = CL(A) = {A}.  (A, 0) = CL({E}) = {B, C, D, E}.  (A, 01) = CL({C, D}) = {C, D}. Language of an ε-NFA is the set of strings w such that (q0, w) contains a final state. C E F A B D 1 1 1 0 0 0 ε ε ε ˄ δ ˄ δ ˄ δ ˄ δ
  • 29. 29 Equivalence of NFA, ε-NFA Every NFA is an ε-NFA.  It just has no transitions on ε. Converse requires us to take an ε-NFA and construct an NFA that accepts the same language. We do so by combining ε–transitions with the next transition on a real input. Warning: This treatment is a bit different from that in the text.
  • 30. 30 Picture of ε-Transition Removal Transitions on ε a a a Transitions on ε
  • 31. 31 Picture of ε-Transition Removal Transitions on ε a a a Transitions on ε Text goes from here To here, and performs the subset construction
  • 32. 32 Picture of ε-Transition Removal Transitions on ε a a a Transitions on ε We’ll go from here To here, with no subset construction
  • 33. 33 Equivalence – (2) Start with an ε-NFA with states Q, inputs Σ, start state q0, final states F, and transition function δE. Construct an “ordinary” NFA with states Q, inputs Σ, start state q0, final states F’, and transition function δN.
  • 34. 34 Equivalence – (3)  Compute δN(q, a) as follows: 1. Let S = CL(q). 2. δN(q, a) is the union over all p in S of δE(p, a).  F’ = the set of states q such that CL(q) contains a state of F.  Intuition: δN incorporates ε–transitions before using a but not after.
  • 35. 35 Equivalence – (4) Prove by induction on |w| that CL(δN(q0, w)) = E(q0, w). Thus, the ε-NFA accepts w if and only if the “ordinary” NFA does. ˄ δ
  • 36. 36 Example: ε-NFA- to-NFA 0 1 ε A {E} {B} ∅ B ∅ {C} {D} C ∅ {D} ∅ D ∅ ∅ ∅ E {F} ∅ {B, C} F {D} ∅ ∅ * ε-NFA 0 1 A {E} {B} B ∅ {C} C ∅ {D} D ∅ ∅ E {F} {C, D} F {D} ∅ * * * Since closure of E includes B and C; which have transitions on 1 to C and D. Since closures of B and E include final state D. Interesting closures: CL(B) = {B,D}; CL(E) = {B,C,D,E}
  • 37. 37 Summary DFA’s, NFA’s, and ε–NFA’s all accept exactly the same set of languages: the regular languages. The NFA types are easier to design and may have exponentially fewer states than a DFA. But only a DFA can be implemented!