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

FLAT - UNIT1 - Regulation18

Uploaded by

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

FLAT - UNIT1 - Regulation18

Uploaded by

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

FORMAL LANGUAGES AND AUTOMATA THEORY

UNIT 1: FINITE AUTOMATA: Introduction to formal proof – Additional forms of proof –


Inductive proofs – Basic Definitions – Finite Automaton – DFA&NFA – Finite Automaton
with epsilon moves – Equivalence of NFA and DFA – Equivalence of NDFA’s with and
without epsilon moves – Minimization of DFA.

Introduction:

Formal Language and Automata Theory is based on mathematical computation. These


computations are used to represent various mathematical models.

Working of every process can be represented by means of model. The model can be a
theoretical or mathematical model. The model helps in representing the concept of every
activity.

The different models are,

 Finite Automata
 Pushdown Automata
 Linear Bounded Automata
 Turing Machine

The logic or behavior of such models can be well understood with the help of Proof.

There are three subdivisions in Computation:

1. Automata Theory: Some mathematical model done automatically. This type of study is
called automata theory. Example: Calculator and Computer perform the task
automatically.

2. Computability Theory: All problems have not solved by all devices. Each device has some
limitations. In this model, we have to study the problem has been solved or not.

3. Complexity Theory: Different ways are used to solve a particular problem/task. This type
of study is used to select one of the efficient ways and to measure the efficient of that
model that is if a problem is possible to solve, how much time or space has taken.

The combination of the above three theories can be studied in computation.

1
The different models are,

 Finite Automata
 Push Down Automata
 Turing Machine

Automata Theory:
Automata theory is the base of computation. The automata theory has four models.
The authors were proposed many models but some of them were implemented.

i) Finite Automata(FA):
Finite means limited amount of memory and process. Automata describe the process
has perform automatically. Finite automata (automaton- singular) are the simplest type of
abstract machine, also called Finite State Machine (FSM). It can solve problem without
memory. Example, Automated door in shopping mall.

with limited memory. It is used to


construct lexical analyzer of a compiler.
There is no external memory. They use
limited internal memory. It recognizes
only regular language.
Yes – someone stand in front of the
door
No – No one stand in front of the door

FSM is developed in 1950’s by


Robin and Scott as model of computer

ii) Push Down Automata (PDA):

PDA is finite automata with extra memory,


called stack. It is used to construct syntax
analyzer of the compiler. It recognizes
context free languages. PDA has more
capable than FSM, but less capable then
Turing Machine.

iii) Linear Bound Automata (LBA): This model overcomes the previous one. The PDA has not
possible of random element selection. The LBA has finite length of tape as a memory unit,
2
which can be divided into number of cells. Elements can be stored in each cell. We can
move left and right-side direction, but in PDA, it is not possible. It recognizes context
sensitive language. The disadvantage of this model,tape size is limited and finite size.

iv) Turing Machine (TM): Alan Turing, British mathematician developed TM is more powerful
than other models. It has infinite amount of Tape (auxiliary) memory accessible in both
directions that is left or right. Itrecognizes recursive enumerable languages. Turing
machine can solve all type of problems as computer performs the task in now days. If a
function not computable by TM, it can’t be computed even by digital computer.

Applications of Automata Theory:


 In switching theory of circuit design
 Robotics
 Artificial Intelligence
 Compiler constructions
 Design of editors
 Natural language processing
 Knowledge based systems

Introduction of Formal Proof:


Normally, the truth of a statement is solved by a detailed sequence of steps and
reasons. Testing programs is very essential because you cannot try your program on every
input. More complex programs are solved by recursion or iteration.
To make our iteration or recursion correct, it is needed to set up an inductive
hypothesis and it is helpful to reason, formally or informally, that the hypothesis is
consistent with the iteration or recursion. In addition to giving you models that are useful
for certain types of software, it has become traditional for a course on automata theory to
cover methodologies of formal proof.
Automata theory plays an important role in solving proofs both by deductive (a
sequence of justified steps) and the inductive (recursive proofs of a parameterized
statement that use the statement itself with “lower” values of the parameter).

Formal proof is the proof in which we try to prove that statement B is true
because statement A is true, where statement A is called Hypothesis and
statement B is called Conclusion statement. If A then B means we say that B is
deduced from A.

Several methods of formal proof:


1. Deductive Proofs
3
2. Reduction to Definitions
3. Other Theorem forms
4. Theorems that appear not to be if-then statement
1. Deductive Proofs:
A deductive proof consists of a sequence of statements whose truth leads us from
some initial statement, called the hypothesis or the given statement(s), to a conclusion
statement.Each step in the proof must follow, by some accepted logical principle, from either
the given facts or some of the previous statements in the deductive proof, or a combination of
these.
The hypothesis may be true or false, typically depending on values of its parameters.
Often, the hypothesis consists of several independent statements connected by a logical AND.
The theorem that is proved when we go from a hypothesis H to a conclusion C is the
statement“if H then C”. We say that C is deduced from H.

Theorem: If x ≥ 4, then 2x≥ x2


Proof:
The hypothesis H is “x ≥ 4”. This hypothesis has a parameter x and thus is neither true
nor false. Rather, its truth depends on the value of x:
Example: H is true x= 6 and false for x = 2
The conclusion C is “2x≥ x2”. This statement also uses parameter x and is true for
certain values of x and not others.
Example: C is false for x = 3, since 23 = 8, which is not as large as 32 = 9.
On the other hand, C is true for x = 4, since 24 = 42 = 16
For x = 5, the statement is also true, since 25 = 32 is at least as large as 52 = 25.
Perhaps you can see the intuitive argument that tells us the conclusion 2x ≥ x2 will be true
whenever x ≥ 4. We already saw that it is true for x = 4.
As x grows larger then 4, the left side, 2x doubles each time x increases by 1.
However, the right side, x2, grows by the ratio ((x+1)/x)2. If x ≥ 4, then (x+1)/x cannot be
greater than 1.25 and therefore [(x+1)/x]2= (1.25)2 = 1.5625
Since 1.5625 < 2, each time x increases above 4 the left side 2 x grows more than the right side
x2. Thus, as long as we start from a value like x= 4, the inequality 2x≥ x2 is already satisfied.

2. Reduction to Definitions:
If the hypothesis does not use familiar terms like integer, multiplication, addition etc., then we
can convert all terms in the hypothesis to their definitions.
Theorem: A set S is finite. If there exists an integer n such that S has exactly n elements. |s|
= n, where n denotes the number of elements in the set S. If S and T are both subsets of
some infinite set U, then T is the complement of S(with respect to U) if SUT = U and S ∩ T =
Ф. Then T is infinite.

4
Proof: We can use proof by contradiction. It is a technique where we assume that the
conclusion is false. Then use that assumption together with hypothesis, prove the opposite of
one of the given statements of the hypothesis. So, the only possibility that remains is that the
conclusion is true whenever the hypothesis is true.
Here T is finite (because we assume the conclusion is false), but T is infinite (Given).
Let us assume T is finite, along with the statement of the hypothesis, S is finite.
ie.,|S|= n for some integer n.
|T|= m for some integer m.

S U T= |S| ∪ |T| = n + m, n + m is a integer it follows U is finite. But it


Now given statement tells us that,

contradicts the given statement U is infinite.


So, the conclusion is true whenever the hypothesis is true. Therefore, T is
infinite.
3. Other Theorem Forms:
3.1. If – then: the most common forms of if-then statement are if H then C can be rewritten
as,
(i) H implies C
(ii) H only if C
(iii) C if H
(iv) Whenever H holds, C follows or “if H holds, then C follows” or “whenever H
holds, C holds”
Example: Consider the statement, “For every n ≥ 1, i*2i< n * 2n+1 can be rewritten as,
n
n>= 1 implies ∑ i∗2 < n∗2
i n+1

1

n
n>= 1 only if ∑ i∗2 < n∗2
i n+1

1

n
 ∑ i∗2i< n∗2n+1 if n ≥1
1

n
 ∑ i∗2i< n∗2n+1 if n ≥1 follows
1

“If H then C” could appear as H C


3.2. If – and – only – if statements: The statements of the form “A if and only if B“or “A iff
B” , “A is equivalent to B” or “ A exactly when B”.

In formal logic, the operators ⟷or ≡ to denote an “if – and - only – if” statement.
This statement is actually two if-then statements: “if A then B “and “if B then A”

A if and only if B, appear as A ⟷ B or A


≡B

5
Theorem: Let x be a real number. Then |x| =⌈x⌉if and only if x is an integer.

⌈x⌉, ceiling of real number x, is the least integer equal to or greater than x]
[Note: |x|, floor of real number x, is the greatest integer equal to or less than x.

Proof:

⌈x⌉≥ x by definitions of ceiling ----------- 2


|x| ≤ x by definition of floor -------------- 1

We are given with,|x| =⌈x⌉

⌈x⌉≤|x|
Substituting 1 in 2, we get

Since ⌈x⌉≥ x, by arithmetic inequality, we get ⌈x⌉=x


4. Theorems that appear ’Not’ be ‘if – then’ statement:
Sometimes, a theorem that appears not be having a hypothesis.
Example:Trigonometry
Theorem: sin2ɵ + cos2ɵ = 1
It does not have any hypothesis. This theorem can be written in if-then is, “ if ɵ is an
angle, then sin2ɵ + cos2ɵ = 1”.

Additional Forms of Proof:


The following are the additional forms of proofs.
1. Proofs about sets
2. Proofs by Contradiction & Contrapositive
3. Proofs by counter example.
1. Proofs about sets:
Sets constructed in two different ways:
(i) A set contains symbols to form character strings.
(ii) Sets in automata theory are called as languages.
If E & F are two expressions representing sets, the statement E = F means that two sets
represented are same. ie., every element in the set represented by E is in the set represented
by F and vice versa.
Example Union of sets obeys commutative law. Let S and R be sets. Then R ꓴ S = S ꓴ R.
If E is the expression in R ꓴ S and F is the expression in S ꓴ R, then
E = F, an element x is in E iff x is in F

Theorem: Distributive law of union over intersection


Let R, S, T be sets. Then prove that R ꓴ( S ∩ T) = ( R ꓴ S) ∩(R ꓴ T)
Proof:Aiff B has two parts:
(i) If part : “if B then A” and
(ii) Only if part : if A then B, which is equivalent form “ A only if B”
Let E is the expression in R ꓴ( S ∩ T) & F is the expression in ( R ꓴ S) ∩(R ꓴ T)
i) If part : if x is in E, x is in F

6
x is in R ꓴ( S ∩ T)
x is in R or x is in (S ∩ T)
x is R or x is in both S and T
x is in R ꓴ S
x is in (R ꓴ S) ∩(R ꓴ T)
ii) We can also prove it by “only – if” statement.
x is in (R ꓴ S) ∩(R ꓴ T)
x is in R ꓴ S
x is in R ꓴ T
x is in R or x is in both S and T
x is in R or x is in S ∩ T
xis in R ꓴ( S ∩ T)

1. Proof by contrapositive and contradiction:


Proof by Contrapositive:
It is a logical relationship between two statements.
Example: A proposition or statement,
P = “ Socrates is a man” and
Q = “ Socrates is human”.
Then “ if P then Q implies,
“Socrates is a man then Socrates is human”
The contrapositive is the reversal of negation of both statements. ie., if not C, then not H.
The truth table of Implication (PQ):

P Q PQ
T T T
T F F
F T T
T T T
“if P then Q” and “ if not Q then not P” are logically equivalent. This logical equivalence is,

P Q ¬P ¬Q PQ ¬ P ¬ Q
T T F F T T
T F F T F F
F T T F T T
F F T T T T

Example:
if x ≥ 4 the 2x ≥ x2. The contrapositive of this statement is “if not 2x ≥x2, then not x ≥ 4”.
Therefore, not x ≥ 4 is x < 4
not 2x ≥ x2 is 2x< x2
7
ie., “if 2x< x2, then x < 4”

Proof by Contradiction:
In proof by contradiction, we assume that the theorem is false and then show
that this assumption leads to an obviously false consequence, called a contradiction.
ie., To prove a statement of the form “if H then C” is to prove the statement “H and
not C implies falsehood”.
Step a: State by assuming both the hypothesis H and the negation of the
conclusion C.
Step b: Compute the proof by showing that something known to be false
follows logically from H and C. This form of proof is called proof by contradiction.
Theorem: Let S be a finite subset of some infinite set U. Let T be complement of S
with respect to U. Then T is infinite.
Proof:H = “S is finite set of U.
U is an infinite set,
T is the complement of S w.r.t U”
Conclusion C = “T is infinite”
We proceed to prove the theorem by proof by contradiction.
We assume, not C is true ie., T was finite.
From the assumption S is finite, if T is also finite, then U = S ꓴ T is also finite. But
hypothesis says U is infinite. Therefore, the logical statement is false.

2. Proof by Counter Examples: In order to prove certain statements, we need to see all
possible conditions in which that statement remains true.
Example : There is no such pair of integers such that a mod b = b mod a
Proof: Consider a = 2 and B= 3, then
2 mod 3 ≠ 3 mod 2
Thus, the given pair is true for any pair of integers but if a = b then naturally a mod b =
b mod a
Thus, we need to change the statement slightly. We can say: a mod b = b mod a, when
a= b
Since proof is true only at some specific condition.

Inductive Proof:
Inductive proofs are special kind of proofs which is used to prove recursively defined objects
like tree, expressions of various sorts etc. This type of proof is also called as “ Proof by
mathematical induction”.
The proof by mathematical induction can be carried out using following steps:

8
Let there be a given statementP(n) involving natural numbers n,

(i) Basis: In this step we assume the lowest possible value. This is the initial step. Statement is true
for n = 1
ie. P(1) is true. [Note : Suppose x ≥ 5, the 1st step is P(5)]
(ii) Induction Hypothesis: Let the statement be true for n=K, where K is some positive integer.
(Assumption)
(iii) Inductive Step: If statement P(K) is true we establish that P(K+1) is also true.
(ie.,) truth of P(K)  truth of P(K+1).

Then P(n) is true for all natural numbers ‘n’.

Problems – Inductive Proofs:


n(n+1)
1. Prove that 1 + 2 + 3 + . . . + n = for all n ≥ 1
2

Solution:

n(n+1)
Let P(n) = 1 + 2 + 3 + . . . + n = (Given)
2

Basis: For n = 1

1(1+1)
P(1) : 1 =
2

1=1
i.e. P(1) is true.

Induction Hypothesis: AssumeP(K) be true for some positive integer


K ( K +1)
P(K) : 1 + 2 + 3 + . . . + K = --------------------------- 1
2

Inductive Step: We shall now prove thatP(K +1) is also true whenever P(K) is true
P(K + 1) : 1 + 2 + 3 + . . . + K + (K+1)

K ( K +1)
= + (K + 1) by equation 1.
2

K ( K +1 )+ 2( K +1)
=
2
9
( K +1)(K +2)
=
2
(k + 1)(K +1+1)
=
2

( K +1)(( K+ 1)+1)
=
2

Thus P(K +1) is true whenever P(K) is true. Hence, the statement P(n) is true for all n ≥ 1

2. For all n ≥1, Prove that 1 + 3 + 5 + . . . + (2n – 1) = n2

Solution:
2
Let P(n) = 1 + 3 + 5 + . . . + (2n – 1) = n ------ Given
Basis :for n = 1
2
P(1) : 1 = 1
1 = 1 i.e. P(1) is true
Induction Hypothesis:
AssumeP(K) is true, where K is some positive integer.
2
P(K) : 1 + 3 + 5 + . . . (2K – 1) = K --------------- 1
Inductive Step :
We shall now prove that P(K + 1) is also true whenever P(K) is true.
P(K + 1) = 1 + 3 + 5 + . . . (2K – 1) + 2((K + 1) – 1)

2
= K + 2K + 1
2
=K +K+K+1
= K ( K + 1) + 1(K + 1)
= (K + 1)(K + 1)
2
= (K + 1)
Thus P(K + 1) is true whenever P(K) is true for all n ≥ 1

3. Prove that 9n – 2n is divisible by 7 for all n ∈ N .


Solution:
10
Basis: For n = 1,
P(1): 91 – 21 9 – 2  7.1 is divisible by 7
=7 m, for m = 1,2,3…..N
Induction Hypothesis:
Assume P(K) is true
P(K) : 9K – 2K = 7m is true for some K, m ∈ N ---------------1
(which means that 9K – 2Kis divisible by 7)
Inductive Step: Since P(K) is true, P(K+1) is also true.
P(K + 1) : 9K+1 – 2K+1 = 9K . 91 – 2K. 21 ------------- 2
K K
From equation 1, 9 – 2 = 7m
9K = 7m + 2K
Substitute9K= 7m + 2K in equation 2
(7m + 2K) . 9 - 2K. 21
9.7m + 9.2K- 2K.2
9.7m + 7. 2K
7(9m + 2K) which is divisible by 7
Hence P(K+1) is also true.
4. Prove that for every integer n≥ 0 the number 42n+1 + 3n+2 is multiple of 13
Solution:
Basis :P(1) : 42 . 1 +1 + 31 +2
= 43 + 33 91 which is multiple of 13 (13X7 = 91)
Induction hypothesis: Assume P(K) is true.
P(K): 42K+1 + 3K+2 = 13 m -------------1
where m is some integer
Inductive step: P(K+1) is true, since P(K) is true.
P(K+1):42 (K+1) +1 + 3(K+1) +2
= 42K + 2 +1 + 3K + 1 +2
= 42K + 2 +1 + 3K + 2 + 1 zero

=42 .42K +1 + 42(3K+2 – 3K + 2) + 31. 3K + 2


= 42(42K +1 +3K + 2) + 3K + 2(-42+ 3)
= 42 .13 m + 3K + 2(-13) [From equation 1]
2 K+2
= 13(4 m- 3 ) which is multiple of 13
Hence P(K+1) is also true.

1 1 1 1 n
5. Prove that + + +…+ = for all n ≥ 1
1. 2 2. 3 3 . 4 n .(n+1) n+1
Solution:
1 1 1 1 n
Given, P(n): + + +…+ =
1. 2 2. 3 3 . 4 n .(n+1) n+1
Basis : For n = 1,

11
1 1
P(1) : =
1. 2 1+ 1
1 1
=
2 2
Hence, P(1) is true.
Induction hypothesis:
Let us assume,
1 1 1 1 K
P(K): + + +…+ = is true -------1
1. 2 2. 3 3 . 4 K . (K +1) K +1
where K is positive integer
Inductive step: P(K+1) is true, since P(K) is true.
1 1 1 1 1
P(K+1) : + + +…+ +
1. 2 2. 3 3 . 4 K . ( K +1 ) ( K +1 )( K +1 )+1
K 1
= + [From equation 1]
K +1 ( K +1 )( K + 2 )
K ( K + 2 )+ 1
=
( K +1 )( K + 2 )
2
K +2 K +1
=
( K +1 )( K + 2 )
2
(K +1)
=
( K +1 )( K + 2 )
K +1
=
( K +1+1 )
Hence P(K+1) is true.
Basic Definitions of Automated Theory:

1. Set: Set is used to represent the mathematical model. Set is defined as collection of objects.
These objects are called elements of the set.All the elements are enclosed within curly
brackets {&} and every element is separated by commas.

If ‘a’ is an element of set A then we say that a ∈ A and if ‘a’ is not an element of A then we say
that a∉A.
Typically set is denoted by a capital letter. The set can be represented using 3 methods.
(a) Listing method: The elements are listed in the set.
Example: A set of elements which are less than 5. The A = {0, 1, 2, 3, 4}
(b) Describing properties: The properties of elements of a set.
Example: A set of vowels  vowel is a property of the set which defines the set as,
A = {a, e, i, o, u}
(c)Recursion method: The recursion occurs to define the elements of the set.

Example : A = { x | x is square of n ; n ≤100}

12
This defines the set as,
A = {0, 1, 4, 9, 16, 25, …100}

2. Subset: A set ‘A’ is said to be a subset of ‘B’ if every element of A is present in B. We write

If A ⊆ B, but B contains an element not in A, we say that A is a proper subset of B, A ⊂ B


this as A ⊆ B.

Example 1: A= {1, 2, 3}; B= {1, 2, 3, 4, 5} then A ⊆ B


Example 2: If A = {1, 3, 5} then B = {1, 5} is a proper subset of A. The set C = {1, 3, 5} is a
subset of A, but it is not a proper subset of A, Since C = A. D ={1, 4} is not a subset of
A, since 4 is not an element of A.
If B is a proper subset of A, then all elements of B are in A but A contains at least one
element that is not in B.

3. Empty Set: the set having no element. It is denoted by A = { } and it can be written as
Ф(phi).

4. Power Set: A set of all the subsets of its elements.


Example A = {1, 2, 3}. Then power set of A = {Ф,{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}
The number of elements is always equal to ‘2n’ where n is number of elements in original
set.

5. Equal set: The two sets are said to be equal (A = B) if A ⊆ B and B ⊆ A. i.e every element of
set A is an element of B and vice versa. Example: A = {1,2,3} & B= {1,2,3} then A= B

6. Length of set: The length of set A can be denoted as |A|.


Example: A = {1,2,3,4,5} then |A| = 5.
Automata theory is entirely based on symbols. These symbols are generally
letters and digits.
Example : A, B, a, b, 0,1,…….

7. Alphabet: An alphabet is a collection or set of symbols. It is denoted by ∑ .


Example: ∑ = {0, 1} is an alphabet of binary numbers. {1,2,3,4,5}
∑ = {a, b} is an alphabet of letters.

8. String: A string is a sequence of symbols selected from some alphabet. It is generally


denoted as ‘w’ .
Example :
if ∑ = {a, b} then w = abbaa (or) abab (or) aaabbb
∑ = {0,1} then w = 10110, 00110, 101010,000001

13
9. Length of a string: The length of a string is the number of symbols in the string. The
length of a string ‘w’ is written as |w|.
Example: w = 101101 the |w| = 6.

10.Empty or Null string: The empty string is the string with zero occurrences of symbols. It
is represented by ε or λ. (epsilon or lambda)

11.Power of an Alphabet: If ∑ is an alphabet, the power of an alphabet, ∑ k is the set of all


strings of a certain length k from that alphabet by using an exponential notation.
Example : ∑0 = {ε} . Set of all strings of length ‘0’.
If ∑= {0, 1}
∑1 = {0, 1}  set of all strings over ∑ of length 1.
∑ = ∑ ∑= {0, 1} {0, 1} = {00, 01, 10, 11}
2 .

Note :Cardinality means number of elements in a set.


Example: ∑3 = {000, 001,010,011,100,101,110,111}
|∑3| The cardinality of this set is 8; i.e |∑3|=8

12.Reverse of a string: The reverse of a string is obtained by writing the symbols in reverse
order.
Example: U = 01011 then UR = 11010

13.Concatenation of string: The concatenation of two strings U and V is the string obtained
by appending the symbols of V to the right end of U.

Example : U = a1a2a3 ; V = b1b2b3 then UV = a1a2a3b1b2b3.

14.Substring: A string of consecutive character from string w is called substring of w.


Example: i) w= abbab be a string over an alphabet ∑ = {a, b} then a,ab,abb,ba,bab,… are all
substrings of w.aba is not a substring
ii) w=123
Prefixes = {ε,1,12,123} ; Suffixes = { ε, 3,23,123}

15.Kleene Closure (or) Kleene star (∑*):The Kleene star, Σ* is a unary operator on a set of
symbols or strings, Σ, that gives the infinite set of all possible strings of all possible lengths
over Σ including ε or λ. It is represented by,
¿
L =¿ i=0 ¿ ∞ Li [zero or more occurrence of strings]

Example: i)IfΣ = {a} then Σ *= { ε, a, aa, aaa, aaaa, aaaaa,. . .}


i.e. Σ0 = {ε} ; Σ1 = {a} ; Σ2 = {aa}
Σ* = Σ 0 U Σ1 U Σ2 U …
ii) If Σ = {a, b} then Σ*= {ε, a, b, aa, ab, ba, bb,aaa, . . .}
14
+
16.Positive Closure or Kleene Plus (∑ ):The set Σ+ is the infinite set of all possible strings of all
possible lengths over Σ excluding ε or λ.
+
i.e. Σ = Σ1 U Σ2 U Σ3 U…….
+
Σ = Σ* − { ε }.
It is represented by
+¿¿
L = ¿ i=1 ¿ ∞ Li
17. Language :A language is a subset of Σ* for some alphabet Σ. It can be finite or infinite. It is
denoted by L⊆ Σ*.
Example: i) Σ = {a, b}
Σ*= { ε, a, b, aa, ab, ba, aaa, aab,. . .} is a language.
ii) Language of strings consisting of equal number of a’s and b’s can be,
L= {ab, aabb, abab, baba, aabbab,bbabaa. . .}

18. Complement of Language:


It is denoted by L, where L = ∑* - L

19. Reverse of Language:


It is denoted by LR.
LR = { wR | w ∈ L}

Finite Automata (FA):


Finite Automaton is a mathematical model of a system with discrete inputs and outputs. It is
processed through various intermediate states and finally gives certain output. It recognizes
regular languages only. It was developed by Scott Robin in 1950 as a model of a computer with
limited memory.It receives its input as a string, usually from an input tape. It delivers no output
at all except an indication of whether the input is acceptable or not. Hence, finite automata isused
for decision making problems.

Examples: (i) Start State: close


Final/acceptance State: close

𝛿 (open, No) = close[𝛿


Input strings: Yes, No

transition]

15
ii) Recognizing a string ‘the’. State state: 1
Final state: 4
Input symbols: t,h,e

Finite Automata Model:


A finite automaton has a mechanism to read input, which is a string over a given
alphabet. This input is actually written on an “input tape”, which can be read by the automaton
but cannot change it.

Input tape is a linear tape. It is


divided into cells, each of which can hold
one symbol from the input alphabet. The
end cells of the tape contain the endmarker.
The absence of endmarkers indicates that
the tape is of infinite length. The left-to-
right sequence of symbols between the
endmarkers is the input string to be
processed.
Automaton has a control unit, which
is said to be in one of a finite number of
“internal states”. The control unit decides
the next state on receiving particular input
from input tape.

The read head examines the cells one by one from left to right and at a time only
one input symbol is read.

Definition of Finite Automata:


Finite automata can be defined as 5 – tuple(Quintuple),
M= (Q, ∑, 𝛿, q0,F)
Where,
Q  Finite set of states

𝛿  Transition function or mapping function, defined as 𝛿: Q X ∑ Q


∑  Finite set of input alphabet/symbols

q0 Start state (q0 ∈ Q)


F  Set of final states (F ⊆ Q)
16
𝛿(current state,i/p symbol)next state

Finite Automata can be represented by two ways:


1. Transition Diagram
2. Transition Table
1. Transition Diagram:
A transition diagram or transition graph is a directed graph associated
with the vertices of the graph corresponds to the states and edges
indicatetransition from one state to another.
A state is indicated by a circle:
Arrow indicates transition from one state to another state:
Start state is indicated by arrow with circle:
Final state is indicated by double circle:

Example:

Here, q0,q1,q2 are states,q0 is start state and q2 is the final state or acceptance state.

2. Transition Table:
Transition table is a tabular representation of finite automata. For transition table the
transition function is used.
Example: (i)

The Transition table of above state diagrams is,

Transition Table:

Inputs Indicate start state and * represents


States
a b final state
q0 q1 q0
q1 - q2
17
*q2 - q2

Example : (ii) M = {{q0,q1,q2},{a,b}, 𝛿, q0,{q2}}


𝛿(q0,a)=q1 ;𝛿(q0,b)= q2 ; 𝛿(q1,a)= q2 ;
𝛿 (q1,b)= q0 ;𝛿(q2,a)= q2 ; 𝛿(q2,b)= q2 ;
Transition table:
Inputs
States
a b
q0 q1 q2
q1 q2 q0
*q2 q2 q2

A string ‘x’ is accepted by finite automata, M = (Q, ∑, 𝛿, q0, F) only if 𝛿 (q0, x) = P for
Language Acceptance by FA/ Language of FA:

some P in F. This concludes that the string is accepted when it enters into the
final state on the last input element.
The language accepted by M which is denoted by L(M)

L(M) = {x | 𝛿(q0, x)is in F) (or) L(M) = { x |x ∈∑ * and (q0, x) ∈ F}

The language accepted by FA is called regular language.

Given M = (Q, ∑, 𝛿, q0, F)


Example:

Q = {q0,q1, q2, q3} ;∑ = {0,1}


The transition diagram is

Check whether the input string 110101 is accepted by the FA or not.


Solution:

Inputs
States
0 1
18
*q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2

The input string 110101 is accepted, because q0 is final state.

Properties of Transition Function:


(i)𝛿(q, ε) = q The state of the system can be changed only by an input symbol else
remains in original state.

𝛿(q, aw) = 𝛿 (𝛿 (q, a),w)


(ii) For all strings ‘w’ and input symbol ‘a’

Similarly, 𝛿 (q, wa) = 𝛿 (𝛿(q, w),a)

Extended transition function: If 𝛿 is a transition function, then the extended


transition function is denoted by or 𝛿’. The extended function is a function
that takes a state q and a string ‘w’ and returns a state P.

Basis: (q, ε) = q. That is, if we are in a state q and read no inputs, then we are still in
state q.

thestring consisting of all but the last symbol ‘a’[For example, w=1101 is broken
Induction: Suppose w is a string of the form xa; that is,‘a’ is the last symbol of w, and x is

into x = 110 and a = 1]. Then,


(q, w)= 𝛿 ( (q, x),a)

 To compute (q, w), first compute (q, x), the state that the automaton
is in after processing all but the last symbol of w.
 Suppose this state is p, ie., (q, x) = p
 Then (q, w) is what we get by making a transition from state p on
input a, the last symbol of w. That is (q, w) = 𝛿(p, a)

Types of Finite Automata:


Finite Automata has 2 kinds:
19
1. Deterministic Finite Automata (DFA)
2. Non-Deterministic Finite Automata(NFA)

1. Deterministic Finite Automata(DFA):


In a DFA, for a particular input symbol, the machine goes to one state only. A
transition function is defined on every state for every input symbol. Also, in DFA, null (or
ε) move is not allowed, i.e., DFA cannot change state without any input character.
A DFA can be represented by a 5-tuple:
M = (Q, Σ, δ, q0, F)
Where,
 Q is a finite set of states.
 Σ is a finite set of symbols called the alphabet.
 δ is the transition function or mapping function where δ: Q × Σ →Q
Two parameters are passed to this transition function: one is current state and other
is input symbol. The transition function returns a state which can be called as next
state. Example : δ(q0 , a)  q1 where, q0 is the current state, ‘a’ is input symbol and
q1 is next state .
 q0is the initial state from where any input is processed (q0∈Q).
 F is a set of final state/states of Q (F⊆Q)
Example 1 :

state the input is 1, it will go to q0 state


only and the input is 0 it will go to q1
state only. In q1 state the input is 0, it
will go to q1 state and the input is 1, it
will go to q0 state only. That is, the
The diagram is DFA with ∑ = {0, 1} alphabet symbols 0 and 1(input strings)
accepts all strings ending with 0. In q0 leads to the unique state.

Example 2:

Transition diagram: Transition Table:

Inputs
States
0 1
q0 q0 q1
q1 q2 q1
*q2 q2 q2

In state q0, when input is 0, the transition is q0, when the input is 1, the transition is q1.
In state q1, when input is 1, the transition is q1 and when the input is 0, we have the
transition q2. In state q2, when the input is 0 and 1, the transition is in same state.

20
Dead State/Trap State/Dump state:
A dead state is state from where the automaton cannot reach an accept state.

EXAMPLES of DFA :
1. Design a DFA that accepts set of string such that every string ends with 00, over
alphabet{0,1}.
Solution:
Let M = (Q, Σ, δ, q0, F) be the DFA
According to the problem we have to design a DFA which accepts strings w00. Where ‘w’
can be any combination of 0’s and 1’s such that,
L / Σ*= {00, 100, 000, 1100,101000, . . . . . . }

From the above transition diagram, each state has one and only transition for each input
symbol. The five tuples of DFA M are,
M = {{q0, q1, q2},{0, 1}, δ, q0,q2}
Transition Table:

Inputs
States
0 1
q0 q1 q0
q1 q2 q0
*q2 q2 q0

Consider the string 1100. If this string is accepted by the DFA then by taking this string
will reach to the final state otherwise it will not reach the final state.
δ (q0, 1100) = δ(q0, 1100)
= δ(δ(q0, 1), 100) [ input 1 on state q0, then it will go to state q0]
= δ(q0, 100)
= δ(δ(q0, 1), 00)
= δ(q0, 00)
=δ(δ(q0, 0), 0)
=δ(q1, 0)

21
=q2 [ q2 is final state]
Hence, the given string is accepted as it reaches at the final state q2.
2. Design a DFA for string with at least two consecutive zero which is anywhere in the
string.
Solution:
According the problem we have to design a DFA which accepts string w00w. Where ‘w’
can be any combination of 0’s and 1’s such that,
L={00, 100, 1001, 10100, 0011,100010 . . . . . . . }

3. Design a DFA for string which accept a string containing ‘aba’ as its substring over
Σ* such that Σ = {a, b}.
Solution:
According the problem we have to design a DFA which accepts string wabaw. Where ‘w’
can be any combination of a’s and b’s such that,
L={aba, aaba, abab, aabaa, bbababb, . . . . . . . }

4. Design a DFA for string which accepts set of all string on Σ = {a, b} with no more than
three a’s.
Solution:
Here we have design a DFA which accepts strings of any combination of a’s and b’s but do
not more than three a’s such that,
L/Σ* ={a, b, aa, bb, aba, abb, aab, aaabb, . . . . }

22
5. Design a DFA that accepts the language
L={ w ∈ (0, 1)* | second symbol of w is 0 and fourth input is 1}
Solution:
Here we have to design a DFA in which the number 0 should be at 2 nd position and
1 will be at 4th position such that,

L= {1011, 00111, 000110, 001111, . . . . . . }

6. Design a DFA for the language L = { awa | w ∈ (a, b)*}


Solution:
We have to design a DFA which accepts strings awa. Where w can be any combination of a
and b, and it must start and end with the symbol a, such that,
L = { aba, aa, abba, abaa, abbaa, abbbba, . . . . . }

7. Design a DFA that accepts the language


L= { w | mod 3 = 0 ; w ∈ (a, b)}
Solution:
Here we have to design a DFA in which the length of the string should be divisible
by three such that,
23
Σ* = {aaa, aba, baa, bba, aaaaaa, bbbbbb, . . . . . .}

8. Design a DFA that accepts the language


L = {(01)i 12i | i ≥ 1, j ≥ 1}
Solution:
Here we have to design a DFA that will accepts strings start with any number of 01
and end with even number of 1’s such that,
Σ* = {0111, 011111, 01001111, 01011, . . . . }

9. Construct a DFA for the set of strings over {a, b, c} having ‘bca’ as substring.
Solution:
Here we have to design a DFA which accepts string ‘bca’ as a substring.
i.e. w= x bca x. where x can be any combination of a’s, b’s and c’s.
L= {bca, abca, bbcaaa, cbcabc, . . . .}

10. Design a DFA for the language L = {w | n a(w) ≥ 1, w∈(a, b)*} where na is number
of a’s in string.
Solution:
Here we have to design a DFA in which numbers of a’s in the strings is one or
more. b’s can occur for any number of times at any place. i.e.
L= { a, aa, aaa, ba, bba, bbabb, bbbbba, abbbbba, . . . . . . . . }

24
11.Give DFA accepting the language over the alphabet {0, 1}. “ The set of all strings
whose tenth symbol from the right end is a 1”.

12.Consider the DFA with the following transition table.

0 1
A A B
*B B A

Describe the language accepted by the DFA.


Solution:
The strings generated from this transition diagram are 1,10, 010, 01011, 01110,
011100, . . . . . . .

Therefore, L = 0*1(11)*0* . It is defined by the statement that “The set of strings of 0’s and
1’s containing odd number of 1’s”.
13.Describe the language accepted DFA M= ({q0,q1,q2},{0, 1},q0, δ,{q1}, where δ is
given by,

Inputs
States
0 1
q0 q0 q1
q1 q0 q2
q2 q2 q1
Solution:
25
Examples: (String testing)
1. δ (q0, 0)= q0  Non accepting state
2. δ (q0, 01)= q1  Accepting state
3. δ (q0, 01101)= q1  Accepting state
4. δ (q0, 11)= q2  Non accepting state
Hence the above DFA accepts 01,01101, 101,0111. That is odd number of ones.
i.e. L = { w | w is a combination of 0’s and 1’s containing odd number of 1’s}

Language of DFA:
A string ‘x’ is said to be accepted by DFA M = (Q, Σ, δ, q0, F), if δ(q0,x) = P for some P in F.
The language accepted by DFA is,
L(M) = {w | (q0, w) is in F}
The language accepted by DFA is called regular language
Extended transition function of DFA ( ): If 𝛿 is a transition function, then the
extended transition function is denoted by . The extended function is a
function that takes a state q and a string w and returns a state P.
Basis: (w has length 0) In this case w is the empty string, i.e. the string of length 0, for
which we writeε. Then,
(q, ε) = q
If we are in a state q and read no inputs, then we are still in state q.
Induction: Suppose w is a string of the form xa; that is ‘a’ is the last symbol of w, and x is
the string consisting of all but the last symbol. Then,
(q, w)=δ ( (q, x),a)

 To compute (q, w), first compute (q, x), the state that the automaton
is in after processing all but the last symbol of w.
 Suppose this state is p, ie., (q, x) = p
 Then (q, w) is what we get by making a transition from state p on
input a, the last symbol of w. that is (q, w) = 𝛿(p, a)

Acceptance of strings in DFA:


For the given input string w, if it reaches final state from initial state then it is
acceptable. The DFA can processstrings by using two methods.

26
i) Using transition function (𝛿): DFA starts with initial state q0. Let a1, a2, . . .
. . .an be a sequence of input symbols, 𝛿 is transition function.
Step 1: (q0, a1) = q1, DFA in state q0 on input a1 enters state q1.
Step 2: (q1, a2) = q2 ,DFA in state q1 on input a2 enters state q2.
Similarly, (qi-1, ai) = qi for each i(1≤ i ≤ n )
If qn is a member of F, then the input string a1, a2, . . . . . .anis accepted,
otherwiseit is rejected.

ii) Using extended transition function (or) 𝛿’ :


Step 1: (q0, є) = q0, where q0is the initial state.
Step 2: (q0, w) = (q0, xa) = ( (q0 , x),x) = qf , qf is final state.
i.e., (q0, w) = final state, hence w is accepted by the DFA

Example1: Use δ to describe how the string 011101 is processed by the given DFA: (Using
transition function)

δ (q0,011101) = δ(q1, 11101)


= δ(q2, 1101)
=δ(q3, 101)
=δ(q2, 01)
= δ(q3, 1)
= δ(q2, є) = q2  accepting state
Therefore, δ(q0, 011101) = q2 (Since δ(q0, x) = q for some q ∈ F)

Example2: Use to describe how the string 011101 is processed by the following DFA:
(using extended transition function)

(q0, Є) = δ(q0, Є) = q0
(q0, Є0) = δ( (q0, Є),0) = δ(q0, 0) = q1
(q0, 01) = δ( (q0, 0),1) = δ(q1, 1) = q2
(q0, 011) = δ( (q0, 01),1) = δ(q2, 1) = q3
27
(q0, 0111) = δ( (q0, 011),1) = δ(q3, 1) = q2
(q0, 01110) = δ( (q0, 0111),0) = δ(q2, 0) = q3
(q0, 011101) = δ( (q0, 01110),1) = δ(q3, 1) = q2

Therefore, the string “011101” is accepted by DFA.

Non Deterministic Finite Automata (NFA / NDFA):

The finite automata are called NFA whenthere exist many paths for a specific input
from current state to next state.
The NFA can be formally defined as a collection of 5 tuples.
M = (Q, Σ, δ, q0, F)
Where,
 Q is a finite set of states.
 Σ is a finite set of symbols called the alphabets.
 δ is the transition function where δ: Q × Σ →2 Q (or) Q × (Σ U ε) →2Q (Here the
power set of Q(2Q) has been taken because in case of NDFA, from a state,
transition can occur to any combination of Q states)
 q0 is the initial state from where any input is processed (q0∈Q).
 F is a set of final state/states of Q (F⊆Q).
Example

In NFA, if any path for an input string leads to a final state, then the input string accepted.
For example, in above NFA, there are multiple paths for input string “00”. Since, one of the
paths leads to a final state, “00” is accepted by above NFA.

Properties of NFA :
1. There may be a transition on input symbol ‘ε’ i.e., empty input symbol.
2. A state can have more than one transition on the input symbol

Some Important Points:


1. Every DFA is NFA but not vice versa.
2. Both NFA and DFA have same power and each NFA can be translated into a DFA.
3. There can be multiple final states in both DFA and NFA.
4. NFA is more of a theoretical concept.
28
5. DFA is used in Lexical Analysis in Compiler.

Difference of Transition Table of NFA and DFA:


Transition table can be used to view the transition function of either NFA or DFA.
The only difference is that each entry in a table for NFA is a set.

NFA Transition Table DFA Transition Table

Inputs Inputs
States States
0 1 0 1
q0 {q0, q1} {q1} q0 q0 q1
*q1 Ф {q1} *q1 q1 q1

NFA EXAMPLES:
1. Construct a NFA over alphabet Σ = {a, b} that accepts stringwith substring
ab.

2. Construct a NFA over Σ = {a, b} that accepts string which has 3rd symbol b
from right. (or) Obtain a NFA which should accept a language L, where
L = { x ∈(a, b)* : | x | ≥ 3 and 3rd symbol of x from the right is ‘b’

Solution:

3. Construct a NFA over Σ = {a, b} for the language


L1= { Consisting a substring 0101}

29
L2= { 0n U 1n}
Solution:
For L1 : There can be any combination of o and 1 in the language but a substring
0101 must be present.

For L2: This language be any number of 0’s or any number of 1’s. It accepts { ε, a,
aa, aaa, . . . , b, bb, bbb, . . . . . }

4. Design the NFA transition diagram for the transition table as given below

Inputs
States
0 1
q0 {q0, q1} {q0, q2}
q1 {q3}
q2 {q2, q3} {q3}
*q3 {q3} {q3}

Solution:

30
The NFA M is ({q0, q1, q2, q3}, {0,1}, δ , q0, {q3})
The transitions are
δ(q0, 0) = {q0, q1} ; δ(q0, 1) = {q1} ; δ(q1, 0)={q3};
δ(q2,0) = {q2, q3}; δ(q2,1) = {q3} ; δ(q3,0)= {q3};
δ(q3,1)= {q3}

Language of NFA :
If A = (Q, Σ, δ, q0, F) is an NFA then,
L(A) = {w | (q0, w) ∩ F ≠ Ф}
i.e. L(A) is the set of strings w in ∑* such that (q0, w) contains atleast one accepting
state.

Extended Transition function of NFA:


As for DFA's, we need to extended the transition function δ of an NFA to a

function that takes a state q and a string of input symbols w, and returns the set of

states. Formally, we define for an NFA’s transition function δ by:

Basis: (q,Є)={q}. That is without reading any input symbols; we are only in the same
state.
Induction: Suppose w is of the form w=xa, where ‘a’ is the last symbol and x is the
substring containing rest of w.
Also, suppose that (q,x)={p1,p2…..pk} . Let,

¿ i=1 ¿ k δ ( Pi , a )={r 1 , r 2, … rm }
Then, (q,w)={r1,r2……..rm}. Less formally, we compute (q,w) by first computing (q,x),
and by then following any transition from any of these states that is labeled a.

Acceptance of strings in NFA:


For the given input string ‘w’, if it reaches final stat from initial state then it is
acceptable. It happens sometimes does not happen for the same input string. The
sequence of states for acceptability of a string is different.

Processing a string in NFA:


Consider the given transition diagram and check the acceptance of the input string
“00101” using NFA.

31
i) Using proliferation diagram:

ii) Using transition function δ


δ (q0,00101) = δ (δ(q0, 0),0101)
=δ({q0,q1},0101)
=δ(q0,0101) U δ(q1,0101)
=δ(δ(q0,0),101) U δ(δ(q1,0),101)
=δ({q0,q1},101) U δ(Ф,101)
= δ(q0,101) U δ(q1,101)
=δ(δ(q0,1),01) U δ(δ(q1,1),01)
=δ({q0},01) U δ({q2},01)
=δ(q0,0),1) U δ(q2,0),1)
=δ({q0,q1},1 U δ(Ф, 1)
=δ(q0,1) U δ(q1,1)
= {q0} U {q2}
= {q0,q2} ∩ F ≠ Ф
={q0,q2} ∩ {q2}
= {q2} ≠ Ф

iii) Using extended transition function

(q0, Є) = {q0}

(q0,0) = ( (q0, Є0) = δ ( (q0, Є), 0) = δ({q0}, 0) = δ(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,
q2}
32
(q0, 0010) = δ ( (q0, 001), 0) = δ({q0,q2},0) = δ(q0,0) U δ(q2,0) = {q0,q1} U Ф ={q0,q1}

(q0, 00101) =δ( (q0, 0010),1) = δ ({q0,q1},1) = δ(q0,1) U δ(q1,1) = {q0} U {q2}
={q0,q2}
={q0,q2} ∩ F ≠ Ф
= {q0, q2} ∩ {q2} ≠ Ф
= {q2}≠ Ф
Hence the given string 00101 is accepted.

Example 2: Use extended function( ) to describe how the string 01010 is processed by the
following NFA:

(q0, Є) = δ(q0,Є) = {q0}

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

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

(q0, 010) = δ( (q0, 01), 0) = δ ({q0,q1},0) = δ(q0, 0)⋃ δ(q0, 0) = {q0,q2}

(q0, 0101) = δ( (q0, 010), 1) = δ ({q0,q2},1) = δ(q0, 1)⋃ δ(q2, 1) = {q0,q1}⋃∅


={q0,q1}

(q0, 01010) = δ( (q0, 0101), 0) = δ ({q0,q1},0) = δ(q0, 0)⋃ δ(q1, 0) = {q0,q2}

Therefore, the string “01010” is accepted by the NFA.

3. Construct the given NFA to check whether w=01001 is valid or not.

33
SOLUTION:
M= (Q , Σ, δ , q0, F) is a NFA,
Where Q→{ q0, q1, q2, q3, q4},
Σ→{0,1},
F→{q2, q4},
δ →QXε to 2Q

Transition table is,

INPUTS
STATES 0 1
q0 {q0, q3} {q0, q1}
q1 Φ q2
q2 q2 q2
q3 q4 ϕ
q4 q4 q4

34
Using Extended Transition function:

(q0, ε)=δ (q0, ε)= q0

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

(q0, 01)=δ ( (q0, 0),1)


=δ ({q0, q3},1)
=δ (q0,1) Uδ (q3,1)
= {q0, q1} U { ϕ }
= {q0, q1}

(q0, 010)=δ ( (q0, 01),0)


=δ ({q0, q1},0)
=δ (q0,0) Uδ (q1,0)
= {q0, q3} U { ϕ }
= {q0, q3}

(q0, 0100)=δ ( (q0, 010),0)


=δ ({q0, q3},0)
=δ (q0,0) Uδ (q3,0)
= {q0, q3} U {q4}
= {q0, q3, q4}

(q0, 01001)=δ ( (q0, 0100),1)


=δ ({q0, q3,q4},1)
=δ (q0,1) Uδ (q3,1) Uδ (q4,1)
= {q0, q1} U { ϕ } U {q4}
= {q0, q1, q4}

(q0, 01001) ∩ F ={q0, q3,q4} ∩ {q4}

={q4} FINAL STATE.

∴Hence the given string is accepted.

4.For the NFA shown, check whether the input string 0100 is accepted or not?

35
SOLUTION:

INPUTS
STATES 0 1
q0 {q0, q1} {q2}
q1 ϕ {q1, q2}
q2 {q0, q2} {q1}
Input string = 0100,

(q0,0) = {q0, q1}

(q0, 01)=δ ( (q0,0),1)


=δ ({q0, q1},1)
=δ (q0,1) Uδ (q1,1)
= {q2, q1}

(q0, 010)=δ ( (q0,01),0)


=δ ({q1, q2},0)
=δ (q1,0) Uδ (q2,0)
= {q0, q2} U { ϕ }

= {q0, q2}

(q0, 0100)=δ ( (q0, 010),0)


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

∴ Since it contains q0which is final state, hence the string is accepted.

36
5.The NFA with states {1,2,3,4,5} and input alphabet Σ={a,b} has the following
transition.

INPUTS
STATES a b
1 {1, 2} {1}
2 {3} {3}
3 {4} {4}
4 {5} ϕ
5 Φ {5}

(i) Calculate δ (1, ab) (ii) Calculate δ (1, abab)


SOLUTION:

i) Calculate δ (1, ab) ii) Calculate δ (1, abab)

(1, a) = {1,2} (1,a) = {1,2}

(1, ab)=δ ({1,2}, b) (1,ab) = {1,3} [ Refer (i) ]


=δ (1,b) Uδ (2,b)
(1,aba)=δ ({1,3}, a)
= {1} U { 3 }
=δ (1,a) Uδ (3,a)
= {1,3}
∴δ (1, ab)={1 , 3}
= {1,2} U { 4 }
= {1,2,4}

(1, abab)=δ ({1,2,4}, b)


=δ (1,b) Uδ (2,b) Uδ (4,b)
= {1} U { 3 } U { ϕ }
= {1,3}
∴δ (1, abab)={1 , 3} .

Difference between DFA and NFA:


37
Deterministic Finite Automata Non-Deterministic Finite Automata
(DFA) (DFA)
For a particular input character DFA goes to For a particular input character NFA can
one state only be in multiple states at one time.

The DFA is not possible to move to next In NFA, we can move to next state without
state without reading any symbol reading any symbol.

Dead state is required. Dead state is not required


Eg. L = set of all strings start with 0 Eg. L = set of all strings start with 0

ε (or null) move is not allowed in DFA. ε (or null) move is allowed in NFA.[NFA
[DFA cannot change state without any input can change state without any input
character] character]

DFA for a language is difficult to construct NFA for a language can be smaller and
than NFA easier to construct than a DFA

Every DFA is NFA Every NFA is not DFA

Q X (Σ U ℇ) 2Q
Transition function, Transition function,
Q X Σ Q

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

DFA can be understood as one machine. NFA can be understand as several little
machines that computer together.

Time needed for checking string acceptance It takes more time as compared to DFA.
is less as compared to NFA.

It is easy to find whether string w belongs to It is difficult to find whether w ϵ L as there


language L as transition are deterministic. are several paths. Backtracking is required
to explain several parallel paths.

38
Equivalence of NFA and DFA:
Since every DFA is an NFA, it is clear that the class of languages accepted by
NFA’s includes the regular set.
Theorem: Let L be a set accepted by an NFA then there exists a DFA that accepts same
language, L.
Proof:
As the language accepted by DFA, ie., for every NFA, we can construct an
equivalent DFA, one which accepts the same language.
Let L be a set accepted by an NFA. There exists a DFA that accepts L
Let M = (Q, Σ, δ, q0, F) be the NFA accepting L
Let M’ =(Q’, Σ, δ’, q0’, F’) be the DFA accepting L
 The states (Q’) of DFA M’ will be subsets of the states of M,
i.e. Q’ = 2Q
 Final State of DFA F' is the finite set of final states of M . That is F' is the set of all
final states in Q' containing a final state of M. Observe that [q0, q1, q2,. . . , qi] is a
single state of DFA corresponding to a set of states [q0, q1, q2,. . . , qi] of the NFA.
 Initial state of DFA
q0’ = [q0]
 δ' Mapping of DFA
We define δ' mapping as follows δ'[q0, q1, q2,. . . , qi] , a) = [p0, p1, p2, . . . ,
pi]
if and only if
δ'[q0, q1, q2,. . . , qi] , a) = [p0, p1, p2, . . . , pi]
That is δ' applied to an element [q0, q1,..., qi] of Q' is computed by applying δ to
each state of Q represented by {q0, q1, q2,. . . , qi}. On applying δ to each of q0, q1,
q2,. . . , qi, and taking the union, we get some new set of states {po, p1, . . . ,pi). This
new set of states has a representative, [p0, p1, p2, . . . , pi] in Q', and that element is
the value of δ'([q0, q1, q2,. . . , qi] , a).
By induction we can show that the length of the input string x
δ'(q0’, x)= [q0, q1, q2,. . . , qi]
if and only if
δ(q0, x)= {q0, q1, q2,. . . , qi}

Step 1: Basis
For | x | = 0
i. e. x is = ε, and we have q0’ = [q0] as initial state so basis is true.

Step 2: Induction Hypothesis


Suppose that the hypothesis is true for inputs of length m or less. That is
δ'(q0’, x)= [q0, q1, q2,. . . , qi]
if and only if
δ(q0, x)= {q0, q1, q2,. . . , qi}is true for | x | ≤ m.
39
Step 3: Induction Step
Let "xa" be a string of length m + 1 and a ∈Σ. Then
δ'(q0’, xa) = δ'(δ'(q0’, x), a)by property of transition function.
By induction hypothesis
δ'(q0’, x) = [q1, q2,. . . , qi]
if and only if
δ(q0, x) = {q1, q2,. . . , qi}
So we have
δ'([q1, q2,. . . , qi], a)
By definition of δ'
δ'([q1, q2,. . . , qi], a) = [r1, r2, . . . , rk]
if and only if
δ'([q1, q2,. . . , qi], a) = [r1, r2, . . . , rk]
Thus
δ'(q0’, xa) = [r1, r2, . . . , rk]
if and only if
δ(q0, xa) = [r1, r2, . . . , rk]

This establishes the inductive hypothesis. Thus


δ'(q0’, x) is in F’ exactly when δ(q0, x) is in F

Thus L(M) = L(M’). Hence prove

EXAMPLES:
1. Converting the following NFA diagram to DFA.

Solution.

NFA = (Q, Σ, δ, q0,F)

DFA = (Q’,Σ, δ’,q0’,F’)

STEP 1: Consider initial state q0 and process the input symbol 0.

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

Hence, δD(q0,0)=[q0, q1] New state

For input symbol 1,


40
δN (q0,1) = {q0}

Hence, δD(q0,1)=[q0] Existing state(Old state)

STEP 2: New statement [q0, q1] process the input symbols 0 &
δN ({q0, q1},0) =δN (q0,0)∪ δN (q1,0)
= {q0, q1}∪Φ
={q0, q1}
Hence δD ([q0, q1],0)=[q0, q1] Existing state
δN ({q0, q1},1) =δN (q0, 1)∪ δN (q1,1)
={q0} ∪ {q2}
={q0, q2}
Hence δD ([q0, q1],1)=[q0, q2]New state
STEP 3:New state is [q0, q2] process the input symbols 0 & 1
δN ({ q0, q2},0) =δN (q0,0)∪ δN (q2,0)
= { q0, q1}∪Φ
={ q0, q1}
Hence δD ([ q0, q2])=[q0, q1] Existing state
δN ({ q0, q2},1) = δN (q0,1)∪ δN (q2,1)
= {q0}∪Φ
={q0}
Hence δD ([ q0, q2],1)=[q0]Existing state
No new state can be found.
STEP 4: Construct the DFA transition table
INPUTS
STATES
0 1
 [ q0] [ q0, q1] [ q0]
[ q0, q1] [ q0, q1] [ q0, q2]
* [ q0, q2] [ q0, q1] [ q0]
STEP 5: Draw the DFA transition diagram:

41
∴ q0 is initial state in NFA, therefore
[q0] is initial state in DFA
∴ q2 is final state in NFA ,therefore [q0,
q2] is final state in DFA, because [q0,
q2] contains q2.

2.Construct DFA equivalent to the given NFA ({p,q,r,s},{0,1},δ,p,{s}) where δ is given


below:
INPUTS
STATES 0 1
p {p, q} {p}
q {r} {r}
r {s} _
*s {s} {s}
SOLUTION:

We construct a DFA M'= (Q', Σ,δ', q0’, F') an equivalent which accepts L(M).

STEP 1:The transition of DFA, δ'is calculated as,

Consider the initial state is ‘p’

δ'([p],0) =δ (p,0) =[p,q] New state [δ' or δD]


δ'([p],1) =δ (p,1) =[p] Existing state

Apply input symbols (0, 1), in the new state [p, q]

δ'([p,q],0) =δ (p,0) Uδ (q,0)


={p,q} U {r}
= [p,q,r] New state ok

δ'([p,q],1) =δ (p,1) Uδ (q,1)

={p} U {r}

=[p,r]New state

Apply input symbols (0, 1) in the new state [p, q, r]


δ'([p,q,r],0) =δ (p,0) Uδ (q,0) Uδ (r,0)
42
={p,q} U{r} U{s}

=[p,q,r,s] New state

δ'([p,q,r],1) =δ (p,1) Uδ (q,1) Uδ (r,1)

={p} U{r} U{ ϕ }

=[p,r] Existing state

Apply input symbols (0, 1), in the new state [p, r]


δ' ([p,r],0) =δ (p,0) Uδ (r,0)

={p,q}U{ s }

=[p,q,s]  New state

δ'([p,r],1) =δ (p,1) Uδ (r,1)

={p} U{ ϕ }

=[p] Existing state

Apply input symbols (0, 1), in the new state [p, q, r, s]


δ'([p,q,r,s],0)=δ (p,0) Uδ (q,0) Uδ (r,0) Uδ (s,0)

={p,q} U{r} U{s} U{s}

=[p,q,r,s] Existing state

δ'([p,q,r,s],1)=δ (p,1) Uδ (q,1) Uδ (r,1) Uδ (s,1)

={p} U{r} U{ ϕ } U{s}

=[p,r,s] New state

Apply input symbols (0, 1), in the new state [p, q, s]


δ'([p,q,s],0) =δ (p,0) Uδ (q,0) Uδ (s,0)

={p,q} U{r} U{s}

=[p,q,r,s] Existing state

δ'([p,q,s],1) =δ (p,1) Uδ (q,1) Uδ (s,1)

={p} U{r} U{s}

=[p,r,s] Existing state

Apply input symbols (0, 1), in the new state [p, r, s]


δ'([p,r,s],0) =δ (p,0) Uδ (r,0) Uδ (s,0)

={p,q} U{s} U{s}


43
=[p,q,s]  Existing state

δ'([p,r,s],1) =δ (p,1) Uδ (r,1) Uδ (s,1)

={p} U{s} U{s}

=[p,s]New state

Apply input symbols (0, 1), in the new state [p, s]


δ'([p,s],0) =δ (p,0) Uδ (s, 0)

={p,q} U{s}

=[p,q,s]  Existing state

δ'([p,s],1) =δ (p,1) Uδ (s, 1)

={p} U{s}

=[p,s]  Existing state

STEP 2 : Construct the DFA Transition Table :-

INPUTS
STATES 0 1
[p] [p, q] [p]
[p,q] [p,q,r] [p,r]
[p,q,r] [p,q,r,s] [p,r]
[p,r] [p,q,s] [p]
*[p,q,r,s] [p,q,r,s] [p,r,s]
*[p,q,s] [p,q,r,s] [p,r,s]
*[p,r,s] [p,q,s] [p,s]
*[p,s] [p,q,s] [p,s]
The final state F' = ([p,q,r,s],[p,q,s],[p,r,s],[p,s]),since it contains {s}.

STEP 2: Construct DFA Transition Diagram:-

44
Finite Automaton with Є-move/transition (or) NFA with Є- move/transition:

In NFA with Є- transition, a finite automaton is modified to allow transition


without input symbols, along with zero, one or more transition on input symbols, because
the transition made without symbols are called as Є – transition.
Example:

In this diagram, without reading any


input symbol the transition moves from
q0 to q1. This move is called Є – move.
This Є represent any number of times.

The NFA with Є – transition can be denoted as five tuples.


M = {q0, Σ, δ, q0, F)

Where,
 Q is a finite non empty set of states.
 Σ is a finite non empty set of symbols called the alphabets.
 δ is the transition function or mapping function where δ: Q X (Σ U ε) →2Q
 q0 is the initial state from where any input is processed (q0∈Q).
 F is a set of final state/states of Q (F⊆Q).

Acceptance of Language:

45
The string w in L accepted by NFA can be represented as,

L(M) = { w | w ∈Σ* and transition δ for w from q0 reaches to F }

Example: FA with ε- move

The transition diagram of the NFA accepts the language consisting of any number
of 0’s followed by any number of 1’s followed by any number of 2’s. For example, the
string w = 002 is accepted by the NFA along the path,

EXAMPLES :
1. Construct NFA with ε which accepts a language consisting the strings of any
number of a’s followed by any number of b’s followed by any number of c’s.

Normally ε’sare not shown in the input string. The transition table can be,

Inputs
States
a b c ε
q0 {q0} Ф Ф {q1}
q1 Ф {q1} Ф {q2}
*q2 Ф Ф {q2} Ф

δ (q0, aabbcc) ⊢δ (q0, abbcc)


We can parse the string ‘aabbcc’ as follows:

⊢ δ (q0, bbcc)
⊢ δ (q0, εbbcc)


δ (q1, bbcc)


δ (q1, bcc)
δ (q1, cc)

46
⊢ δ (q1, εcc)
⊢ δ (q2, cc)
⊢ δ (q2, c)
⊢ δ (q2, ε)
Thus, we reach to accept state, after scanning the complete input string.

ε–closure:
The ε–closure (p) is a set of all states which are reachable from state p on ε –
transition such that:
(i) ε – closure (p) = p where p∈ Q
(ii) If there exists ε–closure(p) = {q} and δ (q, ε) = r then
ε–closure(p) = {q, r}

EXAMPLE:
1. Find the ε–closure for the following NFA with ε.

Solution:
ε–closure(q0) = {q0, q1, q2} [ self state + ε reachable state]
ε–closure(q1) = {q1,q2}
ε–closure(q2) = {q2}

2. Consider the NFA given below and find (q0, 01) [or] Consider NFA with ε-
move (q0, 01).

Solution:
(q0, ε) = ε–closure(q0) = {q0, q1, q2} ------------------------------- 1
Thus,

47
(q0, 0) = ε–closure(δ ( (q0, ε), 0))
= ε– closure(δ(ε–Closure(q0),0))
= ε–closure(δ({q0, q1, q2}, 0)
= ε–closure(δ(q0,0) U δ (q1,0) U δ(q2,0))
= ε–closure({q0} U {Ф} U {Ф})
= ε–closure({q0})
= {q0, q1, q2} ------------------------------ From 1
Then

(q0, 01) = ε–closure(δ ( (q0, 0), 1))


= ε–closure(δ({q0, q1, q2}, 1)
= ε–closure(δ(q0,1) U δ (q1,1) U δ(q2,1))
= ε–closure({Ф} U {q1} U {Ф})
= ε–closure({q1})
= {q1, q2}

Since (q0, 01) = {q1, q2} which contain final state {q2}. It is an accepted string.
Equivalence of NFA’s with and without ε – moves [or Conversion of NFA with ε to
NFA without ε]
Theorem: If L is accepted by an NFA with ε – transition then L is accepted by NFA
without ε-transition.
Proof: Let M = (Q,Σ,δ,q0, F) be an NFA with ε – transitions. Construct M’ which is NFA
without ε – transition.
M’ = (Q,Σ,δ’,q0, F’)
Where,

Let x be any string

δ’(q0,x) = (q0, x)
This statement is not true if x = ε because δ’(q0,ε) = {q0} in NFA without ε and

(q0, ε) = ε-closure(q0) in NFA with ε


Basic Step:
|x|=1; x is a symbol whose value is a

δ’(q0,a) = (q0, a) [because by definition of ]


Inductive Step:
48
Let x = wa where a is in Σ& w in Σ*
δ’(q0,wa) = δ’(δ’(q0, w), a)

= δ’( (q0, w), a)


=δ’(p, a) [because by inductive hypothesis

δ(q0,w) = (q0, w) = P (say) ]


Now we must show that

δ’(P, a) = (q0, wa)


But,

= ( (q0, w), a)

= (q0, wa)

= (q0, x)

Hence δ’(qo, x) = (q0, x)


Conversion of NFA with ε to NFA without ε:
In this method to remove all the ε-transitions from given NFA.
Steps:
1. Find out all the ε-transitions from each state from Q. That will be called as ε-
closure{q}, where q ∈ Q.
2. Then δ’ transition can be obtained. The δ’ transition means an ε–closure on δ
moves.
3. Repeat step 2 for each input symbol and for each state of given NFA.
4. Using the resultant states, the transition table for equivalent NFA without ε can be
built.

EXAMPLES:

1. Convert the given NFA with ε to NFA without ε .

Solution:
Let, M = ( Q, Σ, δ, q0, F) be NFA with ε– transition.
M’ = ( Q, Σ, δ’, q0, F’) be NFA without ε–transition.
49
Step 1: Obtain the ε–closure of each state i.e. find out ε reachable states from current state.
ε–closure(q0) = {q0, q1, q2}
ε–closure(q1) = {q1, q2}
ε–closure(q2) = {q2}

Step 2: Final state, F’ = {q0, q1, q2}, Since q2 has appeared in ε–closure of all states.

Step 3: Then find the extended transition function of NFA with ε - move.
For each state, process all the input symbols {a, b}.

(q0, ε) = ε–Closure(q0) = {q0, q1, q2} [ δ’(q0, 0) = (q0, 0)]

(q0, 0) = ε–Closure(δ ( (q0, ε), 0))


=ε–Closure(δ (ε–Closure(q0),0))
= ε–Closure(δ({q0, q1, q2}, 0))
= ε–Closure(δ(q0, 0) U δ(q1, 0) U δ(q2, 0))
= ε–Closure(q0 U Ф U Ф)
= ε–Closure(q0)

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

(q0, 1) = ε–Closure(δ ( (q0, ε), 1))


= ε–Closure(δ (ε–Closure(q0),1))
= ε–Closure(δ({q0, q1, q2}, 1))
= ε–Closure(δ(q0, 1) U δ(q1, 1) U δ(q2, 1))
= ε–Closure(Ф U q1 U Ф)
= ε–Closure(q1)

(q0, 1) = {q1, q2}

(q0, 2) = ε–Closure(δ ( (q0, ε), 2))


= ε–Closure(δ (ε–Closure(q0),2))
= ε–Closure(δ({q0, q1, q2}, 2))
= ε–Closure(δ(q0, 2) U δ(q1, 2) U δ(q2, 2))
= ε–Closure(Ф U Ф U q2)
= ε–Closure(q2)

(q0, 2) = {q2}

(q1, 0) = ε–Closure(δ ( (q1, ε), 0))


= ε–Closure(δ (ε–Closure(q1),0))
= ε–Closure(δ({q1, q2}, 0))
50
= ε–Closure(δ(q1, 0) U δ(q2, 0))
= ε–Closure(Ф U Ф)

(q1, 0) ={ Ф }

(q1, 1) = ε–Closure(δ ( (q1, ε), 1))


= ε–Closure(δ (ε–Closure(q1),1))
= ε–Closure(δ({q1, q2}, 1))
= ε–Closure(δ(δ(q1, 1) U δ(q2, 1))
= ε–Closure(q1 U Ф)
= ε–Closure(q1)

(q1, 1) = {q1, q2}

(q1, 2) = ε–Closure(δ ( (q1, ε), 2))


= ε–Closure(δ (ε–Closure(q1),2))
= ε–Closure(δ({q1, q2}, 2))
= ε–Closure( δ(q1, 2) U δ(q2, 2))
= ε–Closure( Ф U q2)
= ε–Closure(q2)

(q1, 2) = {q2}

(q2, 0) = ε–Closure(δ ( (q2, ε), 0))


= ε–Closure(δ (ε–Closure(q2),0))
= ε–Closure(δ({q2}, 0))
= ε–Closure( Ф)

(q2, 0) ={Ф }

(q2, 1) = ε–Closure(δ ( (q2, ε), 1))


= ε–Closure(δ (ε–Closure(q2),1))
= ε–Closure(δ({q2}, 1))
= ε–Closure(Ф)

(q2, 1) ={ Ф }

(q2, 2) = ε–Closure(δ ( (q2, ε), 2))


= ε–Closure(δ (ε–Closure(q2),2))
= ε–Closure(δ({q2}, 2))
= ε–Closure(q2)
51
(q2, 2) = {q2}

Step 4: Construct the transition table for NFA without ε-transition :

Inputs
States
0 1 2
*q0 {q0,q1,q2} {q1,q2} {q2}
*q1 Ф {q1,q2} {q2}
*q2 Ф Ф {q2}

Step 5 : Draw the transition diagram of an NFA without ε-transition

2. Construct a NFA without Є – moves from NFA with Є – moves.

Solution:

Let, M = (Q, Σ, δ, q0, F) be NFA with ε– transition.


M’ = (Q, Σ, δ’, q0, F’) be NFA withoutε–transition.
Step 1: Obtain the ε–closure of each state i.e. find out ε reachable states from current state.
ε–closure(q0) = {q0, q1}
ε–closure(q1) = {q1}

52
Step 2: Final state, F’ = {q0, q1}, Since ε–closure(q0) contains final state q1, add q0 also
in set of final states for FA without ε–moves.

Step 3: Then find the extended transition function of NFA with ε - move.
For each state, process all the input symbols {a, b}

(q0, ε) = ε–closure(q0) = {q0, q1} [ δ’(q0, a) = (q0, a)]

(q0, a) = ε–closure(δ ( (q0, ε), a))


= ε–closure(δ (ε–Closure(q0),0))
= ε–closure(δ({q0, q1}, a))
= ε–closure(δ(q0, a) U δ(q1, a) )
= ε–closure(q0 U Ф )
= ε–closure(q0)

(q0, a) = {q0, q1}

(q0, b) = ε–closure(δ ( (q0, ε), b))


= ε–closure(δ (ε–Closure(q0), b))
= ε–closure(δ({q0, q1}, b))
= ε–closure(δ(q0, b) U δ(q1, b) )
= ε–closure(q0 U Ф )
= ε–closure(q0)

(q0, b) = {q0, q1}

(q1, a) = ε–closure(δ ( (q1, ε), a))


= ε–closure(δ (ε–Closure(q1), a))
= ε–closure(δ({q1}, a))
= ε–closure(Ф )

(q1, a) = Ф

(q1, b) = ε–closure(δ ( (q1, ε), b))


= ε–closure(δ (ε–Closure(q1), b))
= ε–closure(δ({q1}, b))
= ε–closure(q1)

(q1, b) = {q1}
Step 4: Construct the transition table for NFA without ε-transition :
53
Inputs
States
a b
*q0 {q0, q1} {q1}
*q1 Ф {q1}
Step 5 : Draw the transition diagram of an NFA without ε-transition

Shortcut Method:

States ε* Input a ε*
q0 q0 {q0,q1}
q0
q1 Ф -
ε* Input b ε*
q0 Ф -
q0
q1 q1 {q1}
ε* Input a ε*
q1 q1 Ф -
ε* Input b ε*
q1 q1 q1 {q1}

Conversion of NFA with Є to DFA:


In this method, we first convert NFA with Є to NFA without Є. Then the NFA
without Є can be converted to its equivalent DFA.

Prove that there exists a DFA for every Є-NFA.


Step 1: Consider M = (Q, Σ, δ, q0, F) is a NFA with ε. We have to convert this NFA with ε
toequivalent DFA denoted by MD = (QD, Σ, δD, q0, FD)

Then obtain,
ε–closure(q0) = { P1, P2, P3, . . . Pn} then [P1, P2, P3, . . . Pn] ∈QD
Step 2:We will obtain δ transitions on [P1, P2, P3, . . . Pn] for each input.
δD ([P1, P2, P3, . . . Pn], a) = ε–closure( δ (P1, a) U δ(P2, a) U . . . δ(Pn, a)

54
Where ‘a’ is input ∈Σ

Step 3: The states obtained [ P1, P2, P3, . . . Pn] ∈QD


The states containing final state in Pi is a final state in DFA.

EXAMPLES:

1. Convert the following NFA with Є to equivalent DFA.

Solution:
First find the Є-closure of all states.

ε–Closure(q0) = {q0, q1, q2}


ε–Closure(q1) = {q1, q2}
ε–Closure(q2) = {q2}

Now we will obtain transition, Let us start from Є-closure of start state.

ε–Closure{q0} = {q0, q1, q2} we will call this state as A

(A, a) = ε–closure(δ(A, a)
=ε–closure(δ(q0, q1, q2), a))
= ε–closure(δ(q0,a) U δ(q1,a) U δ(q2,a))
= ε–closure(q1)

(A, a) = {q1, q2} B (New State)

(A, b) = ε–closure(δ(A, b)
=ε–closure(δ(q0, q1, q2), b))
= ε–closure(δ(q0,b) U δ(q1,b) U δ(q2,b))
= ε–closure(q0)

55
(A, b) = {q0, q1, q2} A
Hence,

(A, a) = { q1, q2}

(A, b) = {q0, q1, q2}

Now let us find transitions for state,


B= { q1, q2}

(B, a) = ε–closure(δ(B, a)
=ε–closure(δ(q1, q2), a))
= ε–closure(δ(q1,a) U δ(q2,a))
= ε–closure(q1)

(B, a) = {q1, q2} B

(B, b) = ε–closure(δ(B, b)
=ε–closure(δ(q1, q2), b))
= ε–closure(δ(q1,b) U δ(q2,b))
= ε–closure(q0)

(B, b) = {q0, q1, q2} A


Hence,

(B, a) = {q1, q2}

(B, b) = {q0, q1, q2}

Transition table for DFA is,

Inputs
States
0 1
*A B A
*B B A

Transition Diagram for DFA is,

56
Final states are A and B, since the final state of NFA with ε is q2, which is present in
both A and B.

2. Convert the given NFA into its equivalent DFA.

Solution:page 122
First obtain the ε–closure of each state
ε–closure(q0) = {q0, q1, q2}
ε–closure(q1) = {q1, q2}
ε–closure(q2) = {q2}

57
3. Consider the following ε–NFA for an identifier. Consider the ε–closure of each state
and find its equivalent DFA.

Minimization of DFA:
DFA Minimization using Myphill-Nerode Theorem/Table Filling Method:
Procedure:

Step 2 –Mark all pairs where P ∈ FS and Q ∉ FS or vice versa and mark them. [Here FS is
Step 1 − Draw a table for all pairs of states (P, Q).

the set of final states]


Step 3 − If there are any unmarked pairs (P, Q), such that {δ (P, x), δ (Q, x)} is marked,
then mark [P, Q] where ‘x’ is an input symbol.
58
Repeat this step until nomore markings can be made.
Step 4 − Combine all the unmarked pair (P, Q) and make them a single state in the
minimized DFA.
Example:

Step 1 &2 − Draw a table for all pair of states&Mark the state pairs.
Check B, A  Both are non-final state, so

Check C, A C ∈ FS and A ∉ FS, so Mark


Unmark.

Check C, B C ∈ FS and B ∉ FS, so Mark


Check D, A D ∈ FS and A ∉ FS, so Mark
Check D, B D ∈ FS and B ∉ FS, so Mark
Check D, C D ∈ FS and C ∈ FS, so Unmark
Check E, A E ∈ FS and A ∉ FS, so Mark
Check E, B E ∈ FS and B ∉ FS, so Mark
Check E, C E ∈ FS and C ∈ FS, so Unmark
Check E, D E ∈ FS and D ∈ FS, so Unmark
Check F, A F ∉ FS and A ∉ FS, so Unmark
Check F, B F ∉ FS and B ∉ FS, so Unmark
Check F, C F ∉ FS and C ∈ FS, so Mark
Check F, D F ∉ FS and D ∈ FS, so Mark
Check F, E F ∉ FS and E ∈ FS, so Mark

Step 3 –Check the unmarked pairs.

δ(B, 0) = A δ(B, 1) = D
(A, B) is not already marked. So do not
Check (B, A) :
mark (B, A)
δ(A, 0) = B δ(A, 1) = C

δ(D, 0) = E δ(D, 1) = F
Check (D, C): (E, E) and (F, F) is no pair.
δ(C, 0) = E δ(C, 1) = F

Check (E, C) : δ(E, 0) = E δ(E, 1) = F (E, E) and (F, F) is no pair.


59
δ(C, 0) = E δ(C, 1) = F

δ(E, 0) = E δ(E, 1) = F
Check (E, D): (E, E) and (F, F) is no pair.
δ(D, 0) = E δ(D, 1) = F

δ(F, 0) = F δ(F, 1) = F
Check (F, A) : (F, C) is already marked. So mark (F, A)
δ(A, 0) = B δ(A, 1) = C

δ(F, 0) = F δ(F, 1) = F (F, D) is already marked. So mark (F, B).


Check (F, B) : [(F, A) is also marked, if anyone is marked
δ(B, 0) = A δ(B, 1) = D
already, we can mark (F, B)]

Step 4 –After step 3, we have got state combinations {A, B} {C, D} {C, E} {D, E} that are
unmarked.
We can recombine {C, D} {C, E} {D, E} into {C, D, E}
Hence we got two combined states as − {A, B} and {C, D, E}
So the final minimized DFA will contain three states {F}, {A, B } and {C, D, E}
Step 5: Minimized DFA diagram is,

60
http://www.plantuml.com/plantuml/umla/
JT3DYeCm5CNn_NsAiqmMWXywphWOtFH1nAGQI1NYBNtztjGhT2NdbxyY6G-
U4ZyVaQA_CtX72ilAS27vcSE-qJ5FqQCkIxo2u_LhhpwdH6GgMnJ5lwajC21wPfyWBFlZZHM-
KNxAX6ajCe1Cgz9f8Vk4NuNkWXy1_JJ9gUfVLXUMm2J5YO3fzMqvrb04WqX_HQOgDLBItyhIg4YZDFhDoI
Mz0G00

61

You might also like