SlideShare a Scribd company logo
1 of 30
Formal Language, chapter 5, slide 1 Copyright © 2007 by Adam Webber
Chapter Five:
Nondeterministic Finite Automata
AL-ofairi Adel Ahmed
Formal Language, chapter 5, slide 2 Copyright © 2007 by Adam Webber
A DFA has exactly one transition from every state on every
symbol in the alphabet. By relaxing this requirement we get
a related but more flexible kind of automaton: the
nondeterministic finite automaton or NFA.
NFAs are a bit harder to think about than DFAs, because
they do not appear to define simple computational processes.
They may seem at first to be unnatural, like puzzles invented
by professors for the torment of students. But have patience!
NFAs and other kinds of nondeterministic automata arise
naturally in many ways, as you will see later in this book,
and they too have a variety of practical applications.
Formal Language, chapter 5, slide 3 Copyright © 2007 by Adam Webber
Outline
• 5.1 Relaxing a Requirement
• 5.2 Spontaneous Transitions
• 5.3 Nondeterminism
• 5.4 The 5-Tuple for an NFA
• 5.5 The Language Accepted by an NFA
Formal Language, chapter 5, slide 4 Copyright © 2007 by Adam Webber
Not A DFA
• Does not have exactly one transition from
every state on every symbol:
– Two transitions from q0 on a
– No transition from q0 (on either a or b)
• Though not a DFA, this can be taken as
defining a language, in a slightly different way
q1
a,b
q0
a
Formal Language, chapter 5, slide 5 Copyright © 2007 by Adam Webber
Possible Sequences of Moves
• We'll consider all possible sequences of moves the machine
might make for a given string
• For example, on the string aa there are three:
– From q0 to q0 to q0, rejecting
– From q0 to q0 to q1, accepting
– From q0 to q1, getting stuck on the last a
• Our convention for this new kind of machine: a string is in L(M) if
there is at least one accepting sequence
q1
a,b
q0
a
Formal Language, chapter 5, slide 6 Copyright © 2007 by Adam Webber
Nondeterministic Finite
Automaton (NFA)
• L(M) = the set of strings that have at least one accepting
sequence
• In the example above, L(M) = {xa | x ∈ {a,b}*}
• A DFA is a special case of an NFA:
– An NFA that happens to be deterministic: there is exactly one
transition from every state on every symbol
– So there is exactly one possible sequence for every string
• NFA is not necessarily deterministic
q1
a,b
q0
a
Formal Language, chapter 5, slide 7 Copyright © 2007 by Adam Webber
NFA Advantage
• An NFA for a language can be smaller and easier to construct
than a DFA
• Strings whose next-to-last symbol is 1:
DFA:
NFA:
0
0
0
1
1
1
1
0
0,1
0,1
1
Formal Language, chapter 5, slide 8 Copyright © 2007 by Adam Webber
Outline
• 5.1 Relaxing a Requirement
• 5.2 Spontaneous Transitions
• 5.3 Nondeterminism
• 5.4 The 5-Tuple for an NFA
• 5.5 The Language Accepted by an NFA
Formal Language, chapter 5, slide 9 Copyright © 2007 by Adam Webber
Spontaneous Transitions
• An NFA can make a state transition
spontaneously, without consuming an input
symbol
• Shown as an arrow labeled with ε
• For example, {a}* ∪ {b}*:
q0
aq1
q2 b
Formal Language, chapter 5, slide 10 Copyright © 2007 by Adam Webber
ε-Transitions To Accepting States
• An ε-transition can be made at any time
• For example, there are three sequences on the empty string
– No moves, ending in q0, rejecting
– From q0 to q1, accepting
– From q0 to q2, accepting
• Any state with an ε-transition to an accepting state ends up
working like an accepting state too
q0
aq1
q2 b
Formal Language, chapter 5, slide 11 Copyright © 2007 by Adam Webber
ε-transitions For NFA Combining
∀ε-transitions are useful for combining smaller
automata into larger ones
• This machine is combines a machine for {a}*
and a machine for {b}*
• It uses an ε-transition at the start to achieve
the union of the two languages
q0
aq1
q2 b
Formal Language, chapter 5, slide 12 Copyright © 2007 by Adam Webber
Incorrect Union
A = {an
| n is odd}
B = {bn
| n is odd}
A ∪ B ?
No: this NFA accepts aab
a
a
b
b
a
a
b
b
Formal Language, chapter 5, slide 13 Copyright © 2007 by Adam Webber
Correct Union
A = {an
| n is odd}
B = {bn
| n is odd}
A ∪ B
a
a
b
b
a
a
b
b
Formal Language, chapter 5, slide 14 Copyright © 2007 by Adam Webber
Incorrect Concatenation
A = {an
| n is odd}
B = {bn
| n is odd}
{xy | x ∈ A and y ∈ B} ?
No: this NFA accepts abbaab
a
a
b
b
a
a
b
b
Formal Language, chapter 5, slide 15 Copyright © 2007 by Adam Webber
Correct Concatenation
A = {an
| n is odd}
B = {bn
| n is odd}
{xy | x ∈ A and y ∈ B}
a
a
b
b
a
a
b
b
Formal Language, chapter 5, slide 16 Copyright © 2007 by Adam Webber
Outline
• 5.1 Relaxing a Requirement
• 5.2 Spontaneous Transitions
• 5.3 Nondeterminism
• 5.4 The 5-Tuple for an NFA
• 5.5 The Language Accepted by an NFA
Formal Language, chapter 5, slide 17 Copyright © 2007 by Adam Webber
DFAs and NFAs
• DFAs and NFAs both define languages
• DFAs do it by giving a simple computational procedure for
deciding language membership:
– Start in the start state
– Make one transition on each symbol in the string
– See if the final state is accepting
• NFAs do it without such a clear-cut procedure:
– Search all legal sequences of transitions on the input string?
– How? In what order?
Formal Language, chapter 5, slide 18 Copyright © 2007 by Adam Webber
Nondeterminism
• The essence of nondeterminism:
– For a given input there can be more than one legal
sequence of steps
– The input is in the language if at least one of the legal
sequences says so
• We can achieve the same result by deterministically
searching the legal sequences, but…
• ...this nondeterminism does not directly correspond to
anything in physical computer systems
• In spite of that, NFAs have many practical
applications
Formal Language, chapter 5, slide 19 Copyright © 2007 by Adam Webber
Outline
• 5.1 Relaxing a Requirement
• 5.2 Spontaneous Transitions
• 5.3 Nondeterminism
• 5.4 The 5-Tuple for an NFA
• 5.5 The Language Accepted by an NFA
Formal Language, chapter 5, slide 20 Copyright © 2007 by Adam Webber
Powerset
• If S is a set, the powerset of S is the set of all subsets of S:
P(S) = {R | R ⊆ S}
• This always includes the empty set and S itself
• For example,
P({1,2,3}) = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}
Formal Language, chapter 5, slide 21 Copyright © 2007 by Adam Webber
The 5-Tuple
• The only change from a DFA is the transition function δ
∀δ takes two inputs:
– A state from Q (the current state)
– A symbol from Σ∪{ε} (the next input, or ε for an ε-transition)
∀δ produces one output:
– A subset of Q (the set of possible next states)
An NFA M is a 5-tuple M = (Q, Σ, δ, q0, F), where:
Q is the finite set of states
Σ is the alphabet (that is, a finite set of symbols)
δ ∈ (Q × (Σ∪{ε}) → P(Q)) is the transition function
q0 ∈ Q is the start state
F ⊆ Q is the set of accepting states
Formal Language, chapter 5, slide 22 Copyright © 2007 by Adam Webber
Example:
• Formally, M = (Q, Σ, δ, q0, F), where
– Q = {q0,q1,q2}
Σ = {a,b} (we assume: it must contain at least a and b)
– F = {q2}
δ(q0,a) = {q0,q1}, δ(q0,b) = {q0}, δ(q0,ε) = {q2},
δ(q1,a) = {}, δ(q1,b) = {q2}, δ(q1,ε) = {}
δ(q2,a) = {}, δ(q2,b) = {}, δ(q2,ε) = {}
• The language defined is {a,b}*
q0 q1
a
q2
b
a,b
Formal Language, chapter 5, slide 23 Copyright © 2007 by Adam Webber
Outline
• 5.1 Relaxing a Requirement
• 5.2 Spontaneous Transitions
• 5.3 Nondeterminism
• 5.4 The 5-Tuple for an NFA
• 5.5 The Language Accepted by an NFA
Formal Language, chapter 5, slide 24 Copyright © 2007 by Adam Webber
The δ* Function
• The δ function gives 1-symbol moves
• We'll define δ* so it gives whole-string results
(by applying zero or more δ moves)
• For DFAs, we used this recursive definition
δ*(q,ε) = q
δ*(q,xa) = δ(δ*(q,x),a)
• The intuition is the similar for NFAs, but the
ε-transitions add some technical hair
Formal Language, chapter 5, slide 25 Copyright © 2007 by Adam Webber
NFA IDs
• An instantaneous description (ID) is a
description of a point in an NFA's execution
• It is a pair (q,x) where
– q ∈ Q is the current state
– x ∈ Σ* is the unread part of the input
• Initially, an NFA processing a string x has the
ID (q0,x)
• An accepting sequence of moves ends in an
ID (f,ε) for some accepting state f ∈ F
Formal Language, chapter 5, slide 26 Copyright © 2007 by Adam Webber
The One-Move Relation On IDs
• We write
if I is an ID and J is an ID that could follow
from I after one move of the NFA
• That is, for any string x ∈ Σ* and any ω ∈ Σ
or ω = ε,
I a J
q,ωx( )a r ,x()if and only if r ∈δq,w( )
Formal Language, chapter 5, slide 27 Copyright © 2007 by Adam Webber
The Zero-Or-More-Move Relation
• We write
if there is a sequence of zero or more moves
that starts with I and ends with J:
• Because it allows zero moves, it is a reflexive
relation: for all IDs I,
I a∗
J
I a L a J
I a∗
I
Formal Language, chapter 5, slide 28 Copyright © 2007 by Adam Webber
The δ* Function
• Now we can define the δ* function for NFAs:
• Intuitively, δ*(q,x) is the set of all states the
NFA might be in after starting in state q and
reading x
• Our definition allows ε-transitions, including
those made before the first symbol of x is
read, and those made after the last
δ∗
q,x( )=r q,x( )a∗
r,ε( ){ }
Formal Language, chapter 5, slide 29 Copyright © 2007 by Adam Webber
M Accepts x
• Now δ*(q,x) is the set of states M may end in,
starting from state q and reading all of string x
• So δ*(q0,x) tells us whether M accepts x:
A string x ∈ Σ* is accepted by an NFA M = (Q, Σ, δ, q0, F)
if and only if δ*(q0, x) contains at least one element of F.
Formal Language, chapter 5, slide 30 Copyright © 2007 by Adam Webber
For any NFA M = (Q, Σ, δ, q0, F), L(M) denotes
the language accepted by M, which is
L(M) = {x ∈ Σ* | δ*(q0, x) ∩ F ≠ {}}.
The Language An NFA Defines

More Related Content

What's hot

Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languagesparmeet834
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata TheorySaifur Rahman
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESsuthi
 
context free language
context free languagecontext free language
context free languagekhush_boo31
 
Theory of computing
Theory of computingTheory of computing
Theory of computingRanjan Kumar
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)Naman Joshi
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
Non regular languages
Non regular languagesNon regular languages
Non regular languageslavishka_anuj
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Simplification of cfg ppt
Simplification of cfg pptSimplification of cfg ppt
Simplification of cfg pptShiela Rani
 
Nfa(non deterministic finite automata)
Nfa(non deterministic finite automata)Nfa(non deterministic finite automata)
Nfa(non deterministic finite automata)Dr. ABHISHEK K PANDEY
 

What's hot (20)

Finite automata
Finite automataFinite automata
Finite automata
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata Theory
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
context free language
context free languagecontext free language
context free language
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Finite automata(For college Seminars)
Finite automata(For college Seminars)Finite automata(For college Seminars)
Finite automata(For college Seminars)
 
Push down automata
Push down automataPush down automata
Push down automata
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
 
Non regular languages
Non regular languagesNon regular languages
Non regular languages
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Simplification of cfg ppt
Simplification of cfg pptSimplification of cfg ppt
Simplification of cfg ppt
 
Nfa(non deterministic finite automata)
Nfa(non deterministic finite automata)Nfa(non deterministic finite automata)
Nfa(non deterministic finite automata)
 

Viewers also liked

Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite AutomatAdel Al-Ofairi
 
Nfa presentation
Nfa presentationNfa presentation
Nfa presentationannholtz
 
Nfa presentation
Nfa presentationNfa presentation
Nfa presentationannholtz
 
Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...
Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...
Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...Farwa Ansari
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,8neutron8
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfadeepinderbedi
 
Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1Abhimanyu Mishra
 
Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...
Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...
Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...Eugen Glavan
 
Model Organism Linked Data
Model Organism Linked DataModel Organism Linked Data
Model Organism Linked DataMichel Dumontier
 
iPhone and Appstore
iPhone and AppstoreiPhone and Appstore
iPhone and AppstoreHome
 
Android Bootcamp Santa Fe GTUG
Android Bootcamp Santa Fe GTUGAndroid Bootcamp Santa Fe GTUG
Android Bootcamp Santa Fe GTUGmatiasmolinas
 
Wicked Wiki
Wicked WikiWicked Wiki
Wicked Wikijactlc
 

Viewers also liked (20)

Finite automata
Finite automataFinite automata
Finite automata
 
Deterministic Finite Automata
Deterministic Finite AutomataDeterministic Finite Automata
Deterministic Finite Automata
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
 
1.1
1.11.1
1.1
 
Nfa presentation
Nfa presentationNfa presentation
Nfa presentation
 
Nfa presentation
Nfa presentationNfa presentation
Nfa presentation
 
Finite automata
Finite automataFinite automata
Finite automata
 
Syntax
SyntaxSyntax
Syntax
 
Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...
Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...
Introduction to Computer theory (Automata Theory) 2nd Edition By Denial I.A. ...
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
 
Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1Theory of Automata and formal languages unit 1
Theory of Automata and formal languages unit 1
 
Minimizing DFA
Minimizing DFAMinimizing DFA
Minimizing DFA
 
Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...
Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...
Scientific Literacy, Attitudes towards Science, Religiosity and Superstitious...
 
Model Organism Linked Data
Model Organism Linked DataModel Organism Linked Data
Model Organism Linked Data
 
Fig geometricz
Fig geometriczFig geometricz
Fig geometricz
 
iPhone and Appstore
iPhone and AppstoreiPhone and Appstore
iPhone and Appstore
 
Android Bootcamp Santa Fe GTUG
Android Bootcamp Santa Fe GTUGAndroid Bootcamp Santa Fe GTUG
Android Bootcamp Santa Fe GTUG
 
Wicked Wiki
Wicked WikiWicked Wiki
Wicked Wiki
 
Collaborate
CollaborateCollaborate
Collaborate
 

Similar to Nondeterministic Finite Automata

Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata parmeet834
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Dr. Maamoun Ahmed
 
MidtermI-review.pptx
MidtermI-review.pptxMidtermI-review.pptx
MidtermI-review.pptxamara jyothi
 
CS911-Lecture-13_34826.pptx
CS911-Lecture-13_34826.pptxCS911-Lecture-13_34826.pptx
CS911-Lecture-13_34826.pptxALIZAIB KHAN
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computationprasadmvreddy
 
Finite Automata
Finite AutomataFinite Automata
Finite Automataparmeet834
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfSergioUlisesRojasAla
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauagesdanhumble
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaRushabh2428
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyserArchana Gopinath
 
Chapter 2 limits of DFA NDFA.ppt
Chapter 2  limits of DFA  NDFA.pptChapter 2  limits of DFA  NDFA.ppt
Chapter 2 limits of DFA NDFA.pptArwaKhallouf
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysisDattatray Gandhmal
 
NFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition DiagramNFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition DiagramAbdullah Jan
 
Resumen material MIT
Resumen material MITResumen material MIT
Resumen material MITRawel Luciano
 
deterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdfdeterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdfAmayJaiswal4
 

Similar to Nondeterministic Finite Automata (20)

Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7
 
MidtermI-review.pptx
MidtermI-review.pptxMidtermI-review.pptx
MidtermI-review.pptx
 
CS911-Lecture-13_34826.pptx
CS911-Lecture-13_34826.pptxCS911-Lecture-13_34826.pptx
CS911-Lecture-13_34826.pptx
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdf
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
SS UI Lecture 6
SS UI Lecture 6SS UI Lecture 6
SS UI Lecture 6
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Automata
AutomataAutomata
Automata
 
Chapter 2 limits of DFA NDFA.ppt
Chapter 2  limits of DFA  NDFA.pptChapter 2  limits of DFA  NDFA.ppt
Chapter 2 limits of DFA NDFA.ppt
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
NFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition DiagramNFA Converted to DFA , Minimization of DFA , Transition Diagram
NFA Converted to DFA , Minimization of DFA , Transition Diagram
 
Resumen material MIT
Resumen material MITResumen material MIT
Resumen material MIT
 
deterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdfdeterministicfiniteautomatondfa-181008145215 (1).pdf
deterministicfiniteautomatondfa-181008145215 (1).pdf
 
Final fa part1
Final fa part1Final fa part1
Final fa part1
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Nondeterministic Finite Automata

  • 1. Formal Language, chapter 5, slide 1 Copyright © 2007 by Adam Webber Chapter Five: Nondeterministic Finite Automata AL-ofairi Adel Ahmed
  • 2. Formal Language, chapter 5, slide 2 Copyright © 2007 by Adam Webber A DFA has exactly one transition from every state on every symbol in the alphabet. By relaxing this requirement we get a related but more flexible kind of automaton: the nondeterministic finite automaton or NFA. NFAs are a bit harder to think about than DFAs, because they do not appear to define simple computational processes. They may seem at first to be unnatural, like puzzles invented by professors for the torment of students. But have patience! NFAs and other kinds of nondeterministic automata arise naturally in many ways, as you will see later in this book, and they too have a variety of practical applications.
  • 3. Formal Language, chapter 5, slide 3 Copyright © 2007 by Adam Webber Outline • 5.1 Relaxing a Requirement • 5.2 Spontaneous Transitions • 5.3 Nondeterminism • 5.4 The 5-Tuple for an NFA • 5.5 The Language Accepted by an NFA
  • 4. Formal Language, chapter 5, slide 4 Copyright © 2007 by Adam Webber Not A DFA • Does not have exactly one transition from every state on every symbol: – Two transitions from q0 on a – No transition from q0 (on either a or b) • Though not a DFA, this can be taken as defining a language, in a slightly different way q1 a,b q0 a
  • 5. Formal Language, chapter 5, slide 5 Copyright © 2007 by Adam Webber Possible Sequences of Moves • We'll consider all possible sequences of moves the machine might make for a given string • For example, on the string aa there are three: – From q0 to q0 to q0, rejecting – From q0 to q0 to q1, accepting – From q0 to q1, getting stuck on the last a • Our convention for this new kind of machine: a string is in L(M) if there is at least one accepting sequence q1 a,b q0 a
  • 6. Formal Language, chapter 5, slide 6 Copyright © 2007 by Adam Webber Nondeterministic Finite Automaton (NFA) • L(M) = the set of strings that have at least one accepting sequence • In the example above, L(M) = {xa | x ∈ {a,b}*} • A DFA is a special case of an NFA: – An NFA that happens to be deterministic: there is exactly one transition from every state on every symbol – So there is exactly one possible sequence for every string • NFA is not necessarily deterministic q1 a,b q0 a
  • 7. Formal Language, chapter 5, slide 7 Copyright © 2007 by Adam Webber NFA Advantage • An NFA for a language can be smaller and easier to construct than a DFA • Strings whose next-to-last symbol is 1: DFA: NFA: 0 0 0 1 1 1 1 0 0,1 0,1 1
  • 8. Formal Language, chapter 5, slide 8 Copyright © 2007 by Adam Webber Outline • 5.1 Relaxing a Requirement • 5.2 Spontaneous Transitions • 5.3 Nondeterminism • 5.4 The 5-Tuple for an NFA • 5.5 The Language Accepted by an NFA
  • 9. Formal Language, chapter 5, slide 9 Copyright © 2007 by Adam Webber Spontaneous Transitions • An NFA can make a state transition spontaneously, without consuming an input symbol • Shown as an arrow labeled with ε • For example, {a}* ∪ {b}*: q0 aq1 q2 b
  • 10. Formal Language, chapter 5, slide 10 Copyright © 2007 by Adam Webber ε-Transitions To Accepting States • An ε-transition can be made at any time • For example, there are three sequences on the empty string – No moves, ending in q0, rejecting – From q0 to q1, accepting – From q0 to q2, accepting • Any state with an ε-transition to an accepting state ends up working like an accepting state too q0 aq1 q2 b
  • 11. Formal Language, chapter 5, slide 11 Copyright © 2007 by Adam Webber ε-transitions For NFA Combining ∀ε-transitions are useful for combining smaller automata into larger ones • This machine is combines a machine for {a}* and a machine for {b}* • It uses an ε-transition at the start to achieve the union of the two languages q0 aq1 q2 b
  • 12. Formal Language, chapter 5, slide 12 Copyright © 2007 by Adam Webber Incorrect Union A = {an | n is odd} B = {bn | n is odd} A ∪ B ? No: this NFA accepts aab a a b b a a b b
  • 13. Formal Language, chapter 5, slide 13 Copyright © 2007 by Adam Webber Correct Union A = {an | n is odd} B = {bn | n is odd} A ∪ B a a b b a a b b
  • 14. Formal Language, chapter 5, slide 14 Copyright © 2007 by Adam Webber Incorrect Concatenation A = {an | n is odd} B = {bn | n is odd} {xy | x ∈ A and y ∈ B} ? No: this NFA accepts abbaab a a b b a a b b
  • 15. Formal Language, chapter 5, slide 15 Copyright © 2007 by Adam Webber Correct Concatenation A = {an | n is odd} B = {bn | n is odd} {xy | x ∈ A and y ∈ B} a a b b a a b b
  • 16. Formal Language, chapter 5, slide 16 Copyright © 2007 by Adam Webber Outline • 5.1 Relaxing a Requirement • 5.2 Spontaneous Transitions • 5.3 Nondeterminism • 5.4 The 5-Tuple for an NFA • 5.5 The Language Accepted by an NFA
  • 17. Formal Language, chapter 5, slide 17 Copyright © 2007 by Adam Webber DFAs and NFAs • DFAs and NFAs both define languages • DFAs do it by giving a simple computational procedure for deciding language membership: – Start in the start state – Make one transition on each symbol in the string – See if the final state is accepting • NFAs do it without such a clear-cut procedure: – Search all legal sequences of transitions on the input string? – How? In what order?
  • 18. Formal Language, chapter 5, slide 18 Copyright © 2007 by Adam Webber Nondeterminism • The essence of nondeterminism: – For a given input there can be more than one legal sequence of steps – The input is in the language if at least one of the legal sequences says so • We can achieve the same result by deterministically searching the legal sequences, but… • ...this nondeterminism does not directly correspond to anything in physical computer systems • In spite of that, NFAs have many practical applications
  • 19. Formal Language, chapter 5, slide 19 Copyright © 2007 by Adam Webber Outline • 5.1 Relaxing a Requirement • 5.2 Spontaneous Transitions • 5.3 Nondeterminism • 5.4 The 5-Tuple for an NFA • 5.5 The Language Accepted by an NFA
  • 20. Formal Language, chapter 5, slide 20 Copyright © 2007 by Adam Webber Powerset • If S is a set, the powerset of S is the set of all subsets of S: P(S) = {R | R ⊆ S} • This always includes the empty set and S itself • For example, P({1,2,3}) = {{}, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}
  • 21. Formal Language, chapter 5, slide 21 Copyright © 2007 by Adam Webber The 5-Tuple • The only change from a DFA is the transition function δ ∀δ takes two inputs: – A state from Q (the current state) – A symbol from Σ∪{ε} (the next input, or ε for an ε-transition) ∀δ produces one output: – A subset of Q (the set of possible next states) An NFA M is a 5-tuple M = (Q, Σ, δ, q0, F), where: Q is the finite set of states Σ is the alphabet (that is, a finite set of symbols) δ ∈ (Q × (Σ∪{ε}) → P(Q)) is the transition function q0 ∈ Q is the start state F ⊆ Q is the set of accepting states
  • 22. Formal Language, chapter 5, slide 22 Copyright © 2007 by Adam Webber Example: • Formally, M = (Q, Σ, δ, q0, F), where – Q = {q0,q1,q2} Σ = {a,b} (we assume: it must contain at least a and b) – F = {q2} δ(q0,a) = {q0,q1}, δ(q0,b) = {q0}, δ(q0,ε) = {q2}, δ(q1,a) = {}, δ(q1,b) = {q2}, δ(q1,ε) = {} δ(q2,a) = {}, δ(q2,b) = {}, δ(q2,ε) = {} • The language defined is {a,b}* q0 q1 a q2 b a,b
  • 23. Formal Language, chapter 5, slide 23 Copyright © 2007 by Adam Webber Outline • 5.1 Relaxing a Requirement • 5.2 Spontaneous Transitions • 5.3 Nondeterminism • 5.4 The 5-Tuple for an NFA • 5.5 The Language Accepted by an NFA
  • 24. Formal Language, chapter 5, slide 24 Copyright © 2007 by Adam Webber The δ* Function • The δ function gives 1-symbol moves • We'll define δ* so it gives whole-string results (by applying zero or more δ moves) • For DFAs, we used this recursive definition δ*(q,ε) = q δ*(q,xa) = δ(δ*(q,x),a) • The intuition is the similar for NFAs, but the ε-transitions add some technical hair
  • 25. Formal Language, chapter 5, slide 25 Copyright © 2007 by Adam Webber NFA IDs • An instantaneous description (ID) is a description of a point in an NFA's execution • It is a pair (q,x) where – q ∈ Q is the current state – x ∈ Σ* is the unread part of the input • Initially, an NFA processing a string x has the ID (q0,x) • An accepting sequence of moves ends in an ID (f,ε) for some accepting state f ∈ F
  • 26. Formal Language, chapter 5, slide 26 Copyright © 2007 by Adam Webber The One-Move Relation On IDs • We write if I is an ID and J is an ID that could follow from I after one move of the NFA • That is, for any string x ∈ Σ* and any ω ∈ Σ or ω = ε, I a J q,ωx( )a r ,x()if and only if r ∈δq,w( )
  • 27. Formal Language, chapter 5, slide 27 Copyright © 2007 by Adam Webber The Zero-Or-More-Move Relation • We write if there is a sequence of zero or more moves that starts with I and ends with J: • Because it allows zero moves, it is a reflexive relation: for all IDs I, I a∗ J I a L a J I a∗ I
  • 28. Formal Language, chapter 5, slide 28 Copyright © 2007 by Adam Webber The δ* Function • Now we can define the δ* function for NFAs: • Intuitively, δ*(q,x) is the set of all states the NFA might be in after starting in state q and reading x • Our definition allows ε-transitions, including those made before the first symbol of x is read, and those made after the last δ∗ q,x( )=r q,x( )a∗ r,ε( ){ }
  • 29. Formal Language, chapter 5, slide 29 Copyright © 2007 by Adam Webber M Accepts x • Now δ*(q,x) is the set of states M may end in, starting from state q and reading all of string x • So δ*(q0,x) tells us whether M accepts x: A string x ∈ Σ* is accepted by an NFA M = (Q, Σ, δ, q0, F) if and only if δ*(q0, x) contains at least one element of F.
  • 30. Formal Language, chapter 5, slide 30 Copyright © 2007 by Adam Webber For any NFA M = (Q, Σ, δ, q0, F), L(M) denotes the language accepted by M, which is L(M) = {x ∈ Σ* | δ*(q0, x) ∩ F ≠ {}}. The Language An NFA Defines