0% found this document useful (0 votes)
64 views

Chapter1 FLAT Module 1

This document discusses finite automata including conceptual views, requirements, sets, graphs, languages, star and plus closures, and deterministic and nondeterministic finite automata. Finite automata have an input tape, read head, and finite controller. Deterministic finite automata have a well-defined transition function while nondeterministic finite automata transitions are not dependent on the number of input symbols.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Chapter1 FLAT Module 1

This document discusses finite automata including conceptual views, requirements, sets, graphs, languages, star and plus closures, and deterministic and nondeterministic finite automata. Finite automata have an input tape, read head, and finite controller. Deterministic finite automata have a well-defined transition function while nondeterministic finite automata transitions are not dependent on the number of input symbols.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Finite Automata

Chapter1
FINITE AUTOMATA
Finite automata are basic modules of a computer system, which addresses simple real time problems.
Figure 1.1 shows conceptual view of finite automata. It has an input tape, read head and finite controller.
Input tape is divided into finite cells and each cell stores one input symbols. Read head is used to read the
input symbol from the input tape. The finite controller used to record the next state of finite automat.

Figure 1.1: Conceptual view of finite automata


Before discussing finite automata in detail, it is very much important to know the basic requirement for
the finite automata. They are
i. Sets.
ii. Graphs.
iii. Languages.
iv. Star closure.
v. Plus closure.
Sets (S):
A set is collection of elements, each element has its own identity. A set can be represented by
enclosing its elements in curly braces. for example, the set of small letters a, b, c is shown as
S= {a, b, c}
Set {2, 4, 6,…} denotes the set of all positive even integers. we can use more explicit notation, in
which we write
S={i | i is > 0 and is even}
We can perform following operations on sets, they are
a. union (∪),
b. intersection (∩), and
c. difference (−)
d. complementation defined as
S1 U S2 = {x | x ϵ S1 or x ϵ S2}
S1 Ո S2 = {x | x ϵ S1 and x ϵ S2}
S1 - S2 = {x | x ϵ S1 and x S2}
The complement of a set S, denoted by Ṡ consists of all elements not in S. To make this meaningful,
we need to know what the universal set U of all possible elements is. If U is specified, then
Ṡ={x | x ϵ U, x S}
The set with no elements, called the empty set or the null set, is denoted by ɛ. From the definition of a set,
it is obvious that

Page 1.
1
Finite Automata

S U ɛ = S - ɛ =S
SՈɛ=ɛ
ἕ= U
De Morgan's laws: The following useful identities, known as De Morgan's laws.

are needed on several occasions.


Subset and Proper Subset: A set S1 is said to be a subset of S, every element of S1 is also an element of
S. We write this as S1 ⊆ S. If S1 ⊆ S, but S contains an element not in S1, we say that S1 is a proper subset
of S; we write this as S1 ⊂ S.
Disjoint Sets: If S1 and S2 have no common element, that is, S1 ∩ S2 = ɛ then the sets are said to be
disjoint.
Finite and Infinite sets: A set is said to be finite if it contains a finite number of elements; otherwise it is
infinite. The size of a finite set is the number of elements in it; this is denoted by |S|.
Power- Set: A given set has many subsets. The set of all subsets is called the power-set and is denoted by
2s. Observe that 2s is a set of sets.
If S is the set {a, b, c}, then its powerset is
2s= {ɛ,{a}, {b}, {c}, {a, b},{b, c},{a, c}, {a, b. c}}
Here |S| = 3 and |2s| = 8.
Cartesian product: Ordered sequences of elements from other sets are said to be the Cartesian product.
For the Cartesian product of two sets, which itself is a set of ordered pairs, we write
S= S1 x S2
Let S1 = {2, 4} and S2 = {2, 3, 5, 6}. Then S1 × S2 = {(2, 2), (2, 3), (2, 5), (2, 6), (4, 2), (4, 3), (4, 5), (4,
6)}. Note that the order in which the elements of a pair are written matters. The pair (4, 2) is in S1 × S2,
but (2, 4) is not.
Graphs:
A graph is a construct consisting of two finite sets, the set V = {υ1, υ2,…, υn} of vertices and the set E =
{e1, e2,…, em} of edges. Each edge is a pair of vertices from V, for instance,

ei=(v, vj).

Languages:

A finite, nonempty set of symbols are called the alphabet and is represented with symbol ∑. From the
individual symbols we construct strings, which are finite sequences of symbols from the alphabet. For
example, if the alphabet ∑ = {0}, then ∑* to denote the set of strings obtained by concatenating zero or
more symbols from ∑.

We can write ∑*= {ɛ, 0, 00, 000 …}


Page 1.
2
Finite Automata

If ∑ = {0, 1}
0 and 1 are input alphabets or symbols, then:
(02=00, 03=000, 12=11, 13=111, where as in mathematics they are numbers 02=0, 12=1)
L=∑*={ ɛ, 0, 1, 00, 01, 10, 11, 000, 001, 010 ……….}

Kleen closure(*closure):
*closure = {∑0U∑1U∑2U∑3 ………}
∑0={ ɛ} ∑1={0, 1} ∑2={00, 01, 10, 11}
∑3={000, 001, 010, 011, 100, 101, 110, 111}
Therefore ∑*={ ɛ , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, 100, 101,……}
+
Closure on ∑ = {0, 1}
∑+= {∑1U∑2U∑3…}
∑*=∑+ + ɛ

Therefore ∑+=∑*- ɛ
Formal Languages and Automata Theory: IT is a mathematical model used to design computer
programs and sequential logic circuits. It is state machines which captures and makes transition to
accept or reject.
Finite automata has input tape, read head and finite controller Input tape: It is divided into finite cell and
each cell is used to store one input symbol. Read head: Read head is used to read input symbol from
input tape. Finite Controller: Finite controller records, the transition to next state. The default value of
finite controller is initial state q0. States are represented with circles; they are of three types,

Figure 1.2: Different types of states used in finite automata


States are connected by lines called transition. It has two ends, one end is called initiation point and the
other end is called termination point (>).

Initiation Termination

The combination of transitions and states is called a transition diagram.

Figure 1.3: A typical transition diagram

Figure 1.4 shows a transition diagram to map cities and their roads.

Page 1.
3
Finite Automata

Figure 1.4: Finite automata with real time example.


Finite Automata are classified into two types. They are:
1) Deterministic Finite Automata (DFA)
2) Non Deterministic Finite Automata (NFA)
In Deterministic Finite Automata number of outgoing transitions are well defined from each state
depending upon input symbols. For example, if there is one Input symbol, then you find one outgoing
transition from each state, for two input symbols two outgoing transitions are present and so on.

Example 1.1: Draw the DFA, the input symbol is ∑= {0}

Figure 1.5: DFA’s for input symbol ∑= {0}.

Example 1.2: Draw the DFA, the input symbol is ∑= {0, 1}

Figure 1.6: DFA’s for input symbol ∑= {0, 1}.


Definition of DFA: we define DFA as,

MDFA = (Q, ∑, δ, Initial state, Final state)

Where, Q is set of states, ∑ =set of input symbols, δ: transition function is

From the table 1.

Q={q0,q1,q2} ∑ ={a, b, c}

δ:
δ (q0, a)=q1 δ (q0,b)=q0 δ (q0,c)=q2
δ (q1,a)=q1 δ (q1,b)=q2 δ (q1,c)=q0
δ (q2,a)=q2 δ (q2,b)=q1 δ (q2,c)=q2
Note: Initial State is q0 and final state is q2

Page 1.
4
Finite Automata

Table 1.1: Transition table

Q\∑ a b c

q0 q1 q0 q2

q1 q1 q2 q0

*q2 q2 q1 q2

Nondeterministic Finite Automata (NFA):

If outgoing transitions are not dependent on number of input symbols, then such automata are called as
Nondeterministic Finite Automata.

For example: ∑ = {0, 1}

Figure 1.7: Nondeterministic Finite Automata for ∑ = {0, 1}

There is no outgoing transition from initial state, for a symbol ‘1 ‘and similarly there is no outgoing
transition from final state for ‘0’.

Transition Function for string:

Note: 1) δ is the transition function, used for symbols.

2) For the string (Set of symbols), is used

{}=ɛ

{a}=a

(q0, ɛ)= q0 //q0 is reading empty string, string is empty therefore, transition to same state q0.

(q0, a)= (q0, ɛa)= δ ( (q0, ɛ),a)= δ (,a)

Therefore (q0, a)= δ (q0, a)

Therefore for single symbol string =δ

(q0, wa)

Where ‘w’ is the multi-symbol string and ‘a’ is a symbol, hence we separate the transition function for
strings and symbols as given below:

δ( (q0, w), a)

Page 1.
5
Finite Automata

Example 1.3: Write a transition table for a DFA shown in figure 1.8.

DFA over alphabet ∑ = {a, b}

Figure 1.8: Transition diagram o0f a DFA.

Table 1.2: Transition table for the figure 1.8

MDFA =(Q, ∑, δ , IS, FS)


Q ={ q0, q1}
∑ ={a ,b}
δ (q0, a) =q1 S δ q0,b) =q0
δ (q1, a) =q1 δ (q1, b) =q0
IS =q0 FS={q0}
Example 1.4: Construct transition table for the diagram shown in figure 1.9, over the alphabet ∑={0, 1, 2}

Figure 1.9: Transition diagram

Table 1.3: Transition table for the figure 1.9

We can define above DFA as: MDFA=(A, ∑, δ, IS, {FS})

δ:
δ (A0, 0)=A1 δ (A0, 1)=A2 δ(A0, 2)=A0
δ (A1, 0)=A2 δ (A1, 1)=A0 δ(A1, 2)=A1
Page 1.
6
Finite Automata

δ (A2, 0)=A2 δ (A2, 1)=A1 δ(A2, 2)=A0

A ={A0,A1,A2}; ∑ ={0,1,2}; IS=A0; FS=A2


String Acceptance:
The first symbol of string begins with initial state. Later, traverses zero or more than zero intermediate
state(s) for the intermediate symbol(s). Finally last symbol of the string ends with final state of automata.
This is called string accepted or otherwise string is not accepted.

Example 1.5: Find out whether the given string is accepted by the DFA. Assume the string as abab.
From the given string ∑ = {a,b} . Note that always string is traversed by left side to right side,

Figure 1.10: Transition diagram for example 1.5.

(q0, a)= δ (q0, a)= q 2 1

(q0, ab)= δ ( (q0, a) b ) from 1 (q0, a)= q2

= δ (q2, b) =q3 2
(q0, aba)= δ( (q0, ab), a) from equation 2 (q0, ab)= q3
= δ(q3, a)=q1
(q0, abab)= δ( (q0, aba), b)
= δ( (q1, b)= q0
Given string is accepted by a DFA.

Example 1.6: Find out the language accepted by the DFA.


Page 1.
7
Finite Automata

Figure 1.12: Transition diagram of Example 1.6.

δ (q0, a)=q1; (q0, aa)= δ ( (q0, a),a)= δ (q1, a)= q1

L={a, aa, ba, baa, aba, …..}

In general we can write:

L= {w |w is a string ending with symbol a}

Example 1.7: Find out the language accepted by the DFA.

Figure 1.13: Transition diagram of Example 1.7

Initial state is also a final state, hence it accept empty string ɛ.

(q0, ɛ)=q0;

(q0, aa)= δ( (q0, a)a)= δ(q2, a)=q0;

(q0, bb)= δ( (q0, b)b)= δ(q1, b)=q0;

Therefore language L={ ɛ, aa, bb, aabb, abab…}

In general we can write L={w |w is a string consist of even number of a’s and even number of b’s}

Design of DFA :

Example 1.8: Design a DFA which accept all the strings ends with symbol a over the alphabet ∑={a, b}.

L={a, aa, ba, aba, bba…}

i. Draw the NFA for the smallest string a of the language.


The NFA for the string a is

Figure 1.14 : NFA for the string a

Page 1.
8
Finite Automata

Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for symbol ‘a’
another for ‘b’. From initial state only one outgoing transition on symbol ‘a’, one more outgoing
transition is required that is on ‘b’. If the condition in the given problem ends with, the outgoing
transition on the other symbol b, definitely loop to a initial state.

Figure 1.14: second outgoing transition from state q0

Figure 1.15 : q0 is termination for symbol b and q1 is termination for symbol a

Termination state for symbol ‘a’ is q1 and for ‘b’ it is q0. Outgoing transition from q1 on
symbol ‘a’ is loop, and for ‘b’ it is to q0 .

Figyre 1.16 :DFA which accept all the strings ends with a.

We can define above DFA as MDFA =(Q, ∑, δ , IS, {FS})


Q ={ q0, q1}
∑ ={a , b}
δ (q0, a) =q1 δ (q0,b) =q0
δ (q1, a) =q1 δ (q1, b) =q0
IS =q0 FS={q1}
Example 1.8: Design a DFA which accept all the strings ends with substring 01 over the alphabet

∑={0, 1}.

L={01, 001, 101, 0001,1001…}.

i. Draw the NFA for the smallest string 01 of the language.


The NFA for the string 01 is

Figure 1.17: NFA for the string 01.

ii. Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘0’ another for ‘1’. From initial state only one outgoing transition on symbol ‘0’, one

Page 1.
9
Finite Automata

more outgoing transition is required that is on ‘1’. If the condition in the given problem is,
ends with, the outgoing transition on the other symbol 1, definitely loop to a initial state.

Figure 1.18 : conversion of NFA state A0 to DFA

Figure 1.19 : A0 is termination for symbol 1 and A1 is termination for symbol 0

Termination state for symbol ‘0’ is A1 and for ‘1’ it is A0. Outgoing transition from A1 on
symbol ‘0’ is loop. From A2 on symbol ‘0’ to A1 and on symboll ‘1’ to A0.

Figyre 1.20 :DFA which accept all the strings ends with 01.

We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})


A={ A0, A1, A2}; ∑={0, 1}
δ:
δ (A0, 0)=A1 δ (A0, 1)=A0
δ (A1, 0)=A1 δ (A1, 1)=A2
δ (A2, 0)=A1 δ (A2, 1)=A0
IS=A0; FS=A2
Example 1.9: Design a DFA which accept all the strings ends with substring 012 over the alphabet

∑={0, 1, 2}.

L={012, 0012, 1012, 00012,10012…}.

i. Draw the NFA for the smallest string 012 of the language.
The NFA for the string 012 is

Figure 1.21: NFA for the string 012.

ii. Convert all states of NFA to DFA, that is from each state three outgoing transitions, one for
symbol ‘0’ second for ‘1’ third from ‘2’. From initial state only one outgoing transition on
symbol ‘0’, two more outgoing transitions are required that is on ‘1’ and ‘2’. If the condition

Page 1.
10
Finite Automata

in the given problem ends with, the outgoing transition on the other symbols ‘1’and ‘2’,
definitely loop to a initial state.

Figure 1.22: conversion of NFA state A0 to DFA state.

Figure 1.23: A0 is termination for symbol 1, 2 and A1 is termination for symbol 0

Termination state for symbol ‘0’ is A1 and for ‘1’ and ‘2’ is A0. Outgoing transition from A1 on
symbol ‘0’ is loop and for’2’ is A0. From A2 on symbol ‘0’ to A1 and on symbol ‘1’ to A0. From
A3 on symbol ‘0’ to A1 and on symbols ‘1’ and ‘2’ to A0.

Figure 1.24 :DFA which accept all the strings ends with 012.

We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})


A={ A0, A1, A2, A3}; ∑={0, 1, 2}
δ:
δ (A0, 0)=A1 δ (A0, 1)=A0 δ(A0, 2)=A0
δ (A1, 0)=A1 δ (A1, 1)=A2 δ(A1, 2)=A0
δ (A2, 0)=A1 δ (A2, 1)=A0 δ(A2, 2)=A3
δ (A3, 0)=A1 δ (A3, 1)=A0 δ(A3, 2)=A0
IS=A0; FS=A3
Example 1.10: Design a DFA which accept all the strings begins with symbol ‘a’ over the alphabet

∑={a, b}.

L={a, aa, ab, abb, aba, aaa…}

i. Draw the NFA for the smallest string a of the language.


The NFA for the string a is

Figure 1.25: NFA for the string a.

Page 1.
11
Finite Automata

Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘a’ another for ‘b’. From initial state only one outgoing transition on symbol ‘a’, one
more outgoing transition is required that is on ‘b’. If the condition in the given problem is,
begin with, the outgoing transition on the other symbol ‘b’, is to new state called dead state.
Dead state: In finite automata the string travers from initial state to final state, in some
situation we make finite automata to die called dead state. Dead state is a non-final state,
from which all outgoing transitions are loop to the same state.

Figure 1.26 : DFA which accept all the string begin with a.
ii. Condition is begin, outgoing transitions from final state is loop.

We can define above DFA as MDFA =(Q, ∑, δ , IS, {FS})


Q ={ q0, q1, q2}
∑ ={a , b}
δ (q0, a) =q1 δ (q0,b) =q2
δ (q1, a) =q1 δ (q1, b) =q1
δ (q2, a) =q2 δ (q2, b) =q2
IS =q0 FS={q1}
Example 1.11: Design a DFA which accept all the strings begins with substring 01 over the alphabet

∑={0, 1}.

L={01, 010, 011, 0100, 0101…}.

i. Draw the NFA for the smallest string 01 of the language.


The NFA for the string 01 is

Figure 1.27: NFA for the string 01.

ii. Convert all states of NFA to DFA, that is from each state two outgoing transitions, one for
symbol ‘0’ another for ‘1’. From initial and intermediate states only one outgoing transition,
one more outgoing transition is required. If the condition in the given problem is, begin with,
the outgoing transition from both the states to new state called dead state.

Page 1.
12
Finite Automata

Figure 1.28 : DFA which accept all the string begin with 01.

iii. Condition is begin, outgoing transitions from final state A2 on symbol ‘0’ and ‘1’ is loop.

We can define above DFA as MDFA=(A, ∑, δ, IS, {FS})


A={ A0, A1, A2 A3}; ∑={0, 1}

δ:
δ (A0, 0)=A1 δ (A0, 1)=A0
δ (A1, 0)=A1 δ (A1, 1)=A2
δ (A2, 0)=A1 δ (A2, 1)=A0
δ (A3, 0)=A3 δ (A3, 1)=A3
IS=A0; FS=A2

Example 1.12: Design a DFA which accept all the strings begins with 01 or ends with 01 or both over the
alphabet ∑={0, 1}.

L={01, 010, 011, 0100, 001, 101, 0001,1001, 0101, 01101…}

We have already designed both the DFAs, joining of these DFAs, is the solution for the given problem.

Figure 1.29: DFA which accept all the string begin with 01.

Figure 1.30: DFA which accept all the string ends with 01.

Page 1.
13
Finite Automata

Figure 1.31: DFA which accept all the string begin with 01, end with 01 begin and end with 01.

Example 1.13: Design a DFA which accept all the binary strings divisible by 2.

L={ ɛ, 10, 100, 110, …}

To design DFA we need to make the following assumptions.

From the above assumption, we can draw the following DFA.

Figure 1.32: DFA which accepts all the strings divisible by 2.

We can define above DFA as MDFA =(Q, ∑, δ , IS, {FS})


Q ={ q0, q1}
∑ ={0, 1}
δ (q0, 0) =q0 δ (q0,1) =q1
δ (q1, 0) =q0 δ (q1, 1) =q1
IS =q0 FS={q0}
Example:

Example 1.14: Design a DFA which accept all the binary strings divisible by 5.

L={ ɛ, 101, 1010, 1111, …}

Figure 1.33: DFA which accept all the strings divisible by 5.

Page 1.
14
Finite Automata

We can define, designed DFA as MDFA=(A, ∑, δ, IS, {FS})


A={ q0, q1, q2 q3, q4} ∑={0, 1}
δ:
δ (q0, 0)=q0 δ (q0, 1)=q1 ; δ (q1, 0)=q2 δ (q1, 1)=q3
δ (q2, 0)=q4 δ (q2, 1)=q0 ; δ (q3, 0)=q1 δ (q3, 1)=q2
δ (q4, 0)=q3 δ (q4, 1)=q4 ;

IS=q0; FS=q0

Example 1.15: Design a DFA which accept string over x, y every block of length 3 contains at least one x.

To design a DFA we need to make following assumptions,

1. If there is no ‘x’ in the string, such a string should not be accepted.

Figure 1.34: NFA which is not accepting three y’s string.

2. One ‘x’ in the string, accepted by finite automata.

Figure 1.35: NFA which is accepting three symbol string in which one symbol is x.

3. The position of A1 and A5 is same as A0 and A4. In between A0 and A4 the symbol is ‘x’,
inbetwwen A1 and A5 is also x and so on.

Figure 1.36: DFA which accept string over x, y if every block of length 3 contains at least one x.

We can define designed DFA as MDFA=(A, ∑, δ, IS, {FS})


A= { A0, A1, A2, A4, A4, A5, A6} ∑={x, y}
δ:
δ (A0, x)= A4 δ (A0, y)= A1 ; δ (A1, x)=A5 δ (A1, y)=A2
δ (A2, x)=A6 δ (A2, y)=A3; δ (A3, x)=A3 δ (A3, y)=A3
δ (A4, x)=A5 δ (A3, y)=A5; δ (A5, x)=A6 δ (A5, y)=A6 ;

Page 1.
15
Finite Automata

δ (A6, x)=A4 δ (A6, y)=A1

IS=A0; FS={ A6}

Example 1.16: Design a DFA which accept even number of r and even number of s over the symbol ∑={r,
s}.

i. Draw separate DFA, one accept even number of r’s and another one accept even number of
s’s.

Figure 1.37 : DFA’s accept even symbols string over r, s.

ii. Join two DFA, we get four new states AB, AC, BC, BD. Designed DFA accept even number of r
and even number of s, out of four states AB satisfied this condition, hence this state is a final
state.

Figure 1.38: DFA which accept even number of r and s.

We can define designed DFA as MDFA=(State, ∑, δ, IS, {FS})


State={ AC, AD, BC, BD} ∑={r, s}
δ:
δ (AC, r)= BC δ (AC, s)= AD ; δ (BC, r)=AC δ (BC, s)=BD
δ (AD, r)=BD δ (AD, s)=BD; δ (BD, r)=AD δ (BD, s)=BC

IS=AC; FS={ AC}


Example 1.17: Design a DFA which accept all the strings described by the language L={N0(w)≥ 1 and
N1(w)=2}

i. Exchange I symbol of first string with the last symbol of the first string, the string obtained is
the second string of the language.
ii. Draw NFA for two smallest strings, for both NFA initial and final states are same.

Page 1.
16
Finite Automata

Figure 1.39: Two DFAs for the string 011 and 110 with same initial and final state.

Figure 1.40: DFA which accept all the strings described by the language L={N0(w)≥ 1 and N1(w)=2}.

We can define designed DFA as MDFA=(A, ∑, δ, IS, {FS})


A={ A0, A1, A2 A3, A4, A5, A6} ∑={0, 1}
δ:
δ (A0, 0)=A1 δ (A0, 1)=A4 ; δ (A1, 0)=A0 δ (A1, 1)=A2
δ (A2, 0)=A2 δ (A2, 1)=A3 ; δ (A4, 0)=A2 δ (A4, 1)=A5
δ (A5, 0)=A3 δ (A5, 1)=A6 ; δ (A6, 0)=A6 δ (A6, 1)=A6

IS=A0; FS={A3}

Nondeterministic Finite Automata (NFA)

In DFA the outgoing transitions are defined in advance, where as in NFA the outgoing transitions are not
defined in advance. In DFA, the string is either accepted or not accepted, where as in NFA both are
possible. The finite automata shown in the figure 1.41 is a NFA. There is no outgoing transition for the
symbol ‘a’ from the state q1.

Figure 1.41: Nondeterministic Finite Automata

We can define above NFA as MDFA =(Q, ∑, δ , IS, {FS})


Q ={ q0, q1,}
∑ ={a , b}
δ:

δ (q0, a) =q1 δ (q0,b) =q0


δ (q1, b) =q0
δ (q2, a) =q2 δ (q2, b) =q2
IS =q0 FS={q1}

Page 1.
17
Finite Automata

The NFA shown in figure 1.42 is, accepting as well as not accepting the string hod.

Figure 1.42:Non-deterministic finite automata

Example 1.18: Design NFA which accept all strings, if second symbol from right side is 1 over the
alphabet ∑={0, 1}.

L={ 10, 110, 010, 0110…}

i. First step draw the final state.

Figure 1.43: Final state

ii. Draw the intermediate state and transition for the symbols ‘0’ and ‘1’.

Figure 1.44: Intermediate and final states

iii. Draw the initial state and transition for the symbol ‘1’.

Figure 1.45: Non-deterministic finite automata accepting two strings 10, 11.

iv. Designed NFA has to accept all the strings, if second symbol from right side is symbol ‘1’, to
do this, mark loop to initial state on symbols ‘0’ and ‘1’.

Figure 1.46: NFA which accepts all strings, if second symbol from right side is 1 over the alphabet ∑={0, 1}.

v. Name the states and stop.

Figure 1.47: NFA which accept all strings, if second symbol from right side is 1 over the alphabet ∑={0, 1}.

Page 1.
18
Finite Automata

Definition of NFA: NFA can be defined as

MDFA =(Q, ∑, δ , IS, {FS})


Q ={ q0, q1, q2}
∑ ={0, 1}
δ:
δ (q0, 0) =q0 δ (q0,1) ={q0, q1}
δ (q1, 0) =q2
δ (q1, 1) =q2
IS =q0 FS={q2}

Equivalence of NFA and DFA:

We have already seen both NFA and DFA, both are same in the definition but they differ in transition
function. If number of states in NFA has two states q0 and q1. Here, q0 is initial state and q1 is final state.
The equivalent states in DFA’s are [q0], [q1] and [q0, q1]. Where q0 is initial state and (q1), (q0, q1) are the
final states. The pair (q0, q1) is final state because; one of its states is final state. They are represented as
shown in figure 1.48

Figure 1.48: Equivalence states of NFA and DFA.

Example 1.19: Convert the NFA shown in figure 1.49 into its equivalent DFA.

Figure 1.49: Non-deterministic finite automata of Example 1.19.

The conversion begins with the initial state of the NFA which is also an initial state of DFA. Conversion
generates number of new states, for every new state we are finding the outgoing transitions for
different symbols.

Table 1.4: Different tables for the conversion of NFA to DFA.

Page 1.
19
Finite Automata

No further new states; mark the final state of DFA. Any pair of state which consists of final state of the
NFA, the particular pair is a final state in DFA.

Figure 1.50: Equivalence DFA of figure 1.49

Application of Finite automata:

Finite automat is used to search a text. There are two methods used to search text, they are:

i. Nondeterministic Finite Automata(NFA)


ii. Deterministic Finite Automata(DFA)

To search a text “shine” and “hire” the NFA shown in figure 1.51 is used

The input alphabets are ∑={s, h, i, n, e, r }

Figure 1.51: NFA used to search strings shine and hire

To search a text “shine” and “hire” the DFA shown in figure 1.52 is used

Page 1.
20
Finite Automata

Figure 1.52: DFA used to search strings ending with shine and hire

Example 1.20: Design a finite automata, that reads string made up of letters HONDA, and recognize
those string that contain the word HOD as a substring.

i. Find out the alphabet from the string HONDA. The input symbols are ∑={H, O, N, D, A}
ii. Draw the NFA for the substring HOD.

Figure 1.53: NFA used to search string HOD

iii. Convert NFA state of figure 1.53 into DFA states.

Figure 1.54: DFA accept all the strings ends with HOD over the symbols {H, O, N, D, A}

NFA with ɛ-transition:

Till now whatever automata we studied were characterized by a transition on the symbols. But there are
some finite automata having transition for empty string also, such NFAs are called NFA- ɛ transition.

ɛ-closure (q0): states which are closed / related to state q0 on empty transition(ɛ) is called ɛ-closure (q0).

In DFA and NFA (q0, ɛ)=q0, where as in ɛ-NFA

i. (q, ɛ)= ɛ-closure( (q, ɛ))= ɛ-closure(q).


ii. (q, x)= ɛ-closure(δ( (q, ɛ), x)= ɛ-closure(δ(ɛ-closure(q), x).
iii. (q, wx)= ɛ-closure(δ( (q, w), x).

Example 1.21: Find out ɛ-closure of all the states of ɛ-NFA shown in figure 1.55.

Page 1.
21
Finite Automata

Figure 1.55: NFA with ɛ-transition of Example 1.21.

Figure 1.56: ɛ-closure of all the states of figure 1.55

Example 1.22: Convert the ɛ-NFA shown in figure 1.57 into NFA

Figure 1.57: ɛ-NFA of Example 1.22.

First find out the ɛ-closure of all the states.

Note: state ɛ-closure consist of final state of ɛ-NFA, the particular state is a final state in NFA.

(q0, 0)= ɛ-closure(δ( (q0, ɛ), 0).

= ɛ-closure(δ({q0q1}, 0).

= ɛ-closure(δ(q0, 0) U δ(q1, 0)).

=ɛ-closure(q0 U q2).

=ɛ-closure(q0) U ɛ-closure(q2).

={q0q1} U {q0q1q2}

={q0q1q2}

(q0, 1)= ɛ-closure(δ( (q0, ɛ), 1).

= ɛ-closure(δ({q0q1}, 1).

= ɛ-closure(δ(q0, 1) U δ(q1, 1)).

Page 1.
22
Finite Automata

=ɛ-closure(q0 U φ).

=ɛ-closure(q0) U ɛ-closure(φ).

={q0q1}

(q1, 0)= ɛ-closure(δ( (q1, ɛ), 0).

= ɛ-closure(δ(q1, 0)).

= ɛ-closure(q2).

={q0q1q2}

(q1, 1)= ɛ-closure(δ( (q1, ɛ), 1).

= ɛ-closure(δ(q1, 1)).

= ɛ-closure(φ).

(q2, 0)= ɛ-closure(δ( (q2, ɛ), 0).

= ɛ-closure(δ({q0q1q2}, 0).

= ɛ-closure(δ(q0, 0) U δ(q1, 0)U δ(q2, 0)).

=ɛ-closure(q0 U q2 U φ).

=ɛ-closure(q0) U ɛ-closure(q2) U ɛ-closure(φ).

={q0q1} U {q0q1q2} U (φ)

={q0q1q2}

(q2, 1)= ɛ-closure(δ( (q2, ɛ), 1).

= ɛ-closure(δ({q0q1q2}, 1).

= ɛ-closure(δ(q0, 1) U δ(q1, 1) U δ(q2, 1)).

=ɛ-closure(q0 U φ U φ).

=ɛ-closure(q0) U ɛ-closure(φ) U ɛ-closure(φ)

=(q0 q1) U (φ) U (φ)

= {q0q1}

Page 1.
23
Finite Automata

Table 1.5: Equivalence table of ɛ-NFA and NFA.

Figure 1.58: NFA without ɛ-transition.

Conversion of ɛ-NFA to DFA:

It is same as conversion of NFA to DFA, begins with initial state of ɛ-NFA.

Example 1.23: Convert the ɛ-NFA shown in figure1.59 into DFA.

Figure 1.59: ɛ-NFA of Example 1.23.

First find out the ɛ-closure of all the states

Table 1.6: Equivalence table of ɛ-NFA and NFA.

(q0, 0)= ɛ-closure(δ( (q0, ɛ), 0).

= ɛ-closure(δ({q0q1}, 0).

Page 1.
24
Finite Automata

= ɛ-closure(δ(q0, 0) U δ(q1, 0)).

=ɛ-closure(φ U q1).

=ɛ-closure(φ) U ɛ-closure(q1).

= φ U q1

=q1

(q0, 1)= ɛ-closure(δ( (q0, ɛ), 1).

= ɛ-closure(δ({q0q1}, 1).

= ɛ-closure(δ(q0, 1)U δ(q1, 1)).

=ɛ-closure(q0U φ).

=ɛ-closure(q0) U ɛ-closure(φ).

={q0q1}U φ

=[q0q1]

(q0, 2)= ɛ-closure(δ( (q0, ɛ), 2).

= ɛ-closure(δ({q0q1}, 2).

= ɛ-closure(δ(q0, 2)U δ(q1, 2)).

=ɛ-closure(φ U q2).

=ɛ-closure(q2).

=[q1q2 ]

(q1, 0)= ɛ-closure(δ( (q1, ɛ), 0).

= ɛ-closure(δ(q1, 0).

= ɛ-closure(q1).

= q1

(q1, 1)= ɛ-closure(δ( (q1, ɛ), 1).

= ɛ-closure(δ(q1, 1).

= ɛ-closure(φ).

Page 1.
25
Finite Automata

= φ

(q1, 2)= ɛ-closure(δ( (q1, ɛ), 2).

= ɛ-closure(δ(q1, 2)

= ɛ-closure(q2)

= [q1 q2]

([q0q1], 0)= ɛ-closure(δ( ([q0q1], ɛ), 0)

= ɛ-closure(δ( (q0, ɛ)U (q1, ɛ)), 0).

= ɛ-closure(δ((q0, q1) U q1), 0)).

= ɛ-closure(δ((q0, q1), 0)).

= ɛ-closure(δ(q0, 0) U δ(q1, 0)).

= ɛ-closure(φ U q1)

= ɛ-closure(q1)

= q1

([q0q1], 1)= ɛ-closure(δ( ([q0q1], ɛ), 1)

= ɛ-closure(δ( (q0, ɛ)U (q1, ɛ)), 1).

= ɛ-closure(δ((q0, q1) U q1), 1)).

= ɛ-closure(δ((q0, q1), 1)).

= ɛ-closure(δ(q0, 1) U δ(q1, 1)).

= ɛ-closure(q0 U φ)

= ɛ-closure(q0)

= [q0, q1]

([q0q1], 2)= ɛ-closure(δ( ([q0q1], ɛ), 2)

= ɛ-closure(δ( (q0, ɛ)U (q1, ɛ)), 2).

= ɛ-closure(δ((q0, q1) U q1), 2)).

= ɛ-closure(δ((q0, q1), 2)).

= ɛ-closure(δ(q0, 2) U δ(q1, 2)).

Page 1.
26
Finite Automata

= ɛ-closure(φ U q2 )

= ɛ-closure(q2)

= [q1 q2]

([q1q2], 0)= ɛ-closure(δ( ([q1q2], ɛ), 0)

= ɛ-closure(δ( (q1, ɛ)U (q2, ɛ), 0)).

= ɛ-closure(δ(q1U (q1 q2)), 0).

= ɛ-closure(δ(q1, q2), 0 )).

= ɛ-closure(δ(q1, 0 ) U δ (q2, 0 ))

= ɛ-closure(q1 U φ).

= ɛ-closure(q1)

= q1

([q1q2], 1)= ɛ-closure(δ( ([q1q2], ɛ), 1)

= ɛ-closure(δ( (q1, ɛ)U (q2, ɛ), 1)).

= ɛ-closure(δ(q1U (q1 q2)), 1).

= ɛ-closure(δ(q1, q2), 1 )).

= ɛ-closure(δ(q1, 1 )U δ (q2, 1 ))

= ɛ-closure(φ U φ).

= ɛ-closure(φ)

([q1q2], 2)= ɛ-closure(δ( ([q1q2], ɛ), 2)

= ɛ-closure(δ( (q1, ɛ)U (q2, ɛ), 2)).

= ɛ-closure(δ(q1U (q1 q2)), 2).

= ɛ-closure(δ(q1, q2), 2)).

= ɛ-closure(δ(q1, 2 )U δ (q2, 2 ))

= ɛ-closure(q2 U φ).

= ɛ-closure(q2)

Page 1.
27
Finite Automata

= [q1 q2]

Table 1.7: Equivalence table of ɛ-NFA and DFA.

( φ, (0,1,2))= φ

Mark the final states, any pair which has a final state of ɛ -NFA the particular pair is afinal state in DFA.

Table 1.7: Equivalence table of ɛ-NFA and DFA .

Figure 1.60: DFA of figure 1.59.

Page 1.
28

You might also like