NFAs and Transition Graphs
Lecture 5
Deterministic FA (DFA)
• The FAs that we have studied so far are
DFA in that
– At every state there is exactly one outgoing
transition for a character and the machine can
follow the transition deterministically
• No duplicates
• No missing edges
Nondeterministic Finite Automata
• The FA where a state can have more than
one transition for the same character. This
puts the machine in an indecisive state for
which transition to follow
– Has duplicate transitions
– Can miss transitions for some characters
Nondeterministic Finite Automata
• In particular, every DFA is also an NFA.
• But Every NFA is not an DFA.
• NFAs have been generalized in multiple
ways, e.g nondeterministic finite
automaton with ε-moves....
NFA
• Reduces number of states and transitions
• Costly execution
– Needs concurrent processing to find a successful path
• An NFA can have a successful and unsuccessful
path for the same input
• If an NFA has at least one successful path for an
input it is considered to be valid
• Machine crashes for an undefined transition thus
causing implicit reject
NFA Language recognition
• Acceptance
– If at least one successful path exists
• Rejection
– Either machine crashes on input
– No successful path exists
NFA
Alphabet = {a}
q1 a q2
a
Start
q0
a
q3
Example: Accepting
a a
q1 a q2
a
Start
q0
a
q3
Example: Accepting
a a
First choice q1 a q2
a
Start
q0
a
Parallel Processing
Second choice q3
Example: Accepting
a a
q1 a q2
a
Start
q0
a
q3 No transition so
leave it
Example: Accepting
a a
q1 a q2 Since there is no more
symbol to read and
a it is an accepting state
Therefore, the
NFA will “Accept”
Start
q0
a
q3
Example: Rejecting
a a a
q1 a q2
a
Start
q0
a
q3
Example: Rejecting
a a a
q1 a q2
a
Start
q0
a
q3
Example: Rejecting
a a a
q1 a q2
a
Start
q0
a
q3 No transition
Example: Rejecting
a a a
q1 a q2 No transition so leave
the state
a
Start
q0 Since there is no current
a state or accepting state
therefore, NFA will “Reject”
q3 the input string.
Language of the NFA
L {aa}
q1 a q2
a
Start
q0
a
q3
Epsilon Transitions
• ε- Transitions
• A null transition that changes state but
doesn’t consume any character
• Possible with NFAs and Transition Graphs
(discussed next)
NFA with ε Transition
Alphabet(0,1)
if the input contains an even number of 0s or an even
number of 1s.
•Note that 0 occurrences is an even number of occurrences as well.
NFA with ε Transition
Transition Table
Examples
1.All words that start with a double letter
2.All words that start and end with a double
letter
3.All words that do not start with a double letter
4.All words in which is the second letter is b
Transition Graphs
• Relaxed input conditions
• Can read multiple characters
• Thus every edge can be labeled with a
substring instead of a single character
• Can have multiple start states
Transition Graphs
• Examples
– All words that start and end with a double letter
(aa+bb)(a+b)*(aa+bb)
a,b
aa,bb
-1 2
aa,bb
+3
Examples
WHY?
• The arc from state 1 to state 2 is labeled with the
string aa, which is not a single letter.
• There is no arc leaving state 2 labeled with a.
• There is an arc from state 1 to state 3 labeled with
null , which is not a letter from .
• There is no arc leaving state 3 labeled with b.
So this is not an FA Machine.
Examples
(a+b)*(aa+bb)(a+b)*
(aaa+bbbb+nul)
No
Transition Graphs
• Examples
– All words that have at least one double letter in
them
– All words that begin and end with different
letters
– All words in which a occurs only in even
clumps and that end in three or more bs
– All words that have even number of letters
Generalized Transition Graphs
• A variation of TG
• A generalized transition graph is a collection of
three things
– A finite set of states, of which at least one is a start
state and some (may be none) are final states
– An alphabet of input letters
– Directed edges connecting some pairs of states
each labeled with a regular expression
Example
Generalized Transition Graphs
a*(ba+a)*(b+ Λ)a*
a* a*
(ba +a)* (b + Λ)
-1 2 +3
GTGs
• Examples
– All words having even number of as and bs
– All words that start with ab
– All words having as in clumps of even numbers
and end at one or more bs