Compiler: Noor Wali Khan Uoch
Compiler: Noor Wali Khan Uoch
2
Non-Deterministic Finite Automata (NFA).
• Consider the FA.
• In this FA two edges
a 4
coming out of the same
state to have exactly the
3 same label.
•The two edges are leading
a 5 to the different states.
3
Non-Deterministic Finite Automata (NFA).
• When a state can make transition to more than one states on the
same input symbol, we say that this machine is nondeterministic.
• Because it cannot determine to which it should make the transition
next.
• But, a NFA (nondeterministic finite automata) is able to be in several
states at once.
• Another way to think of the NFA is that it travels all possible paths, and so it
remains in many states at once. As long as at least one of the paths results in
an accepting state, the NFA accepts the input.
4
NFA Example. 0,1
q0
1 q0
1
q0
0
1100101 q0 q2 - stuck
0
q0 q1
1
q0 q2 - accept
5
Formal Definition of FA.
Is equivalent to.
2 3 4
a a a
ε ε ε a
1 6 7 8 5
7
NFA for Sequence.
start ε a ε
1 2 3 4
8
NFA for Alternation.
• Alternation is ( a | b ).
b
start
1 2
b
ε 2 4 ε
start 1
6
ε a ε
3 5
9
NFA for Kleene Closure.
• Keleen Closure is ( a | b )*.ε
b
start 1 2
a
ε ε
b
ε 2 4 ε
start 1
6
ε a ε
3 5
ε
10