0% found this document useful (0 votes)
4 views120 pages

AUTOMATA

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 120

SCSVMV

Department of Mathematics

Lecture Notes

Dr. T. N. Kavitha

III CSE- Automata Theory –

Unit I
Automata Theory – Unit I

Unit-I

(FINITE AUTOMATA)
Deterministic finite automata

Non-deterministic finite automata

An application: Text search

Finite automata with epsilon transitions


Automata Theory – Introduction:

Automata (singular: automation) are abstract models of machines that perform


computations on an input by moving through a series of states. At each state of the
computation, a transition function determines the next configuration on the basis of a
finite portion of the present state. As a result, once the computation reaches an
accepting state, it accepts that input. The most general and powerful automata is the
Turing machine.

An automaton has a mechanism to read input, which is string over a given alphabet.
This input is actually written on an input tape /file, which can be read by automaton
but cannot change it. Input file is divided into cells each of which can hold one
symbol. Automaton has a control unit which is said to be in one of finite number of
internal states. The automation can change states in a defined way.

There are four major families of automaton:

Finite-state machine
Pushdown automata
Linear-bounded automata
Turing machine
The families of automata above can be interpreted in a hierarchical form, where the
finite- state machine is the simplest automata and the Turing machine is the most
complex.

Finite State Machines:

An automaton in which the state set Q contains only a finite number of elements is
called a finite-state machine (FSM).
FSMs are abstract machines, consisting of
a set of states (set Q),
a set of input events (set I),
a set of output events (set Z) and a state transition function.
The state transition function takes the current state and an input event and returns the
new set of output events and the next state. Therefore, it can be seen as a function
which maps an ordered sequence of input events into a corresponding sequence, or set,
of output events.
In order to fully understand conceptually a finite-state machine, consider an analogy
to an elevator:
An elevator is a mechanism that does not remember all previous requests for service
but the current floor, the direction of motion (up or down) and the collection of not-
yet satisfied requests for services. Therefore, at any given moment in time, an elevator
in operated would be defined by the following mathematical terms:

States: finite set of states to reflect the past history of the customers’ requests.

Inputs: finite set of input, depending on the number of floors the elevator is able to
access. We can use the set I, whose size is the number of floors in the building.

Outputs: finite set of output, depending on the need for the elevator to go up or down,
according to customers‘ needs.

Applications of Finite State Machines

Traffic Lights
Video Games
Text Parsing
CPU Controllers
Protocol Analysis
Natural Language Processing
Speech Recognition

Types of Finite Automata:

Finite Automaton can be classified into two types:


Deterministic Finite Automata (DFA)
Non-deterministic Finite Automata (NDFA/ NFA)

Automata Introduction
Symbol:
A symbol is a character or mark.

Ex: a, b, c, 0, 1, 2,...... etc.

Alphabet:
A finite non-empty set of symbols is called alphabet. It is denoted by the symbol Σ.

Ex: (1) Σ = {a,b} is an alphabet of a and b.


(2) Σ = {0,1} is an alphabet of machine language.
Basic definitions

String or Word:
A string or Word is a finite sequence of symbols from the alphabet Σ.

Ex: A string formed from the alphabet Σ = {0,1} is 01,0110, 0011, 010, 0100,
1011, .....etc.

Length of a string:
Length of a string is the number of symbols in a string. If w is the string then length of
the string is denoted as │w│.

Ex: If w = 001100, then │w│= 6.

Empty String:
A string with no symbols is usually denoted by ϵ.
│ϵ│= 0.

Substring:
Any string of consecutive characters from a string w is called as substring of w.

Reverse of a string:

The reverse of a string is obtained by writing the symbols in reverse order.


i.e, if w = a1a2…..an-1,an then reverse of the string w can be written as
wR = an a n-1….a2 a1.

Prefix and Suffix of a string:

A prefix is string of any number of leading symbols.


A suffix is any number of trailing symbols.

Ex: If w = abbab, then


prefix = {ϵ , a , ab , abb , abba , abbab}
suffix = {ϵ , b , ab , bab , bbab , abbab}

Concatenation of Strings:
Concatenation of strings w and u is obtained by appending the symbols of string u to
the right end of string w.

Ex:
w = a1a2…..an
u = b1b2…..bn
Concatenation of w and u is
wu = a1a2…..an b1b2…..bn

Kleene Star / Closure of Strings ( ∗ )


If Σ is an alphabet, then Σ∗ is obtained by concatenating zero or more symbols from
Σ.
Σ = {0,1}
Σ0 = {ϵ} which is set of words of length 0
Σ1 = {0,1} which is set of words of length 1
Σ2 = {00, 01, 10, 11} set of strings of length 2 and so on.
Σ* = Σ0 ∪ Σ 1∪ Σ 2∪ … …

Ex:
Σ = {0,1}
Σ* = {ϵ , 0, 1, 00, 01, 10, 11, 000, 010,….}

Positive Closure of Strings ( Σ+)


Σ+ is known as positive closure, which is obtained by Σ+ = Σ* - ϵ .

Ex:

Σ = {0,1}

Σ+ = {0, 1, 00, 01, 10, 11, 000, 010, ……}.

Language:
Language can be defined as a set of strings obtained from Σ*, where Σ denotes
alphabets of that language.
ie, L ⊆ ∑*.
Ex:
Σ = {a, b}
Σ* = {ϵ, a, b, ab, ba, aaa, aab, …..}.
A language of strings consisting of equal number of a’s and b’s can be
L1 = {ab, aabb, abab, baba, …..}

A language of strings consisting of n number of a’s followed by m number of b’s


where m > n is
L2 = {abb, aabbb, aaabbbb, abbb, ……}.
Mark allotment pattern

Writing regular expression ----- 1mark


Minimum string ----- 1mark
L (M) ----- 1mark
Design of DFA or NFA ----- 6 marks
Transition Function ------ 2 marks
Transition table ------ 2 marks
Checking acceptance and rejection of strings- ---- 3 Marks

Deterministic Finite state Automaton


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: MINIMUM STRING
We will construct DFA for the following strings-
01
001
101
0101………….
L(M) = { W | w end with 01}
Step-03:
The required DFA is
Step 4: Transition table

0 1
q0 q1 q0
q1 q1 q2
q2 q1 q0

Step5: Transition function


(i) DFA action for the input string 0001
Consider M(q0, 0001) ⊢ M(q1,001)
⊢ M(q1,01)
⊢ M (q1,1)
⊢ ( q2, ℇ )
Since, we reached the final state at the end of input, the string 0001 is accepted by
M.

(iI) DFA action for the input string 0010:


Consider (q0, 0010) ⊢ M(q1,010)
⊢ M(q1,10)
⊢ M (q2,0)
⊢ ( q1,ℇ)
Since, we reached the end of input and not in the final state, the string 0010 is not
accepted by M.

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:MINIMUM STRING
We will construct DFA for the following strings-
abb
aabb
ababb
abb abb
L(M) = { W | w ends with substring “abb”}

Step-03:
The required DFA is-
Step 4: Transition table

a b
q0 q1 q0
q1 q1 q2
q2 q1 q3
q3 q1 q0

Step5: Transition function


(i) DFA action for the input string ababb
Consider M (q0, ababb) ⊢ M(q1, babb)
⊢ M(q2, abb)
⊢ M (q1, bb)
⊢ M (q2, b)
⊢ ( q3, ℇ )
Since, we reached the final state at the end of input, the string ababb is accepted
by M.
(iI) DFA action for the input string ababba:
Consider (q0, ababba) ⊢ M(q1, babba)
⊢ M(q2, abba)
⊢ M (q1, bba)
⊢ M (q2, ba)
⊢ M (q2, ba)
⊢ ( q3, a)
⊢ ( q1, ℇ)
Since, we reached the end of input and not in the final state, the string ababba is
not accepted by M.

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
ab abba
abb abba
abba abba
L(M) = { W | w ENDS WITH THE SUBSTRING abba }
Step-03:
The required DFA is
Step 4: Transition table

a b
q0 q1 q0
q1 q1 q2
q2 q1 q3
q3 q4 q0
q4 q1 q2

Step5: Transition function


(i) DFA action for the input string ab abba
Consider (q0, ab abba ) ⊢ M( q1, b abba )
⊢ M( q2, abba )
⊢ M ( q1, bba )
⊢ M ( q2, ba )
⊢ M ( q3, a )

⊢ ( q4, ℇ )
Since, we reached the final state at the end of input, the string ab abba is accepted
by M.
(iI) DFA action for the input string ab abbab
Consider (q0, ab abbab ) ⊢ M( q1, b abbab )
⊢ M( q2, abbab )
⊢ M ( q1, bbab )
⊢ M ( q2, ba b )
⊢ M ( q3, ab )
⊢ ( q4, b )
⊢ ( q2, ℇ )

Since, we reached the end of input and not in the final state, the string ab abbab is
not accepted by M.

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
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
(i) DFA action for the input string abaa
Consider (q0, abaa) ⊢ M(q1,baa)
⊢ M(qf,aa)
⊢ M (qf,a)
⊢ ( f,e)
Since, we reached the final state at the end of input, the string abaa is accepted
by M.
(iI) DFA action for the input string bbab:
Consider (q0, bbab) ⊢ M(D,bab)
⊢ M(D,ab)
⊢ M (D,b)
⊢ ( ,e)
Since, we reached the end of input and not in the final state, the string bbab is not
accepted by M.
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
ab…………
Step-03:
The required DFA is
aaaaaaaaa , abbbbbbbb,

a b
Q0 QF D
QF QF QF
D D D

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
1010
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
001
00000
Step-03:
The required DFA is

Non-Deterministic Finite Automata

Non-Deterministic Finite Automata (NDFA / NFA) is an automata in which


for some current state and input symbol, there exists more than one next output states.
It is also known as Non-Deterministic Finite Accepter (NFA).

Formal Definition
Non-Deterministic Finite Automata is defined by the quintuple
M = (Q, Σ, δ, q0, F)
Where,
Q = finite set of states
Σ = non-empty finite set of symbols called as input alphabets
δ : Q x Σ → 2Q is a total function called as transition function
q0 ∈ Q is the initial state

F ⊆ Q is a set of final states

Extended transition function δ for NFA


For a state q and a string x, δ(q, x) is the set of states that NFA can reach when it
reads the string x, starting at the state q. In general, NFA non-deterministically goes
through a number of states from the state q as it reads the symbols in the string x.
Thus, for an NFA, M = (Q, Σ, δ, q0, F), the function ‘δ’ is extended as
δ : Q x Σ* → P(Q)
and is defined recursively as
a) For any state q of Q, δ(q, ϵ) = {q}
This means that an NFA stays in the same state q when it reads an empty string at
state q.
b). For any state q of Q and any string x ϵ Σ* , with ‘a’ as the last symbol of x and
a ϵ Σ , then
δ(q, xa) = ⋃ for every string δ(p, a) or δ(q, xa) = pϵδ(q, x) ⋃ δ(q, a)
This means that the set of states that can be reached by NFA after reading string xa
starting at state q, is the set of states it can reach by reading the symbol ‘a’ after
reading the string x, starting at state q.

Acceptance by NFA
A string ‘w’ is said to be accepted by a NFA if
there exists at least one transition path on which we start at initial state and ends at
final state. δ* (q0, w) = F

In other words,
The language accepted by NFA, M for a string x is defined as,
L(M) = { x | (q0, x) = p, where p contains atleast one member of F}
Or
L(M) = { x | (q0, x)∩ ≠ {φ}}.
This means that the NFA accepts the string x, iff it can reach an accepting state by
reading x starting at the initial state.
Example: ( Language accepted by NFA )

Consider the above automata with input w = 00101.


Minimum set of strings= {ϵ, 0, 00, 001, 0010, 00101}
δ (q0, ϵ) = q0

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

δ (q0, 00) =δ (δ (q0, 0),0)


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

= {q0, q1} ∪ {φ}


= {q0, q1}.
δ (q0, 001) =δ (δ (q0, 00),1)
=δ ({ q0, q1},1)
= δ(q0, 1)∪ δ(q1, 1)
= {q0, q2}.
δ (q0, 0010) =δ (δ (q0, 001),0)
=δ ({q0, q2},0)
=δ (q0, 0)∪δ (q2, 0)

= {q0, q1} ∪ {φ}


= {q0, q1}.
δ (q0, 00101) =δ (δ (q0, 0010),1)
= δ({q0, q1},1)
=δ (q0, 1)∪δ(q1, 1)
= {q0, q2}.
For the above automata with w = 00101, we have
δ(q0, 00101) = {q0, q2}, where P = { q0, q2}.
Since P contains q2 which is the final state, 00101 is accepted.
In other words,
δ(q0, 00101) = {q0, q2} ∩ F
= {q0, q2} ∩ {q2}
= {q2}
≠ {φ}
⇒ 00101 is accepted by the NFA.
Example:
Consider the following NFA

For the string w = ab,


There exists two transition paths.
One transition path starts at initial state and ends at final state.
Therefore, string w = ab is accepted by the NFA.
Dead Configuration or Trap State
In Non-Deterministic Finite Automata,
The result of a transition function may be empty.
In such a case, automata gets stopped forcefully after entering that configuration.
This type of configuration is known as dead configuration.
The string gets rejected after entering the dead configuration.
Example of Non-Deterministic Finite Automata Without Epsilon:
Following automata is an example of Non-Deterministic Finite Automata without
epsilon.

The above NFA can be defined in form of five tuples as-


{Q, ∑, δ, q0, F} = { {A, B, C, D, E, F}, {a, b, c}, δ, A, {D, F} }

where-
 {A, B, C, D, E, F} refers to the set of states
 {a, b, c} refers to the set of input alphabets
 δ refers to the transition function
 A refers to the the initial state
 {D, F} refers to the set of final states

Transition function δ is defined as-


 δ (A, a) = B
 δ (A, a) = E
 δ (B, b) = C
 δ (C, c) = D
 δ (E, b) = F
 δ (F, c) = E

Transition Table for the above Non-Deterministic Finite Automata is-

States / Alphabets a b c

A {B, F} – –

B – C –

C – – D

D – – –

E – F –

F – – E

Example of Non-Deterministic Finite Automata With Epsilon-

Following automata is an example of Non-Deterministic Finite Automata with


epsilon-
The above NFA can be defined in form of five tuples as-
{Q, ∑, δ, q0, F} = { {A, B, C}, {0, 1}, δ, A, {A} }
where-
 {A, B, C} refers to the set of states
 {0, 1} refers to the set of input alphabets
 δ refers to the transition function
 A refers to the the initial state
 {A} refers to the set of final states

Transition function δ is defined as-


 δ (A, 1) = B
 δ (A, ∈) = C
 δ (B, 0) = A
 δ (B, 0) = C
 δ (B, 1) = C

Transition Table for the above Non-Deterministic Finite Automata is-

States / Alphabets 0 1 ∈

A – B C

B {A, C} C –
C – – –

Dead Configuration or Trap State-

In Non-Deterministic Finite Automata,


 The result of a transition function may be empty.
 In such a case, automata gets stopped forcefully after entering that
configuration.
 This type of configuration is known as dead configuration.
 The string gets rejected after entering the dead configuration.

Equivalence of DFA and NFA-

Two finite accepters are said to be equal in power if they both accepts the same language.
DFA and NFA are both exactly equal in power.

Example-
Consider a language L(M) = { (10)n : n >= 0 }= { 10, 1010, 101010, ……….}
Equivalent NFA for the language L(M) is-

Equivalent DFA for the language L(M) is-


 Both the above automata accepts the same language L(M).
 Thus, both are equal in power.

Important Points

It is important to note the following points-


 Both DFA and NFA are exactly same in power.
 For any regular language, both DFA and NFA can be constructed.
 There exists an equivalent DFA corresponding to every NFA.
 Every NFA can be converted into its equivalent DFA.
 There exists no NFA that can not be converted into its equivalent DFA.
 Every DFA is a NFA but every NFA is not a DFA.

Acceptance by NFA-

A string ‘w’ is said to be accepted by a NFA if


there exists at least one transition path on which we start at initial state and ends at final state.
δ* (q0, w) = F

Example-

Consider the following NFA-


For the string w = ab,
 There exists two transition paths.
 One transition path starts at initial state and ends at final state.
 Therefore, string w = ab is accepted by the NFA.

Example:
Design an NFA to accept set of all strings starting with ‘a’ followed by ‘a’ or ‘b’ and
ending with a or any number of b’s.
Solution:
It is required to design an NFA for the regular expression r = a*(ab+a+ba)(bb)*

ie, L(M) = {a, ab, aaa, abbbb, ….}


Consider,
Σ = {0, 1}, Q = {q0, q1, q2, q3},q0= initial state, q3= final state and δ is given by:
a-- q0->q3 ab --> q0->q1->q3 aaa- q0->q0->q0->q3
abbbb - q0->q1 ->q3-> q1- >q3->q1
Transition diagram:
Transition table:

NFA action for the input string:


To Show: The string abb is accepted by the NFA.
δ(q0, ϵ) = q0, δ(q0, a) = {q0, q1, q3}, δ(q0, b) = {q2}
δ(q0, ab) = δ( δ(q0, a), b)
=δ (q0, b) ∪δ (q1, b) ∪ δ(q3, b)

= {q2} ∪ {q3} ∪ {q1}


= {q1, q2, q3}
δ(q0, abb) =δ (δ (q0, ab), b)
= δ(q1, b) ∪δ (q2, b) ∪ δ(q3, b)
= {q3, q1}.
Since P = {q3, q1} contains the final state q3, the string abb is accepted by the NFA.
Example:
Design an NFA that accepts a set of all strings ending in 00.
Solution:
It is required to design an NFA for the regular expression r = (1+0)* (00).
ie, L(M) = {00, 1100,100, 000, 111000 ….}
End with 00 therefore the substring length is 2 . so the number of states are 2+1 = 3
Consider,
Σ = {0, 1}, Q = {q0, q1, q2,},
q0 = initial state, F = q2 is the final state and is given by:
Transition diagram:

L(M) = { wℇ ∑’ | w ends with 00}

Transition table:

NFA action for the input string:


To Show: The string 10100 is accepted by the NFA.
δ(q0, ϵ) = q0, δ(q0, 0) = q1, δ(q0, 1) = q0
δ(q0, 10) = δ (δ (q0, 1), 0)
= δ(q0, 0)
= {q1}.
δ(q0, 101) =δ (δ (q0, 10), 1)
=δ (q1, 1)
= {q0}.
δ(q0, 1010) = δ( δ(q0, 101), 0)
=δ (q0, 0)
= {q1}.
δ(q0, 10100) = δ( δ(q0, 1010), 0)
=δ (q1, 0)
= {q2}.
Since P = {q3, q1} contains the final state q3, the string abb is accepted by the NFA.
ie, δ(q0, 10100) = {q2} ∩ F = {q2} ∩ {q2} = {q2} ≠ φ hence accepted.

Example:
Construct an NFA that accepts the set of all strings over {0,1} that start with 0 or 1
and end with 01 or 10.
Solution:
It is required to design an NFA for the regular expression r = (0+1)* (01+10).
ie, L(M) = {01, 10, 0010, 1110,011001,…..}
Consider,
Σ = {0, 1}, Q = {q0, q1, q2, q3},
q0 = initial state, F = q3 is the final state and is given by:
Transition diagram:

L(M)={ w ℇ Σ∗ | w contains set of all string with 1 or 0 ending in (01+10)}


Transition table:

NFA action for the input string:


To Show: The string 0110 is accepted by the NFA.
δ(q0, ϵ) = q0, δ(q0, 0) = {q0, q1} δ(q0, 1) = {q0, q2}
δ(q0, 01) =δ ( δ(q0, 0), 1)
= δ(q0, 1) ∪ δ (q1, 1)
= {q0, q2, q3}.
δ(q0, 011) = δ( δ(q0, 01), 1)
= δ(q0, 1) ∪ δ(q2, 1) ∪ δ(q3, 1)

= {q0, q2} ∪ {φ} ∪ {φ}


= {q0, q2}.

δ(q0, 0110) = δ( δ(q0, 011), 0)


= δ(q0, 0) ∪ δ (q2, 0)

= {q0 , q1} ∪ { q3}


= { q0 , q1, 3}
Since q3 is the final state, the string 0110 is accepted by the NFA.
ie, δ (q0, 0110) = { q0 , q1, 3} ∩ F = { q0 , q1, 3} ∩ {q3} = {q3} ≠ φ hence accepted.

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.
-----------
Non-Deterministic Automata with ϵ-Moves
In some situations, it would be useful to enhance NFAs by allowing transitions that
are not
triggered by any input symbol; such transitions are called ϵ-transitions.
If in a state q, an ϵ-transition to a state q’ is possible, then whenever the automaton
reaches state q in a computation, it can immediately proceed to state q’ without taking
any further input.
This capacity does not expand the class of languages that can be accepted by finite
automata but gives us some programming convenience.
Formal Definition
Non-Deterministic Finite Automata with ϵ-moves is defined by the quintuple
M = (Q, Σ, δ, q0, F)
Where,
Q = finite set of states
Σ = non-empty finite set of symbols called as input alphabets
δ : Q x (Σ ∪ ϵ )→ 2Q is a total function called as transition function

q0 ∈ Q is the initial state

F ⊆ Q is a set of final states


Transitions of NFA-ϵ
With respect to an NFA-ϵ, there exist two transitions.
ϵ-transitions – transitions that take place without reading any input symbols are
called ϵ-
transitions.
Non ϵ-transitions – transitions that take place with the reading of input symbols
are
called non ϵ-transitions.
Acceptance of strings by NFA-ϵ
A string is said to be accepted by the NFA-ϵ, if atleast one path exists that starts at the
initial
state and ends in one of the final states. The path formed contains states with
transitions from
ϵ-transitions or non ϵ-transitions.
ϵ- closure:
ϵ- closure for a state is the set of states reachable from the state, without reading any
symbol.
ϵ- closure of a given state ‘q’ is defined as the set of all states of automata, that can be
reached
from q on a path labeled by ϵ.
Extended transition function for NFA-ϵ
For a state q and string x, (q,x) is the set of states of NFA-ϵ which it can reach when it
reads
the string x, starting at state q (with or without ϵ). Thus, for an NFA-ϵ, the function is
extended as : Q × Σ* → P(Q) and is recursively defined as follows:
For any state q of Q,
δ(q,ϵ) = ϵ-closure ({q}).
For any state q of Q, any string xϵ Σ* with ‘a’ as the last symbol x and a ϵ Σ,
δ(q,xa) = ϵ-closure ( ⋃ for every p in q, δ (p ,a ))
Language accepted by NFA-ϵ
A language is accepted by NFA-ϵ M, for a string x with a state q0 ϵ Q, if and only if,
(q0,x)
contains atleast one accepting state.
In other words,
The language accepted by NFA-ϵ M, for a string x is defined as,
L(M) = { x | (q0, x) = P, where P contains atleast one member of F}
Or
L(M) = { x | (q0, x) ∩ ≠ {φ}}.
Example of Non-Deterministic Finite Automata With Epsilon
Following automata is an example of Non-Deterministic Finite Automata with epsilon.

The above NFA can be defined in form of five tuples as


{ {A, B, C}, {0, 1}, δ, A, {A} }
where
{A, B, C} refers to the set of states
{0, 1} refers to the set of input alphabets
δ refers to the transition function
A refers to the the initial state
{A} refers to the set of final states
Transition function δ is defined as
δ (A, 1) = B
δ (A, ∈) = C
δ (B, 0) = A
δ (B, 0) = C
δ (B, 1) = C
Transition Table for the above Non-Deterministic Finite Automata is
Example:
NFA with ϵ-transitions between q0 to q1 and q1 to q2.

This NFA with ϵ-transitions showing that, without any input symbol, the NFA can be
in the final
state.
Important Points
It is important to note the following points.
Both DFA and NFA are exactly same in power.
For any regular language, both DFA and NFA can be constructed.
There exists an equivalent DFA corresponding to every NFA.
Every NFA can be converted into its equivalent DFA.
There exists no NFA that can not be converted into its equivalent DFA.
Every DFA is a NFA but every NFA is not a DFA.
Example:
Design an NFA with ϵ-moves to accept all the strings with any number of a’s
followed by any
number of b’s followed by any number of c’s.
Solution:
It is required to design an NFA-ϵ for the regular expression r = a*b*c*
ie, L(M) = {ϵ, aa, bb, cc, abc, aabbcc,…..}
Consider,
Σ = {a, b, c}, Q = {q0, q1, q2},
q0 = initial state, F = q2 is the final state and is given by:
Transition diagram:

L(M) = {w ℇ Σ∗ | w contains a’s or b’s or c’s or combination of a,b,c }


Transition table:

NFA-ϵ action for the input string:


To show: The string abc is accepted by NFA-ϵ.
To Compute ϵ-closure:
ϵ-closure ({q0}) = {q0, q1, q2}
ϵ-closure ({q1}) = {q1, q2}
ϵ-closure ({q2}) = {q2}.
To compute δ:
δ(ϵ-closure ({q0},a) = δ({q0, q1, q2},a)
= δ(q0,a) ∪ δ(q1,a) ∪ δ(q2, a)
= {q0}.
δ(ϵ-closure ({q0},ab) = δ(ϵ-closure δ( ϵ-closure ({q0},a),b)
= δ(ϵ-closure ({q0},b)
= δ({q0, q1, q2},b)
= δ(q0,b) ∪ δ(q1,b) ∪ δ(q2, b)

= {q1}
δ(ϵ-closure ({q0},abc) = δ(ϵ-closure ( δ(ϵ-closure ({q0},ab),c)
= δ(ϵ-closure ({q1},c)
=δ ({q1,q2}, c)
= δ(q1,c) ∪ δ(q2,c)
= {q2}.
⟹ϵ-closure ( δ(ϵ-closure ({q0},abc) = ϵ-closure ({q2}) = {q2}.
Since {q2} is an accepting state, the string abc is accepted.
Example:
Construct an NFA-ϵ to accept the set of all strings over Σ = {0,1} containing an even
number of
0’s or exactly two 1’s.
Solution:
Let M = (Q, Σ, q0, , F) be the NFA-ϵ , where
Q = {q0, q1, q2, q3, q4, q5 }
Σ = {0,1}
q0 = q0 and
F = {q1, q5}.
The transition of M to accept strings containing even number of 0’s or exactly two 1’s
is given below.
Advantages of Non-Deterministic Finite Automata
NFA can be smaller, easier to construct and understand than a DFA that accepts
the
same language.
It is useful for proving some theorems.
It gives a good introduction to non-determinism in more powerful computational
models, where non-determinism plays an important role.
Non-determinism is a kind of parallel computation where several processes can be
running concurrently.
Problem:1
Design an NFA-ϵ that accepts the set of all strings over Σ = {0,1}, which start and end
with 0.
Solution:

Problem:2(HW)
Design an NFA with ϵ-moves to accept the set of all strings over Σ = {a,b} that end in
a or b, followed by any number of a’s and b’s.
Solution:

Converting NFA to DFA | Solved Examples


In Non-Deterministic Finite Automata,
 For some current state and input symbol, there exists more than one next
output states.
 A string is accepted only if there exists at least one transition path starting at
initial state and ending at final state.
we will discuss how to convert a given NFA to a DFA.
NFA to DFA Conversion:
The following steps are followed to convert a given NFA to a DFA.
Step-01: NEW SET OF STATES Q’ AND NEW TRANSITION TABLE T’ FOR
DFA
Let Q’ be a new set of states of the DFA. Q’ is null in the starting.
Let T’ be a new transition table of the DFA.
Step-02: MULTIPLE STATE NFA INTO SINGLE STATE IN DFA

Add start state of the NFA to Q’.


Add transitions of the start state to the transition table T’.
If start state makes transition to multiple states for some input alphabet, then treat
those multiple states as a single state in the DFA.
In NFA, if the transition of start state over some input alphabet is null,
then perform the transition of start state over that input alphabet to a dead state in the
DFA.
Step-03: NEW STATE IN Q’ & T’
If any new state is present in the transition table T’,
Add the new state in Q’.
Add transitions of that state in the transition table T’.
Step-04: NEW STATE IN Q’ & T’

Keep repeating Step-03 until no new state is present in the transition table T’.
Finally, the transition table T’ so obtained is the complete transition table of the
required DFA.
PRACTICE PROBLEMS BASED ON CONVERTING NFA TO DFA-

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} Ø (TRAP STATE)

{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.
-----------

Non-Deterministic Automata with ϵ-Moves


In some situations, it would be useful to enhance NFAs by allowing transitions that
are not triggered by any input symbol; such transitions are called ϵ-transitions.

If in a state q, an ϵ-transition to a state q’ is possible, then whenever the automaton


reaches state q in a computation, it can immediately proceed to state q’ without taking
any further input.
This capacity does not expand the class of languages that can be accepted by finite
automata but gives us some programming convenience.
Formal Definition
Non-Deterministic Finite Automata with ϵ-moves is defined by the quintuple
M = (Q, ∑, δ, q0, F)
Where,
Q = finite set of states
∑ = non-empty finite set of symbols called as input alphabets
δ : Q x (∑ ∪ ϵ )→ 2Q is a total function called as transition function

q0 ∈ Q is the initial state

F ⊆ Q is a set of final states

Transitions of NFA-ϵ
With respect to an NFA-ϵ, there exist two transitions.
ϵ-transitions – transitions that take place without reading any input symbols are
called ϵ- transitions.
Non ϵ-transitions – transitions that take place with the reading of input symbols
are called non ϵ-transitions.

Acceptance of strings by NFA-ϵ

A string is said to be accepted by the NFA-ϵ, if atleast one path exists that starts at the
initial state and ends in one of the final states. The path formed contains states with
transitions from ϵ-transitions or non ϵ-transitions.

ϵ- closure:
ϵ- closure for a state is the set of states reachable from the state, without reading any
symbol.
ϵ- closure of a given state ‘q’ is defined as the set of all states of automata, that can be
reached from q on a path labeled by ϵ.

Extended transition function for NFA-ϵ


For a state q and string x, (q,x) is the set of states of NFA-ϵ which it can reach when it
reads the string x, starting at state q (with or without ϵ). Thus, for an NFA-ϵ, the
function is
extended as : Q × Σ* → P(Q) and is recursively defifined as follows:
For any state q of Q,
(q,ϵ) = ϵ-closure ({q}).
For any state q of Q, any string xϵ Σ* with ‘a’ as the last symbol x and a ϵ Σ,
(q,xa) = ϵ-closure ( ⋃ ( , ))

Language accepted by NFA-ϵ


A language is accepted by NFA-ϵ M, for a string x with a state q0 ϵ Q, if and only if,
(q0,x) contains atleast one accepting state.
In other words,
The language accepted by NFA-ϵ M, for a string x is defined as,
L(M) = { x | (q0, x) = P, where P contains atleast one member of F}
Or
L(M) = { x | (q0, x) ∩ ≠ {φ}}.

Example of Non-Deterministic Finite Automata With Epsilon


Following automata is an example of Non-Deterministic Finite Automata with epsilon.

NON DETERMINISTIC FINITE AUTOMATA (WITH EPSILON)


The above NFA can be defined in form of five tuples as { Q, ∑, δ, q0, F}=
{ {A, B, C}, {0, 1}, δ, A, {A} }
where
{A, B, C} refers to the set of states
{0, 1} refers to the set of input alphabets
δ refers to the transition function
A refers to the the initial state
{A} refers to the set of final states

Transition function δ is defined as


δ (A, 1) = B
δ (A, ∈) = C
δ (B, 0) = A
δ (B, 0) = C
δ (B, 1) = C
Transition Table for the above Non-Deterministic Finite Automata is
Example:
NFA with ϵ-transitions between q0 to q1 and q1 to q2.

This NFA with ϵ-transitions showing that, without any input symbol, the NFA can be
in the final state.
Important Points
It is important to note the following points.
Both DFA and NFA are exactly same in power.
For any regular language, both DFA and NFA can be constructed.
There exists an equivalent DFA corresponding to every NFA.
Every NFA can be converted into its equivalent DFA.
There exists no NFA that can not be converted into its equivalent DFA.
Every DFA is a NFA but every NFA is not a DFA.

Example:
Design an NFA with ϵ-moves to accept all the strings with any number of a’s
followed by any number of b’s followed by any number of c’s.

Solution:
It is required to design an NFA-ϵ for the regular expression r = a*b*c*
ie, L(M) = {ϵ, aa, bb, cc, abc, aabbcc,…..}
Consider,
Σ = {a, b, c}, Q = {q0, q1, q2},
q0 = initial state, F = q2 is the final state and is given by:
Transition diagram:

L(M) = {w ℇ Σ∗ | w contains a’s or b’s or c’s or combination of a,b,c }


Transition table:

NFA-ϵ action for the input string:


To show:

The string abc is accepted by NFA-ϵ.

To Compute ϵ-closure:
ϵ-closure ({q0}) = {q0, q1, q2}
ϵ-closure ({q1}) = {q1, q2}
ϵ-closure ({q2}) = {q2}.

To compute δ:
δ(ϵ-closure ({q0},a) = δ({q0, q1, q2},a)
= δ(q0,a) ∪ δ(q1,a) ∪ δ(q2, a)
= {q0}.

δ(ϵ-closure ({q0},ab) = δ(ϵ-closure δ( ϵ-closure ({q0},a),b)


= δ(ϵ-closure ({q0},b)
= δ({q0, q1, q2},b)
= δ(q0,b) ∪ δ(q1,b) ∪ δ(q2, b)
= {q1}

δ(ϵ-closure ({q0},abc) = δ(ϵ-closure ( δ(ϵ-closure ({q0},ab),c)


= δ(ϵ-closure ({q1},c)
=δ ({q1,q2}, c)
= δ(q1,c) ∪ δ(q2,c)
= {q2}.
⟹ϵ-closure ( δ(ϵ-closure ({q0},abc) = ϵ-closure ({q2}) = {q2}.
Since {q2} is an accepting state, the string abc is accepted.
Example:
Construct an NFA-ϵ to accept the set of all strings over Σ = {0,1} containing an even
number of 0’s or exactly two 1’s.
Solution:
Let M = (Q, Σ, q0, , F) be the NFA-ϵ , where
Q = {q0, q1, q2, q3, q4, q5 }
Σ = {0,1}
q0 = q0 and
F = {q1, q5}.
The transition of M to accept strings containing even number of 0’s or exactly two 1’s
is given below.

Advantages of Non-Deterministic Finite Automata


NFA can be smaller, easier to construct and understand than a DFA that accepts
the same language.
It is useful for proving some theorems.
It gives a good introduction to non-determinism in more powerful computational
models, where non-determinism plays an important role.
Non-determinism is a kind of parallel computation where several processes can be
running concurrently.
Problem:1
Design an NFA-ϵ that accepts the set of all strings over Σ = {0,1}, which start and end
with 0.
Solution:
roblem:2
Design an NFA with ϵ-moves to accept the set of all strings over Σ = {a,b} that end in
a or b, followed by any number of a’s and b’s.
Solution:1.5 NFA to DFA Conversion:
The following steps are followed to convert a given NFA to a DFA.
Step-01:
Let Q’ be a new set of states of the DFA. Q’ is null in the starting.
Let T’ be a new transition table of the DFA.
Step-02:
Add start state of the NFA to Q’.
Add transitions of the start state to the transition table T’.
If start state makes transition to multiple states for some input alphabet, then treat
those
multiple states as a single state in the DFA.
In NFA, if the transition of start state over some input alphabet is null,
then perform the transition of start state over that input alphabet to a dead state in the
DFA.
Step-03:
If any new state is present in the transition table T’,
Add the new state in Q’.
Add transitions of that state in the transition table T’.
Step-04:
Keep repeating Step-03 until no new state is present in the transition table T’.
Finally, the transition table T’ so obtained is the complete transition table of the
required DFA.
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

Step01:
Let Q’ be a new set of states of the Deterministic Finite Automata (DFA).
Let T’ be a new transition table of the DFA.
Step02:
Add transitions of start state q0 to the transition table T’.

Step03:
New state present in state Q’ is {q0, q1}.
Add transitions for set of states {q0, q1} to the transition table T’.

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’.

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
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
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’.

Step-03:
New state present in state Q’ is {q1, q2}.
Add transitions for set of states {q1, q2} to the transition table T’.

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

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

Problem-03:
Convert the following Non-Deterministic Finite Automata (NFA) to Deter
ministic 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’.
Step-03:
New state present in state Q’ is {q1, q2}.
Add transitions for set of states {q1, q2} to the transition table T’.

Step-04:
New state present in state Q’ is q2.
Add transitions for state q2 to the transition table T’

Step-05:
Add transitions for dead state {Ø} to the transition table T’.
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

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


Important Points:
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 .
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
In the resulting DFA, all those states that contain the final state(s) of NFA are
treated as final states.

References:
1. “A text book on Automata Theory” , Nasir S.F.B and P.K.Srimani, Combridge
University Press India Pvt.Ltd. ISBN 978-81-7596-545-4
2. www.tutorialspoint.com
3. www.gatevidyalay.com
4.Formal Languages and Automata By Peter Linz
5.Automata Theory, Languages & Computation By Ullman
6.Introduction to Theory of Computation By Michael Sipser
Answer Key
Unit I-Finite Automata

Part A

1. Define DFA.

An DFA is a 5 tuple or quintuple M = (Q, ∑,  , q0, F) where

M – name of the machine


Q- Finite set of states of finite automata
∑ - set of symbols
 : Qx ∑  Q, the transition function
q0 – the start state
F- set of final states

2. When a string is said to be accepted by the given finite automaton?


A string is said to be accepted by the finite automaton if it takes the machine from
initial state q0 to final state.

3. Define transition graph.


The transition diagram is defined as a graph with circles, arrows and arcs with
labels. Each circle corresponds to each state Q and the directed edge indicates the
transition from one state to another.
4. Define transition table.
Transition table is defined as a conventional tabular representation of a transition
function in which row correspond to state and column correspond to inputs. The
entries of the table indicate the transition of DFA.
5. Define NFA.
An NFA is a 5 tuple or quintuple M=(Q,∑, δ. q0, F) where
M – name of the machine
Q- finite set of states
∑- set of input symbols
δ – transition function δ: Qx∑ → 2Q
q0- a start state
F- Set of final states

6. Define string.

Sequence of symbols obtained from the alphabets of a language is called a string.

7. What is the length of a string?


The length of a string is the number of symbols in the string.

8. Define language.

A language is defined as a set of strings obtained from ∑* where ∑ is the set of


alphabets of a particular language.

9. Define transition function for DFA.


The transition function δ: Q x ∑ → Q specifies the state into which the machine will
move, on the basis of current state and the symbol it reads. Symbolic
representation is δ ( qi, a) = qj, which says that there is a transition from the state qi
to qj when the machine reads the symbol “a”.
10. Define transition function for NFA.

The transition function δ : Q x ∑ → 2Q, specifies the state into which the machine
will move, on the basis of current state and the symbol it reads. Symbolic
representation is δ ( qi, a) = {qj,qk} which says that there is a transition from the state
qi to {qj, qk} when the machine reads the symbol “a”.
11. What do you mean by transition in a finite automaton?

Transition is nothing but change of state after consuming an input symbol.


12. How a DFA processes strings?

At first input pointer points to the first cell of the tape pointing to the string to be
processed. After scanning the current input symbol, the machine may enter in to any
one of the states and the pointer moves one cell towards right. When the end of the
string is encountered, the string is accepted iff the automaton will be in one of the
final states.

13. Define trap state.


Trap state is a non-final state of a finite state machine, whose transitions on every
input symbol terminates on itself.

14.What is the difference between DFA and NFA?

DFA NFA
There can be zero or one There can be zero , one or more
transition from a state on an transition from a state on an
input symbol input symbol
More number of transitions Less number of transitions
Difficult to construct Easy to construct
Less powerful More powerful than DFA

15. What is the need of NFA?


An NFA is an efficient mechanism to describe some complicated languages concisely
and has the power to be in several states at once. So NFA is needed in such cases.
16. Design a DFA to accept one “a” or one “b”.

17. Design a DFA to accept any number of a’s.

18. Give an example of a finite automaton.

Traffic light modeling, vending machine, ATM machine.


19. Define NFA with  transition.

An NFA with zero or more ∈ transitions is called a ∈ - NFA.


20. When a string is said to be accepted by NFA with  transition?

A string is said to be accepted by NFA-∈, if at least one path exists that starts at the
initial state and ends in one of the final state. The path formed contains states with
transitions from ∈- transitions or non ∈-transitions.
Assignment 2 – unit 1 – Automata- 16 mark questions

1. Obtain a DFA to accept strings of a’s and b’s starting with the string ab.
2. Obtain a DFA to accept strings of a’s and b’s ending with the string abb.
3. Obtain a DFA to accept strings of a’s and b’s that do not end with the string abb.
4. Obtain a DFA to accept strings of a’s and b’s having a sub string aab.
5. Obtain a DFA to accept strings of 0’s and 1’s having 3 consecutive zeros.
6. Obtain a DFA to accept strings of a’s and b’s such that


L  awa / w  a  b  where n  0
n

7. Obtain a DFA to accept strings of a’s and b’s ending with ab or ba.
8. Obtain a DFA to accept a string of 0’s, 1’s and 2’s beginning with “0” followed by odd
number of 1’s and ending with a “2”.
9. Obtain a DFA to accept strings of a’s and b’s having even number of a’s and even
number of b’s.
10. Obtain a DFA to the language L={w: na(w) ≥ 1; nb(w) =2 }
11. Obtain a DFAto accept the language L= {w: w has odd number of 1’s followed by
even number of 0’s}.
12. Design a finite automaton that accepts sets of strings such that every string ends in 00
over alphabet ∑ = {0,1}.
13. Design a finite automaton that accepts sets of strings where the number of 0’s in every
string is a multiple of three over alphabet ∑= {0, 1}.
14. Design a finite automatonthat accepts sets of strings containing exactly four 1’s in
every string over ∑ = {0,1}.
15. Obtain an NFA to accept the following language

L  {w / w  abab n or aba n n  0}

16. Obtain an NFA to accept strings of a’s and b’s ending with ab or ba.
17. Obtain the DFA for the following NFA

18. Convert the following NFA to its equivalent DFA


19. Design an  NFA –that accepts the string with any number of a’s
followed by any number of b’s followed by any number of c’s.
20. Design an NFA  - that accepts the set of strings over ∑ = {0, 1} which
start and end with 0.

You might also like