0% found this document useful (0 votes)
46 views7 pages

BCS313 L5 Non-Deterministic Finite Automata

Uploaded by

yungshifu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views7 pages

BCS313 L5 Non-Deterministic Finite Automata

Uploaded by

yungshifu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

NFA (Non-Deterministic finite automata)

o NFA stands for non-deterministic finite automata. It is easy to construct an NFA than DFA
for a given regular language.
o The finite automata are called NFA when there exist many paths for specific input from the
current state to the next state.
o Every NFA is not DFA, but each NFA can be translated into DFA.
o NFA is defined in the same way as DFA but with the following two exceptions, it contains
multiple next states, and it contains ε transition.
In the following image, we can see that from state q0 for input a, there are two next states q1
and q2, similarly, from q0 for input b, the next states are q0 and q1. Thus it is not fixed or
determined that with a particular input where to go next. Hence this FA is called non-
deterministic finite automata.

Formal definition of NFA:

NFA also has five states same as DFA, but with different transition function, as shown follows:

δ: Q x ∑ →2Q
where,

. Q: finite set of states


. ∑: finite set of the input symbol
. q0: initial state
. F: final state
. δ: Transition function

Graphical Representation of an NFA

An NFA can be represented by digraphs called state diagram. In which:

1. The state is represented by vertices.


2. The arc labeled with an input character show the transitions.
3. The initial state is marked with an arrow.
4. The final state is denoted by the double circle.

Example 1:
. Q = {q0, q1, q2}
. ∑ = {0, 1}
. q0 = {q0}
. F = {q2}
Solution:

Transition diagram:

Transition Table:

Present State Next state for Next State of


Input 0 Input 1
→q0 q0, q1 q1
q1 q2 q0
*q2 q2 q1, q2
In the above diagram, we can see that when the current state is q0, on input 0, the next state
will be q0 or q1, and on 1 input the next state will be q1. When the current state is q1, on input
0 the next state will be q2 and on 1 input, the next state will be q0. When the current state is q2,
on 0 input the next state is q2, and on 1 input the next state will be q1 or q2.

Example 2:

NFA with ∑ = {0, 1} accepts all strings with 01.

Solution:

Transition Table:

Present State Next state for Next State of


Input 0 Input 1
→q0 q1 ε
q1 ε q2
*q2 q2 q2
Example 3:

NFA with ∑ = {0, 1} and accept all string of length atleast 2.

Solution:

Transition Table:

Present State Next state for Next State of


Input 0 Input 1
→q0 q1 q1
q1 q2 q2
*q2 ε ε

Examples of NFA

Example 1:

Design a NFA for the transition table as given below:

Present State 0 1
→q0 q0, q1 q0, q2
q1 q3 ε
q2 q2, q3 q3
→q3 q3 q3
Solution:

The transition diagram can be drawn by using the mapping function as given in the table.
Here,

. δ(q0, 0) = {q0, q1}


. δ(q0, 1) = {q0, q2}
. Then, δ(q1, 0) = {q3}
. Then, δ(q2, 0) = {q2, q3}
. δ(q2, 1) = {q3}
. Then, δ(q3, 0) = {q3}
. δ(q3, 1) = {q3}

Example 2:

Design an NFA with ∑ = {0, 1} accepts all string ending with 01.

Solution:
Hence, NFA would be:

Example 3:

Design an NFA with ∑ = {0, 1} in which double '1' is followed by double '0'.

Solution:

The FA with double 1 is as follows:

Advertisement

It should be immediately followed by double 0.

Then,

Now before double 1, there can be any string of 0 and 1. Similarly, after double 0, there can be
any string of 0 and 1.

Hence the NFA becomes:

Now considering the string 01100011

. q0 → q1 → q2 → q3 → q4 → q4 → q4 → q4

Example 4:

Design an NFA in which all the string contain a substring 1110.

Solution:

Advertisement
The language consists of all the string containing substring 1010. The partial transition diagram
can be:
Now as 1010 could be the substring. Hence we will add the inputs 0's and 1's so that the
substring 1010 of the language can be maintained. Hence the NFA becomes:

Transition table for the above transition diagram can be given below:

Advertisement
Present State 0 1
→q1 q1 q1, q2
q2 q3
q3 q4
q4 q5
*q5 q5 q5
Consider a string 111010,

. δ(q1, 111010) = δ(q1, 1100)


. = δ(q1, 100)
. = δ(q2, 00)
Got stuck! As there is no path from q2 for input symbol 0. We can process string 111010 in
another way.

. δ(q1, 111010) = δ(q2, 1100)


. = δ(q3, 100)
. = δ(q4, 00)
. = δ(q5, 0)
. = δ(q5, ε)
As state q5 is the accept state. We get the complete scanned, and we reached to the final state.

Example 5:

Design an NFA with ∑ = {0, 1} accepts all string in which the third symbol from the right end
is always 0.

Solution:
Thus we get the third symbol from the right end as '0' always. The NFA can be:

The above image is an NFA because in state q0 with input 0, we can either go to state q0 or q1.

Questions
1. Create your own transition table and design an NFA from it.
2. What is Epsilon and how can it be removed from an NFA
3. Give a formal definition of NFA and show an example of its application

You might also like