You are on page 1of 21

Nondeterministic Finite Automaton

(NFA)
Definition: An NFA is a TG with a unique start
state and a property of having single letter as
label of transitions. An NFA is a collection of
three things
1) Finite many states with one initial and some
final states
2) Finite set of input letters, say, ={a, b, c}
3) Finite set of transitions, showing where to
move if a letter is input at certain state ( is
not a valid transition), there may be more
than one transition for certain letters and
there may not be any transition for certain
letters. 1
Observations

It may be observed, from the definition of


NFA, that the string is supposed to be
accepted, if there exists at least one
successful path, otherwise rejected.
It is to be noted that an NFA can be
considered to be an intermediate structure
between FA and TG.
The examples of NFAs can be found in the
following
2
Example

2+
a

1- a
3

a
b
4 5+

It is to be noted that the above NFA accepts the language consisting of a and
ab.

3
Example

a, b a,b

a a
1- 2 3+
It is to be noted that the above NFA accepts the language of strings, defined
over Σ = {a, b}, containing aa.

4
Note

► It is to be noted that NFA helps to eliminate a


loop at certain state of an FA. This process is
done converting the loop into a circuit. But
during this process the FA remains no longer FA
and is converted to a corresponding NFA, which
is shown in the following example.

5
Example

► Consider a part of the following FA with an


alphabet Σ={a,b,c,d}

… 4 8 …
a a b

… 5 b c 9
7 …
c d
… 6 10 …
To eliminate the loop at state 7, the 6

corresponding NFA may be as follows


Example continued ...

… 4 b …
11 8
a c
d
… 5 a a …
9
b b
c
… 6 c 7 d 10 …

7
Converting an FA to an equivalent NFA

► It is to be noted that according to the


Kleene’s theorem, if a language can be
accepted by an FA, then there exists a TG
accepting that language. Since, an NFA is a
TG as well, therefore there exists an NFA
accepting the language accepted by the
given FA. In this case these FA and NFA are
said to be equivalent to each others.
Following are the examples of FAs to be
converted to the equivalent NFAs
8
Example

► Consider the following FA corresponding to


*
(a+b) b
a b b

- +
a
► The above FA may be equivalent to the
following NFA
a, b

Can the structure of mentioned NFA be compared - b +


with the corresponding RE ?
9
Example

► Consider the following FA


b a,b
a
a
- 1 +
b
► The above FA may be equivalent to the following
NFA
a, b a,b
a a
- 1 +
► Can the structure of above NFA be compared with
the corresponding RE ?
10
NFA to FA
Method 1: Since in an NFA, there more than
one transition for a certain letter and there
may not be any transition for certain letter,
so starting from the initial state
corresponding to the initial state of given
NFA, the transition diagram of the
corresponding FA, can be built introducing an
empty state for a letter having no transition
at certain state and a state corresponding to
the combination of states, for a letter having
more than one transitions. Following are the
examples

11
Example

Consider the following NFA


2
a b

1- 4+

b a
3
Using the method discussed earlier, the above
NFA may be equivalent to the following FA
12
Example Continued ...
2
a b

1- 4+
b a

3 1- a
2
b

b 4+ a
a a, b

3 b
D
13
a, b
Example

► A simple NFA that accepts the language of


strings defined over ={a,b}, consists of bb
and bbb
b

b b b
1- 2 3 4+

► The above NFA can be converted to the


following FA
14
Example Continued ...
b

b b b
1- 2 3 4+

b b b
1- 2 (3,4)+ 4+

a a a a,b

D
15

a, b
Task

► Build an FA corresponding to the following


NFA which accepts the language of strings
containing bb
a, b a, b

b b
1- 2 3+

16
Solution of the Task

a, b a, b

b b
1- 2 3+

b a
a b a

1- (1,2) b (1,2,3) (1,3)+


a + b

It may be noted that the above method


seems to be complicated, hence an easier
method discussed by Martin, follows as 17
NFA to FA continued …

Method 2:
As discussed earlier that in an NFA, there may
be more than one transition for a certain letter
and there may not be any transition for certain
letter, so starting from the initial state
corresponding to the initial state of given NFA,
the transition table along with new labels of
states, of the corresponding FA, can be built
introducing an empty state for a letter having no
transition at certain state and a state
corresponding to the combination of states, for a
letter having more than one transitions.
Following are the examples

18
Example

► Consider the following NFA which accepts


the language of strings containing bb
a, b a, b

b b
x - x x +
1 2 3
Using the method discussed earlier, the transition table corresponding to
the required FA may be constructed as

19
Example continued …

New States after reading


Old States
a b
z1>x1 x1>z1 (x1,x2) >z2
z2> (x1,x2) (x1 , D) >x1>z1 (x1 ,x2,x3) >z3
z3+> (x1,x2,x3) (x1,x3) >z4 (x1 ,x2,x3) >z3
z4+> (x1,x3) (x1,x3) >z4 (x1 ,x2,x3) >z3

The corresponding transition diagram follows as 20


Example continued …

b a
a b a

z - b
z z + z +
1 a 2 3 b 4

21

You might also like