Automata

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 62

Automata

The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-
acting". An automaton (Automata in plural) is an abstract self-propelled computing
device which follows a predetermined sequence of operations automatically.

Theory of automata is a theoretical branch of computer science and mathematical. It


is the study of abstract machines and the computation problems that can be solved
using these machines. The abstract machine is called the automata. The main
motivation behind developing the automata theory was to develop methods to
describe and analyse the dynamic behaviour of discrete systems.

This automaton consists of states and transitions. The State is represented


by circles, and the Transitions is represented by arrows.

Automata is the kind of machine which takes some string as input and this input goes
through a finite number of states and may enter in the final state.

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite
State Machine (FSM).

There are the basic terminologies that are important and frequently used in
automata: Ad

Symbols:

Symbols are an entity or individual objects, which can be any letter, alphabet or
any picture.

Example:
1, a, b, #

Alphabets:

Alphabets are a finite set of symbols. It is denoted by ∑.

Examples:

1. ∑ = {a, b}
2. ∑ = {A, B, C, D}
3. ∑ = {0, 1, 2}
4. ∑ = {0, 1, ....., 5]
5. ∑ = {#, β, Δ}

String:

It is a finite collection of symbols from the alphabet. The string is denoted by w.

Example 1:
If ∑ = {a, b}, various string that can be generated from ∑ are {ab, aa, aaa, bb,
bbb, ba, aba.....}.

o A string with zero occurrences of symbols is known as an empty string. It is


represented by ε.
o The number of symbols in a string w is called the length of a string. It is denoted
by |w|.

Example 2:

1. w = 010
2. Number of Sting |w| = 3

Language:

A language is a collection of appropriate string. A language which is formed


over Σ can be Finite or Infinite.

Example: 1
L1 = {Set of string of length 2}

= {aa, bb, ba, bb} Finite Language

Example: 2
L2 = {Set of all strings starts with 'a'}

= {a, aa, aaa, abb, abbb, ababb} Infinite Language

Related Terminologies
Alphabet
 Definition − An alphabet is any finite set of symbols.
 Example − ∑ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and ‘d’ are symbols.
String
 Definition − A string is a finite sequence of symbols taken from ∑.
 Example − ‘cabcad’ is a valid string on the alphabet set ∑ = {a, b, c, d}
Length of a String
 Definition − It is the number of symbols present in a string. (Denoted by |S|).
 Examples −
o If S = ‘cabcad’, |S|= 6
o If |S|= 0, it is called an empty string (Denoted by λ or ε)
Kleene Star
 Definition − The Kleene star, ∑*, is a unary operator on a set of symbols or strings, ∑, that

Representation − ∑* = ∑0 ∪ ∑1 ∪ ∑2 ∪……. where ∑p is the set of all possible strings of


gives the infinite set of all possible strings of all possible lengths over ∑ including λ.

length p.
 Example − If ∑ = {a, b}, ∑* = {λ, a, b, aa, ab, ba, bb,………..}
Kleene Closure / Plus
 Definition − The set ∑+ is the infinite set of all possible strings of all possible lengths over ∑

Representation − ∑+ = ∑1 ∪ ∑2 ∪ ∑3 ∪…….
excluding λ.

∑+ = ∑* − { λ }
 Example − If ∑ = { a, b } , ∑+ = { a, b, aa, ab, ba, bb,………..}
Language
 Definition − A language is a subset of ∑* for some alphabet ∑. It can be finite or infinite.
 Example − If the language takes all possible strings of length 2 over ∑ = {a, b}, then L =
{ ab, aa, ba, bb }

Finite Automata
o Finite automata are used to recognize patterns.
o It takes the string of symbol as input and changes its state accordingly. When the
desired symbol is found, then the transition occurs.
o At the time of transition, the automata can either move to the next state or stay in the
same state.
o Finite automata have two states, Accept state or Reject state. When the input string is
processed successfully, and the automata reached its final state, then it will accept.

Formal Definition of FA
A finite automaton is a collection of 5-tuple (Q, ∑, δ, q0, F), where:

1. Q: finite set of states


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

Finite Automata Model:


Finite automata can be represented by input tape and finite control.

Input tape: It is a linear tape having some number of cells. Each input symbol is
placed in each cell.

Finite control: The finite control decides the next state on receiving particular input
from input tape. The tape reader reads the cells one by one from left to right, and at a
time only one input symbol is read.
Types of Automata:
There are two types of finite automata:

1. DFA(Deterministic Finite Automata)


2. NFA(Non-deterministic Finite Automata)

1. DFA

DFA refers to deterministic finite automata. Deterministic refers to the uniqueness of


the computation. In the DFA, the machine goes to one state only for a particular input
character. DFA does not accept the null move.

2. NFA

NFA stands for non-deterministic finite automata. It is used to transmit any number of
states for a particular input. It can accept the null move.

Some important points about DFA and NFA:

1. Every DFA is NFA, but NFA is not DFA.


2. There can be multiple final states in both NFA and DFA.
3. DFA is used in Lexical Analysis in Compiler.
4. NFA is more of a theoretical concept.

Transition Diagram
A transition diagram or state transition diagram is a directed graph which can be
constructed as follows:
o There is a node for each state in Q, which is represented by the circle.
o There is a directed edge from node q to node p labeled a if δ(q, a) = p.
o In the start state, there is an arrow with no source.
o Accepting states or final states are indicating by a double circle.

Some Notations that are used in the transition diagram:

There is a description of how a DFA operates:

1. In DFA, the input to the automata can be any string. Now, put a pointer to the start
state q and read the input string w from left to right and move the pointer according
to the transition function, δ. We can read one symbol at a time. If the next symbol of
string w is a and the pointer is on state p, move the pointer to δ(p, a). When the end
of the input string w is encountered, then the pointer is on some state F.

2. The string w is said to be accepted by the DFA if r ∈ F that means the input string

to be rejected by DFA if r ∉ F.
w is processed successfully and the automata reached its final state. The string is said

Example 1:
DFA with ∑ = {0, 1} accepts all strings starting with 1.

Solution:
The finite automata can be represented using a transition graph. In the above
diagram, the machine initially is in start state q0 then on receiving input 1 the
machine changes its state to q1. From q0 on receiving 0, the machine changes its
state to q2, which is the dead state. From q1 on receiving input 0, 1 the machine
changes its state to q1, which is the final state. The possible input strings that can be
generated are 10, 11, 110, 101, 111......., that means all string starts with 1.

Example 2:
NFA with ∑ = {0, 1} accepts all strings starting with 1.

Solution:

The NFA can be represented using a transition graph. In the above diagram, the
machine initially is in start state q0 then on receiving input 1 the machine changes its
state to q1. From q1 on receiving input 0, 1 the machine changes its state to q1. The
possible input string that can be generated is 10, 11, 110, 101, 111......, that means
all string starts with 1.

Transition Table
The transition table is basically a tabular representation of the transition function. It
takes two arguments (a state and a symbol) and returns a state (the "next state").

A transition table is represented by the following things:

o Columns correspond to input symbols.


o Rows correspond to states.
o Entries correspond to the next state.
o The start state is denoted by an arrow with no source.
o The accept state is denoted by a star.

Example 1:
Solution:

Transition table of given DFA is as follows:

Skip Ad

Present Next state Next


State for Input 0 State of
Input 1

→q0 q1 q2

q1 q0 q2

*q2 q2 q2

Explanation:

o In the above table, the first column indicates all the current states. Under column 0 and
1, the next states are shown.
o The first row of the transition table can be read as, when the current state is q0, on
input 0 the next state will be q1 and on input 1 the next state will be q2.
o In the second row, when the current state is q1, on input 0, the next state will be q0,
and on 1 input the next state will be q2.
o In the third row, when the current state is q2 on input 0, the next state will be q2, and
on 1 input the next state will be q2.
o The arrow marked to q0 indicates that it is a start state and circle marked to q2
indicates that it is a final state.

Example 2:
Solution:

Transition table of given NFA is as follows:

Present Next state Next State


State for Input 0 of Input 1

→q0 q0 q1

q1 q1, q2 q2

q2 q1 q3

*q3 q2 q2

Explanation:

o The first row of the transition table can be read as, when the current state is q0, on
input 0 the next state will be q0 and on input 1 the next state will be q1.
o In the second row, when the current state is q1, on input 0 the next state will be either
q1 or q2, and on 1 input the next state will be q2.
o In the third row, when the current state is q2 on input 0, the next state will be q1, and
on 1 input the next state will be q3.
o In the fourth row, when the current state is q3 on input 0, the next state will be q2, and
on 1 input the next state will be q2.

Examples of DFA
Example 1:
Design a FA with ∑ = {0, 1} accepts those string which starts with 1 and ends with 0.

Solution:

The FA will have a start state q0 from which only the edge with input 1 will go to the
next state.
In state q1, if we read 1, we will be in state q1, but if we read 0 at state q1, we will
reach to state q2 which is the final state. In state q2, if we read either 0 or 1, we will
go to q2 state or q1 state respectively. Note that if the input ends with 0, it will be in
the final state.

Example 2:
Design a FA with ∑ = {0, 1} accepts the only input 101.

Solution:

In the given solution, we can see that only input 101 will be accepted. Hence, for
input 101, there is no other path shown for other input.

Example 3:
Design FA with ∑ = {0, 1} accepts even number of 0's and even number of 1's.

Solution:

This FA will consider four different stages for input 0 and input 1. The stages could be:

Here q0 is a start state and the final state also. Note carefully that a symmetry of 0's
and 1's is maintained. We can associate meanings to each state as:

q0: state of even number of 0's and even number of 1's.


q1: state of odd number of 0's and even number of 1's.
q2: state of odd number of 0's and odd number of 1's.
q3: state of even number of 0's and odd number of 1's.

Example 4:
Design FA with ∑ = {0, 1} accepts the set of all strings with three consecutive 0's.

Solution:

The strings that will be generated for this particular languages are 000, 0001, 1000,
10001, .... in which 0 always appears in a clump of 3. The transition graph is as
follows:

Note that the sequence of triple zeros is maintained to reach the final state.

Example 5:
Design a DFA L(M) = {w | w ε {0, 1}*} and W is a string that does not contain
consecutive 1's.

Solution:

When three consecutive 1's occur the DFA will be:

Here two consecutive 1's or single 1 is acceptable, hence

The stages q0, q1, q2 are the final states. The DFA will generate the strings that do
not contain consecutive 1's like 10, 110, 101,..... etc.

Example 6:
Design a FA with ∑ = {0, 1} accepts the strings with an even number of 0's followed
by single 1.

Solution:
The DFA can be shown by a transition diagram as:

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,

1. Q: finite set of states


2. ∑: finite set of the input symbol
3. q0: initial state
4. F: final state
5. δ: 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:

1. Q = {q0, q1, q2}


2. ∑ = {0, 1}
3. q0 = {q0}
4. F = {q2}

Solution:

Transition diagram:

Transition Table:

Present State Next state for Input 0 Next State of 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 Input 0 Next State of 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 Input 0 Next State of 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,
1. δ(q0, 0) = {q0, q1}
2. δ(q0, 1) = {q0, q2}
3. Then, δ(q1, 0) = {q3}
4. Then, δ(q2, 0) = {q2, q3}
5. δ(q2, 1) = {q3}
6. Then, δ(q3, 0) = {q3}
7. δ(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:

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

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

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

Solution:

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:

Present 0 1
State

→q1 q1 q1, q2
q2 q3

q3 q4

q4 q5

*q5 q5 q5

Consider a string 111010,

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


2. = δ(q1, 100)
3. = δ(q2, 00)

Got stuck! As there is no path from q2 for input symbol 0. We can process string
111010 in another way.

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


2. = δ(q3, 100)
3. = δ(q4, 00)
4. = δ(q5, 0)
5. = δ(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.

Construction Of DFA-

In this article, we will learn the construction of DFA.

Type-01 Problems-

In Type-01 problems, we will discuss the construction of DFA for languages consisting of strings
ending with a particular substring.

Steps To Construct DFA-

Following steps are followed to construct a DFA for Type-01 problems-

Step-01:

 Determine the minimum number of states required in the DFA.


 Draw those states.

Use the following rule to determine the minimum number of states-

RULE
Calculate the length of substring.
All strings ending with ‘n’ length substring will always require minimum (n+1) states in the DFA.

Step-02:
 Decide the strings for which DFA will be constructed.

Step-03:

 Construct a DFA for the strings decided in Step-02.

Remember the following rule while constructing the DFA-

RULE
While constructing a DFA,
 Always prefer to use the existing path.
 Create a new path only when there exists no path to go with.

Step-04:

 Send all the left possible combinations to the starting state.


 Do not send the left possible combinations over the dead state.

PRACTICE PROBLEMS BASED ON CONSTRUCTION OF


DFA-

Problem-01:

Draw a DFA for the language accepting strings ending with ’01’ over input alphabets ∑ = {0, 1}

Solution-

Regular expression for the given language = (0 + 1)*01

Step-01:

 All strings of the language ends with substring “01”.


 So, length of substring = 2.

Thus, Minimum number of states required in the DFA = 2 + 1 = 3.


It suggests that minimized DFA will have 3 states.
Step-02:

We will construct DFA for the following strings-


 01
 001
 0101

Step-03:

The required DFA is-

Problem-02:

Draw a DFA for the language accepting strings ending with ‘abb’ over input alphabets ∑ = {a, b}

Solution-

Regular expression for the given language = (a + b)*abb

Step-01:

 All strings of the language ends with substring “abb”.


 So, length of substring = 3.
Thus, Minimum number of states required in the DFA = 3 + 1 = 4.
It suggests that minimized DFA will have 4 states.

Step-02:

We will construct DFA for the following strings-


 abb
 aabb
 ababb
 abbabb

Step-03:

The required DFA is-

Problem-03:

Draw a DFA for the language accepting strings ending with ‘abba’ over input alphabets ∑ = {a, b}

Solution-

Regular expression for the given language = (a + b)*abba

Step-01:

 All strings of the language ends with substring “abba”.


 So, length of substring = 4.

Thus, Minimum number of states required in the DFA = 4 + 1 = 5.


It suggests that minimized DFA will have 5 states.

Step-02:

We will construct DFA for the following strings-


 abba
 aabba
 ababba
 abbabba
 abbaabba

Step-03:

The required DFA is-

Problem-04:

Draw a DFA for the language accepting strings ending with ‘0011’ over input alphabets ∑ = {0, 1}

Solution-

Regular expression for the given language = (0 + 1)*0011


Step-01:

 All strings of the language ends with substring “0011”.


 So, length of substring = 4.

Thus, Minimum number of states required in the DFA = 4 + 1 = 5.


It suggests that minimized DFA will have 5 states.

Step-02:

We will construct DFA for the following strings-


 0011
 00011
 000011
 0010011
 00110011

Step-03:

The required DFA is-

Construction Of DFA-
Type-02 Problems-

In Type-02 problems, we will discuss the construction of DFA for languages consisting of strings
starting with a particular substring.

Steps To Construct DFA-

Following steps are followed to construct a DFA for Type-02 problems-

Step-01:

 Determine the minimum number of states required in the DFA.


 Draw those states.

Use the following rule to determine the minimum number of states-

RULE
Calculate the length of substring.
All strings starting with ‘n’ length substring will always require minimum (n+2) states in the DFA.

Step-02:

 Decide the strings for which DFA will be constructed.

Step-03:

 Construct a DFA for the strings decided in Step-02.

Remember the following rule while constructing the DFA-

RULE
While constructing a DFA,
 Always prefer to use the existing path.
 Create a new path only when there exists no path to go with.
Step-04:

 Send all the left possible combinations to the dead state.


 Do not send the left possible combinations over the starting state.

PRACTICE PROBLEMS BASED ON CONSTRUCTION


OF DFA-

Problem-01:

Draw a DFA for the language accepting strings starting with ‘ab’ over input alphabets ∑ = {a, b}

Solution-

Regular expression for the given language = ab(a + b)*

Step-01:

 All strings of the language starts with substring “ab”.


 So, length of substring = 2.

Thus, Minimum number of states required in the DFA = 2 + 2 = 4.


It suggests that minimized DFA will have 4 states.

Step-02:

We will construct DFA for the following strings-


 ab
 aba
 abab

Step-03:

The required DFA is-


Problem-02:

Draw a DFA for the language accepting strings starting with ‘a’ over input alphabets ∑ = {a, b}

Solution-

Regular expression for the given language = a(a + b)*

Step-01:

 All strings of the language starts with substring “a”.


 So, length of substring = 1.

Thus, Minimum number of states required in the DFA = 1 + 2 = 3.


It suggests that minimized DFA will have 3 states.

Step-02:

We will construct DFA for the following strings-


a
 aa
Step-03:

The required DFA is-

Problem-03:

Draw a DFA for the language accepting strings starting with ‘101’ over input alphabets ∑ = {0, 1}

Solution-

Regular expression for the given language = 101(0 + 1)*

Step-01:

 All strings of the language starts with substring “101”.


 So, length of substring = 3.

Thus, Minimum number of states required in the DFA = 3 + 2 = 5.


It suggests that minimized DFA will have 5 states.

Step-02:

We will construct DFA for the following strings-


 101
 1011
 10110
 101101

Step-03:

The required DFA is-

Problem-04:

Draw a DFA that accepts a language L over input alphabets ∑ = {0, 1} such that L is the set of all
strings starting with ’00’.

Solution-

Regular expression for the given language = 00(0 + 1)*

Step-01:

 All strings of the language starts with substring “00”.


 So, length of substring = 2.

Thus, Minimum number of states required in the DFA = 2 + 2 = 4.


It suggests that minimized DFA will have 4 states.
Step-02:

We will construct DFA for the following strings-


 00
 000
 00000

Step-03:

The required DFA is-

Problem-05:

Construct a DFA that accepts a language L over input alphabets ∑ = {a, b} such that L is the set of all
strings starting with ‘aa’ or ‘bb’.

Solution-

Regular expression for the given language = (aa + bb)(a + b)*

Step-01:
Minimum number of states required in the DFA = 5.
It suggests that minimized DFA will have 5 states.

Step-02:

We will construct DFA for the following strings-


 aa
 aaa
 aaaa
 bb
 bbb
 bbbb

Step-03:

The required DFA is-

Problem-06:

Construct a DFA that accepts a language L over input alphabets ∑ = {a, b} such that L is the set of all
strings starting with ‘aba’.

Solution-

Regular expression for the given language = aba(a + b)*


Step-01:

 All strings of the language starts with substring “aba”.


 So, length of substring = 3.

Thus, Minimum number of states required in the DFA = 3 + 2 = 5.


It suggests that minimized DFA will have 5 states.

Step-02:

We will construct DFA for the following strings-


 aba
 abaa
 abaab
 abaaba

Step-03:

The required DFA is-


DFA Examples
Example 1: Draw a DFA for the language accepting strings ending with ‘0’ over input
alphabets ∑={0, 1} ?

Solution:

Example 2: Draw a DFA for the language accepting strings ending with ‘01’ over input
alphabets ∑={0, 1} ?

Solution:

Example 3: Draw a DFA for the language accepting strings ending with ‘00’ over input
alphabets ∑={0, 1} ?
Solution:

Example 4: Draw a DFA for the language accepting strings ending with ‘011’ over
input alphabets ∑ = {0, 1} ?

Solution:

Example 5: Draw a DFA for the language accepting strings ending with ‘0110’ over
input alphabets ∑ = {0, 1} ?

Solution:

Example 6: Draw a DFA for the language accepting strings ending with ‘0011’ over
input alphabets ∑ = {0, 1} ?

Solution:
Example 7: Draw a DFA for the language accepting strings with ‘0’ only over input
alphabets ∑={0, 1} ?

Solution:

Example 8: Draw a DFA for the language accepting strings with ‘0’ and ‘1’ only over
input alphabets ∑={0, 1} ?

Solution:
Example 9: Draw a DFA for the language accepting strings starting with ‘0’ over input
alphabets ∑={0, 1} ?

Solution:

Example 10: Draw a DFA for the language accepting strings starting with ‘01’ over
input alphabets ∑={0, 1} ?

Solution:
Example 11: Draw a DFA for the language accepting strings starting with ‘00’ over
input alphabets ∑={0, 1} ?

Solution:

Example 12: Draw a DFA for the language accepting strings starting with ‘011’ over
input alphabets ∑ = {0, 1} ?

Solution:
Example 13: Draw a DFA for the language accepting strings starting with ‘0110’ over
input alphabets ∑ = {0, 1} ?

Solution:

Example 14: Draw a DFA for the language accepting strings starting with ‘0011’ over
input alphabets ∑ = {0, 1} ?

Solution:

Example 15: Draw a DFA for the language accepting strings starting with ‘00’ or ’11’
over input alphabets ∑ = {0, 1} ?

Solution:
Example 16: Draw a DFA for the language accepting strings without substring ‘00’
over input alphabets ∑ = {0, 1} ?

Solution:

Example 17: Draw a DFA for the language accepting even binary numbers strings
over input alphabets ∑ = {0, 1} ?

Soluntion:
Example 18: Draw a DFA for the language accepting odd binary numbers strings over
input alphabets ∑ = {0, 1} ?

Solution:

Example 19: Draw a DFA for the language accepting odd or even binary numbers
strings over input alphabets ∑ = {0, 1} ?

Solution:

Example 20: Draw a DFA for the language accepting strings containg even number of
total zeros over input alphabets ∑ = {0, 1} ?

Solution:
Example 21: Draw a DFA for the language accepting strings starting and ending with
different characters over input alphabets ∑ = {0, 1} ?

Soluiton:

Example 22: Draw a DFA for the language accepting strings starting and ending with
same character over input alphabets ∑ = {0, 1} ?

Solution:
Example 23: Draw a DFA for the language accepting strings starting and ending with
‘0’ always over input alphabets ∑ = {0, 1} ?

Solution:

Example 24: Draw a DFA for the language accepting strings containing three
consecutives ‘0’ always over input alphabets ∑ = {0, 1} ?

Solution:
Example 25: Draw a DFA for the language accepting strings such that each ‘0’ is
immediately preceded and followed by ‘1’ over input alphabets ∑ = {0, 1} ?

Solution:

Example 26: Draw a DFA for the language accepting strings containing at most two ‘0’
over input alphabets ∑ = {0, 1} ?

Solution:

Example 27: Draw a DFA for the language accepting strings containing at least two ‘0’
over input alphabets ∑ = {0, 1} ?

Solution:
Example 28: Draw a DFA for the language accepting strings containing exactly two ‘0’
over input alphabets ∑ = {0, 1} ?

Solution:

Example 29: Draw a DFA for the language accepting strings with ‘011’ as substring
over input alphabets ∑ = {0, 1} ?

Solution:

Example 30: Draw a DFA for the language accepting strings ending in either ’01’, or
’10’ over input alphabets ∑ = {0, 1} ?
Solution:

Example 31: Draw a DFA for the language accepting strings containing ’01’, or ’10’ as
substring over input alphabets ∑ = {0, 1} ?

Solution:

Example 32: Draw DFA that accepts any string which ends with 1 or it ends with an
even number of 0’s following the last 1. Alphabets are {0,1}.
Solution:
Example 33: Construct DFA accepting set of all strings containing even no. of a’s and
even no. of b’s over input alphabet {a,b}.
Solution:

Example 34: Give DFA accepting the language over alphabet {0,1} such that all
strings of 0 and 1 ending in 101.
Solution:

Example 35: Construct DFA for anb | n>=0.


Solution:
Example 36: construct DFA for binary integer divisible by 3 ?
Solution:

Example 37: Draw a DFA for the language accepting strings containing neither ’00’,
nor ’11’ as substring over input alphabets ∑ = {0, 1} ?

Solution:
Example 38.

Consider the DFA that identifies whether the given decimal is even or odd.

Here we consider 3 states, one start state qstart, one even state qeven and one odd
state qodd.

If the machine stops at qeven the given number is even.

If it stops at qodd the given number is odd.


Conversion from NFA to DFA
In this section, we will discuss the method of converting NFA to its equivalent DFA. In
NFA, when a specific input is given to the current state, the machine goes to multiple
states. It can have zero, one or more than one move on a given input symbol. On the
other hand, in DFA, when a specific input is given to the current state, the machine
goes to only one state. DFA has only one move on a given input symbol.

Let, M = (Q, ∑, δ, q0, F) is an NFA which accepts the language L(M). There should be
equivalent DFA denoted by M' = (Q', ∑', q0', δ', F') such that L(M) = L(M').

Steps for converting NFA to DFA:


Step 1: Initially Q' = ϕ

Step 2: Add q0 of NFA to Q'. Then find the transitions from this start state.

Step 3: In Q', find the possible set of states for each input symbol. If this set of states
is not in Q', then add it to Q'.

Step 4: In DFA, the final state will be all the states which contain F(final states of
NFA)

Example 1:
Convert the given NFA to DFA.

Solution: For the given transition diagram we will first construct the transition table.

State 0 1

→q0 q0 q1

q1 {q1, q2} q1

*q2 q2 {q1, q2}


Now we will obtain δ' transition for state q0.

1. δ'([q0], 0) = [q0]
2. δ'([q0], 1) = [q1]

The δ' transition for state q1 is obtained as:

1. δ'([q1], 0) = [q1, q2] (new state generated)


2. δ'([q1], 1) = [q1]

The δ' transition for state q2 is obtained as:

1. δ'([q2], 0) = [q2]
2. δ'([q2], 1) = [q1, q2]

Now we will obtain δ' transition on [q1, q2].

1. δ'([q1, q2], 0) = δ(q1, 0) ∪ δ(q2, 0)


2. = {q1, q2} ∪ {q2}
3. = [q1, q2]
4. δ'([q1, q2], 1) = δ(q1, 1) ∪ δ(q2, 1)
5. = {q1} ∪ {q1, q2}
6. = {q1, q2}
7. = [q1, q2]

The state [q1, q2] is the final state as well because it contains a final state q2. The transition table for the
constructed DFA will be:

State 0 1

→[q0] [q0] [q1]

[q1] [q1, q2] [q1]

*[q2] [q2] [q1, q2]

*[q1, q2] [q1, q2] [q1, q2]

The Transition diagram will be:


The state q2 can be eliminated because q2 is an unreachable state.

Example 2:
Convert the given NFA to DFA.

Solution: For the given transition diagram we will first construct the transition table.

State 0 1

→q0 {q0, q1} {q1}

*q1 ϕ {q0, q1}

Now we will obtain δ' transition for state q0.


1. δ'([q0], 0) = {q0, q1}
2. = [q0, q1] (new state generated)
3. δ'([q0], 1) = {q1} = [q1]

The δ' transition for state q1 is obtained as:

1. δ'([q1], 0) = ϕ
2. δ'([q1], 1) = [q0, q1]

Now we will obtain δ' transition on [q0, q1].

1. δ'([q0, q1], 0) = δ(q0, 0) ∪ δ(q1, 0)


2. = {q0, q1} ∪ ϕ
3. = {q0, q1}
4. = [q0, q1]

Similarly,

1. δ'([q0, q1], 1) = δ(q0, 1) ∪ δ(q1, 1)


2. = {q1} ∪ {q0, q1}
3. = {q0, q1}
4. = [q0, q1]

As in the given NFA, q1 is a final state, then in DFA wherever, q1 exists that state
becomes a final state. Hence in the DFA, final states are [q1] and [q0, q1]. Therefore
set of final states F = {[q1], [q0, q1]}.

The transition table for the constructed DFA will be:

State 0 1

→[q0] [q0, q1] [q1]

*[q1] ϕ [q0, q1]

*[q0, q1] [q0, q1] [q0, q1]

The Transition diagram will be:


Even we can change the name of the states of DFA.

Suppose

1. A = [q0]
2. B = [q1]
3. C = [q0, q1]

With these new names the DFA will be as follows:


Problem-01:

Convert the following Non-Deterministic Finite Automata (NFA) to Deterministic Finite Automata
(DFA)-

Solution-

Transition table for the given Non-Deterministic Finite Automata (NFA) is-

State / Alphabet a b

→q0 q0 q0, q1

q1 – *q2

*q2 – –

Step-01:

Let Q’ be a new set of states of the Deterministic Finite Automata (DFA).


Let T’ be a new transition table of the DFA.

Step-02:

Add transitions of start state q0 to the transition table T’.


State / Alphabet a b

→q0 q0 {q0, q1}

Step-03:

New state present in state Q’ is {q0, q1}.


Add transitions for set of states {q0, q1} to the transition table T’.

State / Alphabet a b

→q0 q0 {q0, q1}

{q0, q1} q0 {q0, q1, q2}

Step-04:

New state present in state Q’ is {q0, q1, q2}.


Add transitions for set of states {q0, q1, q2} to the transition table T’.

State / Alphabet a b

→q0 q0 {q0, q1}

{q0, q1} q0 {q0, q1, q2}

{q0, q1, q2} q0 {q0, q1, q2}

Step-05:

Since no new states are left to be added in the transition table T’, so we stop.
States containing q2 as its component are treated as final states of the DFA.
Finally, Transition table for Deterministic Finite Automata (DFA) is-

State / Alphabet a b

→q0 q0 {q0, q1}

{q0, q1} q0 *{q0, q1, q2}

*{q0, q1, q2} q0 *{q0, q1, q2}

Now, Deterministic Finite Automata (DFA) may be drawn as-

Problem-02:

Convert the following Non-Deterministic Finite Automata (NFA) to Deterministic Finite Automata
(DFA)-
Solution-

Transition table for the given Non-Deterministic Finite Automata (NFA) is-

State / Alphabet 0 1

→q0 q0 q1, *q2

q1 q1, *q2 *q2

*q2 q0, q1 q1

Step-01:

Let Q’ be a new set of states of the Deterministic Finite Automata (DFA).


Let T’ be a new transition table of the DFA.

Step-02:

Add transitions of start state q0 to the transition table T’.

State / Alphabet 0 1

→q0 q0 {q1, q2}


Step-03:

New state present in state Q’ is {q1, q2}.


Add transitions for set of states {q1, q2} to the transition table T’.

State / Alphabet 0 1

→q0 q0 {q1, q2}

{q1, q2} {q0, q1, q2} {q1, q2}

Step-04:

New state present in state Q’ is {q0, q1, q2}.


Add transitions for set of states {q0, q1, q2} to the transition table T’.

State / Alphabet 0 1

→q0 q0 {q1, q2}

{q1, q2} {q0, q1, q2} {q1, q2}

{q0, q1, q2} {q0, q1, q2} {q1, q2}

Step-05:

Since no new states are left to be added in the transition table T’, so we stop.
States containing q2 as its component are treated as final states of the DFA.

Finally, Transition table for Deterministic Finite Automata (DFA) is-


State / Alphabet 0 1

→q0 q0 *{q1, q2}

*{q1, q2} *{q0, q1, q2} *{q1, q2}

*{q0, q1, q2} *{q0, q1, q2} *{q1, q2}

Now, Deterministic Finite Automata (DFA) may be drawn as-

Problem-03:

Convert the following Non-Deterministic Finite Automata (NFA) to Deterministic Finite Automata
(DFA)-
Solution-

Transition table for the given Non-Deterministic Finite Automata (NFA) is-

State / Alphabet a b

→q0 *q1, q2 –

*q1 – –

q2 *q1, q2 q2

Step-01:

Let Q’ be a new set of states of the Deterministic Finite Automata (DFA).


Let T’ be a new transition table of the DFA.

Step-02:

Add transitions of start state q0 to the transition table T’.

State / Alphabet a b

→q0 {q1, q2} Ø (Dead State)

Step-03:

New state present in state Q’ is {q1, q2}.


Add transitions for set of states {q1, q2} to the transition table T’.

State / Alphabet a b
→q0 {q1, q2} Ø

{q1, q2} {q1, q2} q2

Step-04:

New state present in state Q’ is q2.


Add transitions for state q2 to the transition table T’.

State / Alphabet a b

→q0 {q1, q2} Ø

{q1, q2} {q1, q2} q2

q2 {q1, q2} q2

Step-05:

Add transitions for dead state {Ø} to the transition table T’.

State / Alphabet a b

→q0 {q1, q2} Ø

{q1, q2} {q1, q2} q2

q2 {q1, q2} q2

Ø Ø Ø
Step-06:

Since no new states are left to be added in the transition table T’, so we stop.
States containing q1 as its component are treated as final states of the DFA.

Finally, Transition table for Deterministic Finite Automata (DFA) is-

State / Alphabet a b

→q0 *{q1, q2} Ø

*{q1, q2} *{q1, q2} q2

q2 *{q1, q2} q2

Ø Ø Ø

Now, Deterministic Finite Automata (DFA) may be drawn as-


Important Points-

It is important to note the following points when converting a given NFA into a DFA-

Note-01:

 After conversion, the number of states in the resulting DFA may or may not be same as NFA.
 The maximum number of states that may be present in the DFA are 2Number of states in the NFA.

Note-02:

In general, the following relationship exists between the number of states in the NFA and DFA-

1 <= n <= 2m

Here,
 n = Number of states in the DFA
 m = Number of states in the NFA

Note-03:

 In the resulting DFA, all those states that contain the final state(s) of NFA are treated as final
states.

You might also like