SlideShare a Scribd company logo
Chapter Five:
Nondeterministic Finite Automata
From DFA to NFA
•  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.
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
Not A DFA
•  Does not have exactly one transition from
every state on every symbol:
–  Two transitions from q0 on a
–  No transition from q1 (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
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
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
NFA Example
•  This NFA accepts only
those strings that end in
01
•  Running in “parallel
threads” for string
1100101
q0Start q1 q2
0 1
0,1
q0
q0
q0
q0
q0
1
1
0
0
q1 - stuck
q0
q0
1
1
0
q0
q1
q2 - stuck
q1
q2 - accept
q0
q0
q0
q0
q0
1
1
0
0
q1 - stuck
q0
q0
1
1
0
q0
q1
q2 - stuck
q1
q2 - accept
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 computing all
legal sequences in parallel and then deterministically
search the legal sequences that accept the input,
but…
•  ...this nondeterminism does not directly correspond to
anything in physical computer systems
•  In spite of that, NFAs have many practical
applications
Nondeterminism DFA:
0
0
0
1
1
1
1
0
q0 q1
q2 q3
NFA:
0,1
0,1
1
q0 q1 q2
Now consider string: 0110
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 by considering all possible transitions in parallel.
NFA Advantage
•  An NFA for a language can be smaller and easier to construct than a
DFA
•  Let L={x ∈ {0,1}*|where x is a string whose next-to-last symbol is 1}
•  Construct both a DFA and NFA for recognizing L.
DFA:
0
0
0
1
1
1
1
0
NFA:
0,1
0,1
1
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
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
ε-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
ε-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
Revisiting Union
A = {an | n is odd}
B = {bn | n is odd}
A ∪ B
a
a
b
b
a
a
b
b
ε
ε
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
Some Exercises
What is the language accepted by the following NFAs?
a) b)
c)
•  Let Σ = {a, b, c}. Give an NFA M that accepts:
L = {x | x is in Σ* and x contains ab}
q1q0
q2
a
a,b,c
b
a,b,c
More Exercises
•  Let Σ = {a, b}. Give an NFA M that accepts:
L = {x | x is in Σ* and the third to the last symbol in x is b}
q1q0
b q3
a/b
a/b
q2
a/b
One More Exercise
NFA Exercise
•  Construct an NFA that will accept strings over
alphabet {1, 2, 3} such that the last symbol appears
at least twice, but without any intervening higher
symbol, in between:
–  e.g., 11, 2112, 123113, 3212113, etc.
•  Trick: use start state to mean “I guess I haven't seen
the symbol that matches the ending symbol yet.”
Use three other states to represent a guess that the
matching symbol has been seen, and remembers
what that symbol is.
NFA Exercise (answer)
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
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}}
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 - since multiple transitions can
happen in parallel!)
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
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
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
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 similar for NFAs taking parallel
transitions into account, but the
ε-transitions add some technical difficulties
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
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 a ∈ Σ or
a = ε,€
I  J
q,ax( )  r,x( ) if and only if r ∈ δ q,a( )
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 ∗
J
€
I    J
I ∗
I
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€
δ∗
q,x( ) = r q,x( ) ∗
r,ε( ){ }
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 by
computing all possible states by executing all
possible transitions in parallel on the string x:
A string x ∈ Σ* is accepted by an NFA M = (Q, Σ, δ, q0, F)
if and only if the set δ*(q0, x) contains at least one
element of F.
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
Exercise
•  Compute the results of
the following transitions:
–  δ*(q1,ε)
–  δ*(q1,0110)
Exercise
•  Theorem: Let M be an NFA with a single accepting
state, show how to construct the 5-tuple for a new
NFA, say N, with
L(N) = { xy | x∈ L(M) and y∈ L(M)}.
Show that the language of construct NFA is indeed
L(N) as specified.
•  Proof Idea: The idea here is to make two copies of
the NFA, linking the accepting state of the first to the
start state of the second. The accepting state of the
second copy becomes the only accepting state in the
new machine.
Assignment
•  Assignment #3 – see website

More Related Content

What's hot

Programmable PN Sequence Generators
Programmable PN Sequence GeneratorsProgrammable PN Sequence Generators
Programmable PN Sequence Generators
Rajesh Singh
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7
Dr. Maamoun Ahmed
 
Codefreeze eng
Codefreeze engCodefreeze eng
Codefreeze eng
Devexperts
 
Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)
Igalia
 
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Igalia
 
Deep speech
Deep speechDeep speech
Deep speech
Rabimba Karanjai
 
Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine
Nadeem Qasmi
 
Specifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with CryptolSpecifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with CryptolUlisses Costa
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
Muhammad Muzammal
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
Sampath Kumar S
 
RFID tag anti collision protocols
RFID tag anti collision protocolsRFID tag anti collision protocols
RFID tag anti collision protocolsArsnet
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
Inside LoLA - Experiences from building a state space tool for place transiti...
Inside LoLA - Experiences from building a state space tool for place transiti...Inside LoLA - Experiences from building a state space tool for place transiti...
Inside LoLA - Experiences from building a state space tool for place transiti...
Universität Rostock
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
Rushabh2428
 
Isola 12 presentation
Isola 12 presentationIsola 12 presentation
Isola 12 presentation
Iakovos Ouranos
 
Transformer Mods for Document Length Inputs
Transformer Mods for Document Length InputsTransformer Mods for Document Length Inputs
Transformer Mods for Document Length Inputs
Sujit Pal
 

What's hot (19)

Programmable PN Sequence Generators
Programmable PN Sequence GeneratorsProgrammable PN Sequence Generators
Programmable PN Sequence Generators
 
Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7Theory of Computation - Lectures 6 & 7
Theory of Computation - Lectures 6 & 7
 
Codefreeze eng
Codefreeze engCodefreeze eng
Codefreeze eng
 
Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)Optimizing with persistent data structures (LLVM Cauldron 2016)
Optimizing with persistent data structures (LLVM Cauldron 2016)
 
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Deep speech
Deep speechDeep speech
Deep speech
 
Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine
 
Specifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with CryptolSpecifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with Cryptol
 
Algorithmic Notations
Algorithmic NotationsAlgorithmic Notations
Algorithmic Notations
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
RFID tag anti collision protocols
RFID tag anti collision protocolsRFID tag anti collision protocols
RFID tag anti collision protocols
 
Lecture8
Lecture8Lecture8
Lecture8
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
 
Inside LoLA - Experiences from building a state space tool for place transiti...
Inside LoLA - Experiences from building a state space tool for place transiti...Inside LoLA - Experiences from building a state space tool for place transiti...
Inside LoLA - Experiences from building a state space tool for place transiti...
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
 
Isola 12 presentation
Isola 12 presentationIsola 12 presentation
Isola 12 presentation
 
Transformer Mods for Document Length Inputs
Transformer Mods for Document Length InputsTransformer Mods for Document Length Inputs
Transformer Mods for Document Length Inputs
 
Lecture set 4
Lecture set 4Lecture set 4
Lecture set 4
 

Similar to Nondeterministic Finite Automata

Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite AutomatAdel Al-Ofairi
 
Automata
AutomataAutomata
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
ranjan317165
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
amara jyothi
 
Alofairi Adel
Alofairi  AdelAlofairi  Adel
Alofairi Adel
Adel Al-Ofairi
 
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
Abdullah Jan
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
ankitamakin
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
Rushabh2428
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
parmeet834
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
Archana Gopinath
 
TOC Introduction
TOC Introduction TOC Introduction
TOC Introduction
Thapar Institute
 
Nfa egs
Nfa egsNfa egs
Nfa egs
ankitamakin
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
Meghnadh
 
@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
FariyaTasneem1
 
FiniteAutomata.ppt
FiniteAutomata.pptFiniteAutomata.ppt
FiniteAutomata.ppt
RohitPaul71
 
FiniteAutomata (1).ppt
FiniteAutomata (1).pptFiniteAutomata (1).ppt
FiniteAutomata (1).ppt
ssuser47f7f2
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdf
SergioUlisesRojasAla
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
Akila Krishnamoorthy
 
Theory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite AcceptorsTheory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite Acceptors
Rushabh2428
 
1. finite_automata_new.ppt
1. finite_automata_new.ppt1. finite_automata_new.ppt
1. finite_automata_new.ppt
SanthoshS508159
 

Similar to Nondeterministic Finite Automata (20)

Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
 
Automata
AutomataAutomata
Automata
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
Alofairi Adel
Alofairi  AdelAlofairi  Adel
Alofairi Adel
 
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
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
TOC Introduction
TOC Introduction TOC Introduction
TOC Introduction
 
Nfa egs
Nfa egsNfa egs
Nfa egs
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
@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
 
FiniteAutomata.ppt
FiniteAutomata.pptFiniteAutomata.ppt
FiniteAutomata.ppt
 
FiniteAutomata (1).ppt
FiniteAutomata (1).pptFiniteAutomata (1).ppt
FiniteAutomata (1).ppt
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdf
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Theory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite AcceptorsTheory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite Acceptors
 
1. finite_automata_new.ppt
1. finite_automata_new.ppt1. finite_automata_new.ppt
1. finite_automata_new.ppt
 

More from parmeet834

DFA
DFA DFA
Problemes chap1 toc
Problemes chap1 tocProblemes chap1 toc
Problemes chap1 toc
parmeet834
 
Hwsoln03 toc
Hwsoln03 tocHwsoln03 toc
Hwsoln03 toc
parmeet834
 
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
parmeet834
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
parmeet834
 
Graph representation of DFA’s Da
Graph representation of DFA’s DaGraph representation of DFA’s Da
Graph representation of DFA’s Da
parmeet834
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
parmeet834
 
Pushdown Automata
Pushdown AutomataPushdown Automata
Pushdown Automata
parmeet834
 
Assignment Theory of computation TOC
Assignment Theory of computation TOCAssignment Theory of computation TOC
Assignment Theory of computation TOC
parmeet834
 
5 decidability theory of computation
5 decidability theory of computation 5 decidability theory of computation
5 decidability theory of computation
parmeet834
 
Turing Machines (TM)
Turing Machines (TM)Turing Machines (TM)
Turing Machines (TM)
parmeet834
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
parmeet834
 
1 introduction
1 introduction1 introduction
1 introduction
parmeet834
 

More from parmeet834 (13)

DFA
DFA DFA
DFA
 
Problemes chap1 toc
Problemes chap1 tocProblemes chap1 toc
Problemes chap1 toc
 
Hwsoln03 toc
Hwsoln03 tocHwsoln03 toc
Hwsoln03 toc
 
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 
Graph representation of DFA’s Da
Graph representation of DFA’s DaGraph representation of DFA’s Da
Graph representation of DFA’s Da
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Pushdown Automata
Pushdown AutomataPushdown Automata
Pushdown Automata
 
Assignment Theory of computation TOC
Assignment Theory of computation TOCAssignment Theory of computation TOC
Assignment Theory of computation TOC
 
5 decidability theory of computation
5 decidability theory of computation 5 decidability theory of computation
5 decidability theory of computation
 
Turing Machines (TM)
Turing Machines (TM)Turing Machines (TM)
Turing Machines (TM)
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
1 introduction
1 introduction1 introduction
1 introduction
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

Nondeterministic Finite Automata

  • 2. From DFA to NFA •  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.
  • 3. 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. Not A DFA •  Does not have exactly one transition from every state on every symbol: –  Two transitions from q0 on a –  No transition from q1 (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. 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. 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. NFA Example •  This NFA accepts only those strings that end in 01 •  Running in “parallel threads” for string 1100101 q0Start q1 q2 0 1 0,1 q0 q0 q0 q0 q0 1 1 0 0 q1 - stuck q0 q0 1 1 0 q0 q1 q2 - stuck q1 q2 - accept q0 q0 q0 q0 q0 1 1 0 0 q1 - stuck q0 q0 1 1 0 q0 q1 q2 - stuck q1 q2 - accept
  • 8. 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 computing all legal sequences in parallel and then deterministically search the legal sequences that accept the input, but… •  ...this nondeterminism does not directly correspond to anything in physical computer systems •  In spite of that, NFAs have many practical applications
  • 9. Nondeterminism DFA: 0 0 0 1 1 1 1 0 q0 q1 q2 q3 NFA: 0,1 0,1 1 q0 q1 q2 Now consider string: 0110
  • 10. 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 by considering all possible transitions in parallel.
  • 11. NFA Advantage •  An NFA for a language can be smaller and easier to construct than a DFA •  Let L={x ∈ {0,1}*|where x is a string whose next-to-last symbol is 1} •  Construct both a DFA and NFA for recognizing L. DFA: 0 0 0 1 1 1 1 0 NFA: 0,1 0,1 1
  • 12. 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
  • 13. 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
  • 14. ε-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
  • 15. ε-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
  • 16. Revisiting Union A = {an | n is odd} B = {bn | n is odd} A ∪ B a a b b a a b b ε ε
  • 17. 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
  • 18. Some Exercises What is the language accepted by the following NFAs? a) b) c)
  • 19. •  Let Σ = {a, b, c}. Give an NFA M that accepts: L = {x | x is in Σ* and x contains ab} q1q0 q2 a a,b,c b a,b,c More Exercises
  • 20. •  Let Σ = {a, b}. Give an NFA M that accepts: L = {x | x is in Σ* and the third to the last symbol in x is b} q1q0 b q3 a/b a/b q2 a/b One More Exercise
  • 21. NFA Exercise •  Construct an NFA that will accept strings over alphabet {1, 2, 3} such that the last symbol appears at least twice, but without any intervening higher symbol, in between: –  e.g., 11, 2112, 123113, 3212113, etc. •  Trick: use start state to mean “I guess I haven't seen the symbol that matches the ending symbol yet.” Use three other states to represent a guess that the matching symbol has been seen, and remembers what that symbol is.
  • 23. 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. 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}}
  • 25. 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 - since multiple transitions can happen in parallel!) 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
  • 26. 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
  • 27. 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
  • 28. 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 similar for NFAs taking parallel transitions into account, but the ε-transitions add some technical difficulties
  • 29. 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
  • 30. 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 a ∈ Σ or a = ε,€ I  J q,ax( )  r,x( ) if and only if r ∈ δ q,a( )
  • 31. 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 ∗ J € I    J I ∗ I
  • 32. 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€ δ∗ q,x( ) = r q,x( ) ∗ r,ε( ){ }
  • 33. 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 by computing all possible states by executing all possible transitions in parallel on the string x: A string x ∈ Σ* is accepted by an NFA M = (Q, Σ, δ, q0, F) if and only if the set δ*(q0, x) contains at least one element of F.
  • 34. 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
  • 35. Exercise •  Compute the results of the following transitions: –  δ*(q1,ε) –  δ*(q1,0110)
  • 36. Exercise •  Theorem: Let M be an NFA with a single accepting state, show how to construct the 5-tuple for a new NFA, say N, with L(N) = { xy | x∈ L(M) and y∈ L(M)}. Show that the language of construct NFA is indeed L(N) as specified. •  Proof Idea: The idea here is to make two copies of the NFA, linking the accepting state of the first to the start state of the second. The accepting state of the second copy becomes the only accepting state in the new machine.