Unit - 1 TOC
Unit - 1 TOC
COMPUTATION
capabilities of today‟s computer.
In 1940‟s and 1950‟s, the machines were simplified to finite automation machines.
Researchers proposed the automation model in order to model the functions of human brain.
The linguist Noam Chomsky made a study on formal grammars in late 1950‟s .These
grammars provided the basis of compliers.
S.Cook extended Turing‟s study in 1969, which separated the problems as solvable
and unsolvable. He classified problems as NP-Hard and as NP-Complete.
PUSH
Start
OFF ON
PUSH
1.2 Theory of Computation
Here,
When the electric switch = “ON” indicates logic „1‟ when pushed from start state.
t h e n
t th the then
a u t o m a t
a au aut auto autom automa automat
a automata
Subset [ ]
Let A1and A2 are two sets, then A1 is a subset of A2 [indicated as A1 A2 ], if every
element of A1 is in A2.
Example:
A1 = {1, 2, 3, 4}
A2 = {1, 2, 3, 4, 5}
A1 A2
Automata Fundamentals 1.3
Let A be a set of finite number of elements. Then A' is a set of elements that are not
the elements of set A. [A' A]
Example:
A1 = {a, e, i, o, u}
Operations on Sets
Union [ ]
The union of two sets results in a set containing the elements of both the sets (without
repeatition of elements).
Example:
A1 = {1, 3, 5, 7}
A2 = {1, 2, 3, 4,}
A1 A2 = {1, 2, 3, 4, 5, 7}
Intersection [ ]
The intersection of two sets contains a set of elements that are available in both the
sets.
Example:
A1 = {1, 3, 5, 7}
A2 = {1, 2, 3, 4}
A1 A2 = {1, 3}
Difference [ - ]
The difference of two sets A and B results in the set of elements that are in A and not
in B.
Example:
A1 = {1, 3, 5, 7}
A2 = {1, 2, 3, 4}
A1 – A2 = {5, 7} [A1 – A2 = A1 A2']
1.4 Theory of Computation
Laws on Sets
Commutative Laws
A B =B A
A B=B A
Associative Laws
A (B C) = (A B) C
A (B C) = (A B) C
Distributive Laws
A (B C) = (A B) (A C)
A (B C) = (A B) (A C)
Idempotent Laws
A A= A
A B=A
Absorptive Laws
A (A B) = A
A (A B) = A
De Morgan‟s Laws
(A B) ' = A' B'
(A B) ' = A' B'
Other Laws
(A') ' =A
A A' =
A A' = Universal set, ‟U‟
A =A
A =
A U =U
A U =A
Automata Fundamentals 1.5
Equality of sets [ = ]
Two sets are set to be equal if both the sets contain the same elements.
Example:
A = {1, 3, 5, 7}
B = {set of odd numbers less than 8}
Then, A = B
Empty set [ ]
A set containing no elements is said to be an empty set.
Example:
A = { set of natural numbers between 1 and 2}
A = or { }
Power of a set [ Ak ]
The power of a set A, denoted by A k is the set containing all elements of A, whose
length is less than or equal to k.
Example:
A = {1, 2}
A2 = { , 1, 2, 12}
Relationship of Sets
Relation of two sets is the association of one set with other.
Logic
Logic deals with the logical proportions and connectives.
Proposition
Proposition is a meaningful, objective, declarative statement that has a truth value as
true / false.
1.6 Theory of Computation
Example:
0 1, New Delhi is the capital of India, 5 is an even number, Chennai is in AP.
Connective
Logical connective is a compound statement formed from simple proportions using a
connective such as
and connective /conjunction
or connective /disjunction
Not / Negative connective
Example
p Q p^q pq p q
T T T T F F
T F F T F T
F T F T T F
F F F F T T
Implication
It is a conditional statement of the form, “if p then q” (p implies q), where p and q are
simple proportions.
It is denoted as p q = p q
p q pq
T T T
T F F
F T T
F F T
Proofs
A proof is single line / multiline derivation that provide a convincing argument to
make a statement true.
Proofs can be derived from assumptions or facts or existing derivations.
Automata Fundamentals 1.7
Forms of Proofs
There are basically two forms of proofs. Thery are,
1) Deductive Proofs
2) Inductive Proofs
Deductive Proofs
These are sequence of statements which are derived from any assumption (hypothesis)
or a given initial statement to a conclusion statement.
The proofs are generated using some facts / accepted logics.
Example: If x 4, 2x x2
Conclusion statement 2x x2
Hence proved.
Inductive Proof
It has a sequence of recursive / parametrical statements that handle the statement with
lower values of its parameters.
There are two types of inductions, namely -
Mathematical Induction
Structural Induction
Mathematical Induction
This follows induction principle that follows two steps, namely-
Basis of Induction: It considers „n‟ of f(n) as the lowest possible integer (n = 0 or 1)
and prove the given statement using substitution.
1.8 Theory of Computation
Inductive step: Assume that the given statement is true for nth value and prove the
statement for n = n+1.
Structural Induction
Structural Induction follows the mathematical induction concept but applies for trees
and expressions.
Example: Every tree has one node than it has edges, balancing parenthesis etc.
Proof about the set includes the proofs on the properties of the sets.
Consider, A = P Q, B = Q P
This proof follows “if and only if” type. This is A= B is true if and only if
P Q = Q P is true.
Proof by contradiction
The proof p q is true, then the method follows a contradictory assumption that
p q and from the result, it proves the assumption is false and thus proves, p q.
Example:
xϵPQ
Given a statement, that can be proved to be true for a domain of input instances, and
false for other inputs.
Let a = 5 and b = 10
a % b = 5 % 10 = 5
b % a = 10 % 5 = 0
Thus proved.
Inductive Proofs
These are special type of proofs used to prove recursively defined objects.
It consists of sequence of parameterized statement that uses the statement itself with
lower values of its parameter.
Two steps
SAMPLE PROBLEMS:
1. Prove that: 1+2 +3+ ………+n (n+1) / 2 using method of induction for (n>0).
Proof:
Basis of Induction
Let n = 1 [We cannot take n = 0 since U.H.S starts from 1]
L.H.S = 1
111 1 2 2
R.H.S 1
2 2 2
1.10 Theory of Computation
Inductive Step
n n 1
We have 1 2 3 n
2
Sub n = n + 1
n
L.H.S 1 + 2 + 3 +…… + n = i
i1
= i (n 1)
i1
n(n 1)
= (n 1)
2
n(n 1) 2(n 1)
=
2
n2 n 2n 2
=
2
n2 3n 2
= ----- (1)
2
n(n 1)
R.H.S =
2
When we substitute n=n+1,
(n 1)((n 1) 1)
R.H.S =
2
(n 1)(n 2)
=
2
n2 2n n 2
=
2
Automata Fundamentals 1.11
n2 3n 2
= ----- (2)
2
From (1) and (2), L.H.S = R.H.S
So the given hypothesis is proved.
i1 6
Basis of induction
Let n=1 (we can‟t take n=0 since i=1 in L.H.S)
n
L.H.S = i
i1
2
= 12 = 1
Inductive step
n
n(n 1)(2n 1)
i
i1
2
6
n 3 2
= i2 (n 1)2
i1
i2 i2 (3)2
i1 i1
n(n)(2n 1)
= (n 1)2
6
(n 1)(n 2)(2n 2 1)
=
6
(n2 2n n 2)(2n 3)
=
6
3) P.T for every integer, n 0 the number 42n1 3n2 is a multiple of 13.
Solution
Basis of induction
Let n = 0
= 41 32 4 9
= 13 multiple of 13
Inductive proof
Let n=n+1
= 42n21 3n3
Automata Fundamentals 1.13
= 42n3 3n3
= 42n1.42 3n2.31
= 16(42n1 ) 3(3n2 )
Multiple of 13
= 13(42n1 ) 3(13n)
n4 4n2 0 0 0 3 0 Divisible by 3
Hence proved.
Inductive step
Let us assume that n4 4n2 is divisible by 3 for n, and try to prove the same for n=n+1
4n3 6n2 4n 3
Divisible by 3
FINITE AUTOMATA
Basic Definitions
Alphabet ( )
Example:
Length of a string ( )
Let be the string, then the length of the string, is the number of symbols
composing the string.
Example:
010 ; 3
;0
abcba ; 5
Automata Fundamentals 1.15
Concatenation of strings
The concatenation of two strings '' and ' v ' is the string obtained by appending the
symbols of v to the right end of .
Example:
010
v 111
v 010111
Power of an alphabet ( k )
If is an alphabet, we can express the set of all string of a certain length from that
alphabet by using an exponential notation.
0
0
a, b, c
1
aaa, bbb, ccc, aab, aac, aba, aca, abb, acc, abc, acb, bba, bbc, bab, bcb, baa, bcc,.....
3
Reversing a string ( R )
The reverse of the string is obtained by writing the string in reverse order.
Example:
abc
R cba
Kleene closure ( * )
Let be an alphabet. Then the kleen closure, * denotes the set of all strings over
the alphabet,
1.16 Theory of Computation
Example:
2) Let 1
0
1
1
11
2
* 0
1 2 .....
,1,11,111,...
Example:
1 ,0
1
*
Substring
The string, v if it appears within another string , then v is called as the substring
of .
Automata Fundamentals 1.17
Example:
Let v111 ; 010111
v is a substring of
Let 1, 2,3
Prefixes ,1,12,123
Palindrome
A palindrome is a string which is same when read in backward or forward direction.
R is a palindrome
Example: 1001
Language (L)
Alphabet finite set of symbols
Example:
1) {a, b}
2) {0,1}
L{Set of stringsending with11}
= {ε, 11, 011, 0011, 1011, 0111, 101111, …}
| xy || x | | y |
y101
Then xy10101Concatenation.
| xy || x | | y |
23
5
Operations of Languages
1. Product or concatenation (L1 L2 )
L1{b, ab, aab, ... }{an b, n 0}
2. Reversal (LR )
The reversal of a language is a set of all string reverses.
LR {wR / wL}
Model of FA
a1 a2 a3 a4 … Infinite tape
Read Head
Finite
CPU
control
Input Tape
It is divided into number of cells.
Each cell holds one symbol.
Read Head
Reads one cell at a time and moves ahead.
Finite Control
Acts like a CPU.
Depending on current state and input symbol read from tape, it changes state.
Formal Definition of FA
M(Q, , , q0 , F)
FA consist of 5 Tuples,
Q Set of finite states.
q0 Start state
F Set of final states. [FQ]
Representation of FA
1. Transition Diagram
2. Transition Table
1.20 Theory of Computation
Transition Diagram
It can be directed graph with vertices of a graph corresponding to states and edges
indicates transition from one state to another
0 1
q0 q1 q2
Start
Final
state
state
Start state indicated by circle.
Start transition indicated by arrow.
Final state indicated by double circle.
Transition Table
It is a tabular listing of the transition function which by implication tells us, set of
states and input alphabet.
b
a b
q0 q1 q2
State a b
(q0 , a) q1
Input
(q 0 , b) q 0
q0 q1 q0
(q1 , b) q 2
q1 q2
*q2
Applications
1. Design of digital circuits.
2. String searching
3. Communication protocols for information exchange.
4. Lexical analysis phase of a compiler.
Types
1. Deterministic Finite Automata [DFA]
2. Non-Deterministic Finite Automata [NFA]
Automata Fundamentals 1.21
Properties of DFA
There is only one path for an input from current state to next state.
It contains only one final state.
PROBLEMS
1. Design a DFA for the language, L {anb; n 0}
If n 0La 0 b b n 3La 3 b aaab
n 1La 1 b ab n 4La 4 b aaaab
n 2La 2 b aab n 5La5 b aaaaab
a
b
q0 q1
{a, b}
q0 {q0 }
Transition function,
(q0 , a) {q0 }
1.22 Theory of Computation
(q0 , b) {q1}
(q1 , a)
(q1 , b)
F{q1}
2. Design a DFA that accept L {w / w (a, b,c), and w contains only abac}
a b a c
q0 q1 q2 q3 q4 Valid input: abac
Trap
3. Design a DFA that accept L {w (0, 1)*, where every 0 in w has 1 immediately to
its right.
0 1 Valid input
q0 q1 q2 01
0 1
q0 q1 q2 0101
0
1 1
101, 1101
0 1
q0 q1 q2 Invalid inputs:
0 00, 10, 1100, 1001, ….
0
Trap q2
0, 1
1 0 1
q0 q1 q2 q3 Invalid inputs:
00, 100, 010, 1010, …
1 0
0 0, 1
q4
Trap 0, 1
a b Valid inputs:
q0 q1 q2 101
a, b
a b aba, abb, abaa, abbb,
q0 q1 q2
abab, ….
b a, b Invalid inputs:
a
q0 q1 q2 ba, aa, aab, bab, aaaa,
baab, ….
b a
q1
Trap
a, b
6. Design a DFA that accepts all strings of length atmost 5 over {0, 1}
Valid inputs:
0, 00, 000, 0000,
0, 1 0, 1 0, 1 0, 1 0, 1 00000, 1, 11, 111,
q0 q1 q2 q3 q4 q5
1111, 1111, 10101,
010, 100, 0010, …
0, 1 0, 1 0, 1 0, 1 0, 1
q0 q1 q2 q3 q4 q5 Invalid inputs:
101010, 0000000,
11110000,
0, 1 100011001,
q1 1111111111, …
Trap
0, 1
1.24 Theory of Computation
a a Valid inputs:
q0 q1 q2
aa
a a
q0 q1 q2
aaaa, aaaaaa, a8, a16, ...
a
a q3 a
Invalid input
q0 q2 a, aaa, aaaaa, a7, a17, ...
a a
q1
8. Design a DFA that accepts a language, L having even number of 0s and 1s.
0 Valid inputs:
q2 q1 00, 11, 0000, 1111, 08, 18, …
0
1 1
q1
0
q2 q1 0110, 0101, 1010, 1100, 110011,
0 10101010, 00001111, ...
1 1 1 1 Invalid inputs
0 0, 1, 000, 111, 101010, 110, 1101,
q1 0100, …
q1 0
Automata Fundamentals 1.25
9. Design a DFA that accepts all strings containing atleast two zeroes.
Valid inputs:
0 0
q0 q1 q2 00
0, 1
0 0 00, 000, 0000, 00000, 0001,
q0 q1 q2
000111, …
1
0, 1
0 0 100, 1100, 11100000,
q0 q1 q2
110011, 1001, 11000010, …
10. Design a DFA that accepts strings ending with „00‟ over {0, 1}
Valid inputs:
0 0
q0 q1 q2 00
0
0 0 000, 0000, 00000, …
q0 q1 q2
1
0
q0 0 0 100, 1000, 1100 110000, …
q1 q2
1
0 0100, 101000, 110100, …
0 0
q0 q1 q2
1
1
0 00100, 1000, 1010100, 001000
0 0
q0 q1 q2
1 Invalid input:
1 001, 0011, 101, 10011, 1, 01, ..,
1.26 Theory of Computation
11. Design a DFA that accepts a language, L which has the number of zeroes is of
multiples of 3.
Valid inputs:
0 0
q0 q1 q2 000, 000000, 09, 012, …
0
1
0 0
q0 q1 q2 1, 1000, 100000, …
0
1 1
0 0
q0 q1 q2 10100, 11000, 101100, …
0
1 1
1
0 101010, 1101010, 1101110110, …
0
q0 q1 q2 Invalid inputs: 0,00,10000,01011, …
12. Design a DFA that accepts L 01 12j , i 1; j 1
i
1 1
q0 0 1 q3 Valid inputs:
q1 q2 q4
i = 1, j = 1 L = 0111
0 1 1 1 i = 1, j = 2, L = 011111
q0 q1 q2 q3 q4
i = 1, j = 3, L = 01111111
1
i = 2, j = 1 L = 010111
1 1 1
q0 0 q1 q2 q3 q4 i = 3, j = 1, L = 01010111
i = 2, j = 2 L = 01011111
0 1 i = 3, j = 3, L = 010101111111
Automata Fundamentals 1.27
Invalid inputs:
0 1 1 1
q0 q1 q2 q3 q4 1, 00, 0100, 0110, 01110,
1 011110, 1000, 101, …
0 0
0
Trap
0, 1
13. Design a DFA that accepts L a, b / n b mod 3 1
*
Valid inputs:
b b
q0 q1 q2 bb, b5, b8, b11 [No. of b%3]
bb 2b‟s 2% 3 2
b > 1
a bbbbb 5b‟s 5%
3 2 > 1
b b bbb 3b‟s 3% 3 0
q0 q1 q2
> 1
b
abb, abbbbb, ab8, …
a a
a-b2, a3b5, ...
b b
q0 q1 q2 bab, abab, aabbbbb, …
a a a
bba, bbaa, abba, abbaa, ….
b b Invalid inputs:
q0 q1 q2
b, b3, b4, b6, b7, b9, a, aa, aaa, aba,
b baa, ababb
1.28 Theory of Computation
14. Design a DFA accepting strings containing exactly one 1 over {0, 1}
1 Valid inputs:
q0 q1 1
0 0
0 0
1
q0 q1 Invalid inputs:
11
1
Trap q2
0 0
1
q0 q1 0110, 0101, 1111, 101,…
Trap q2 0, 1
15. Design a DFA that accepts all strings with exactly two 1s over {0, 1}
Valid inputs:
1 1
q0 q1 q2 1
0
1 1
q0 q1 q2 011, 0011, 00011, …
0 0
1 1
q0 q1 q2 0101, 1001, 101, …
Automata Fundamentals 1.29
0 0 0
1 1
q0 q1 q2 110, 01010, 1010, 11000 ….
0 0 0
Invalid inputs:
1 1
q0 q1 q2 111, 1110, 0111, 10101, 1111,
1110101, …
1
Trap q3 0, 1
0 0
q0 q1 q2 000, 0000, 00000, …
1 0
0 0
q0 q1 q2 100, 1100, 11000, …
1 0
0 0
q0 q1 q2 10100, 1101100, 101101, ….
1
0, 1
1
0 0 Invalid inputs:
q0 q1 q2
1001, 11001, 101001, …
1
1.30 Theory of Computation
17. Design a DFA that accepts string, such that its second symbol is zero and fourth
symbol is 1.
Valid inputs:
0 0 0 1
q0 q1 q2 q3 q4 0001
q0 0, 1 0 0 1 1001
q1 q2 q3 q4
0, 1 0 0 1
q0 q1 q2 q3 q4 0011, 1011
0, 1
0, 1 0 0, 1 1 00010, 10010, 00110, 00011,
q0 q1 q2 q3 q4
10011, 00111, …
0, 1
0, 1 Invalid inputs:
0 0, 1 1
q0 q1 q2 q3 q4 0101, 0100, 0010, 1100,
0000, 1000, …
1 0
q5
Trap
0, 1
0, 1 0 0, 1 1
q0 q1 q2 q3 q4 01010, 01000, 11111,
0100000, …
1 0
q5
Trap
0, 1
Automata Fundamentals 1.31
a a a Valid inputs:
q0 q1 q2 q3 aaa, a, aa,
b
a a a
q0 q1 q2 q3 b, ba, baa, baaa, bb, bba, bbba,
…
b b
a a a
q0 q1 q2 q3 bab, abba, abbbaa, babba,…
b b b
a a a
q0 q1 q2 q3 babab, aabb, aaba, bbbaaba, …
b b b b
a a a
q0 q1 q2 q3 aaabbb, aaabab, baaaba, …
b b b b
a a a Invalid inputs:
q0 q1 q2 q3 aaaa, aaabab, baaaba,
a, b q4
Trap
1.32 Theory of Computation
19. Design a DFA that accepts all strings containing substring „101‟.
Valid inputs:
1 0 1
q0 q1 q2 q3 101
0
1 0 1
q0 q1 q2 q3 0101, 000101, …
0 1
1 0 1
q0 q1 q2 q3 011101
0 1 0, 1
1 0 1
q0 q1 q2 q3 10100, 101, 101101, …
0
0 1 0,1
Complementary
1 0 1
q0 q1 q2 q3 [Does not accept
substring with „101‟]
0
20. Design a DFA to check whether a string over {a, b}contains „abb‟ is accepted.
a Valid inputs:
b b
q0 q1 q2 q3 abb
b
a b b
q0 q1 q2 q3 babb, bbabb, …
b a
a b b
q0 q1 q2 q3 aabb, baaabb, …
b a
a b b
q0 q1 q2 q3 ababb, abaabb, bababb, …
a
b a a, b
abba, abbb, abbab
a b b
q0 q1 q2 q3
a Invalid inputs:
ab, bbb, aaaa,abab, aaba,…
Automata Fundamentals 1.33
21. Design a DFA that accepts odd number of ones over {0, 1}
1 Valid inputs:
q0 q1 1
1
q0 q1 111, 11111, 17, 19, 111, …
1
0
1
q0 q1 01, 001, 0000111, …
1
0 0
10, 1011, 10001111, 01101,…
1
q0 q1
Invalid inputs:
1 11, 1111, 0110110, 111100110, …
1
0 0 1
q0 q1 q2 q3 1001, 11001, 111001, …
1 0
0 0 1
q0 q1 q2 q3 0001, 000001, …
1 0 0, 1
0 0 1
q0 q1 q2 q3 00010, 110011, 110010, …
1 0 0, 1
0 0 1
q0 q1 q2 q3 101001, 10101001, …
1
Invalid inputs:
1111, 0111, 0101, 000, …
1.34 Theory of Computation
23. Design a DFA that recognize words which do not end in „b‟ over {a, b}
a
Valid inputs:
a, aa, aaa, aaaa, …
q0
Valid inputs:
1 1 1 1
q0 q1 q2 q3 q4 1111
0 0 0 0 0
q0
1 0 0 1 01111, 010100, 01010101,
q1 q2 q3 q4
1111000, 1101100, …
0 0 0 0 0
q0
1 1 1 1 Invalid inputs:
q1 q2 q3 q4
111101, 10101011, 110111, …
1
Trap q5
0 0 0 0 0
q0
1 1 1 1 1111010, 1111011, …
q1 q2 q3 q4
1
q5
0, 1
Automata Fundamentals 1.35
Extended transition function: δ Delta Cap/Hat
The extended transition function, takes two parameters, state and string.
It is a mapping from Q * Q
Formally cann be defined as
o (q0 ,)q 0
PROBLEMS
1) Consider the transition diagram
b a a, b
a b
q0 q1 q2
2) Consider the FA
a
a
q0 b
q1
b
1.36 Theory of Computation
(q0 , bba)
(q1 , ba)
(q0 , a)
q0 Final state string is accepted
2) 2 aba
(q1 , a)
q1 Not a final state string not accepted
3) Check whether the strings “ababba” ,”baab” are accepted by the DFA?
AU – May / June, Nov / Dec 2009
a b
a
q0 q1 q2
a, b
1) 1 ababba
PROBLEMS
1) Sketch the NFA state diagram for M = (q 0 , q1 , q 2 , q3 , 0,1 , , q 0 , q 3 ) with given as
∑ 0 1
Q
q0 (q0 , q1 ) (q0 , q2 )
q1 q3
q2 q3
* q3 q3 q3
Solution:
0, 1 0, 1
0 q1 0
q0 q3
1 q2 1
Automata Fundamentals 1.39
2) Design a NFA with no more than five states for the set abab n : n 0 aba n : n 0 .
b
a b a
q0 q1 q2 q3
a
q4
a
a a, b
q0 q1 q2
q0 0
q1
1
0
1 1
q2
0
:
∑ 0 1
Q
q0 q 0 , q1 q 2
q1 q1 , q 2
* q2 q0 , q 2 q1
Solution:
(q0 , 0100)
(q0 , 0) q 0 , q1 (q 0 , q1 , 0) q 0 , q1 q 0 , q1
(q0 , 01) ((q0 , 0),1)
(q 0 , q1 ,1)
1.40 Theory of Computation
q1 , q 2
(q0 , 010) ((q0 , 01), 0)
(q1 , q 2 , 0)
(q1 , 0) (q2 , 0)
q 0 , q 2
q 0 , q 2
(q0 , 0100) ((q0 , 010), 0)
(q 0 , q2 , 0)
(1, b) (2, b)
1 3
1, 3
(1, aba) ((1, ab), a)
(1,3, a)
(1, a) (3, a)
1, 24
1, 2, 4
(1, abab) ((1, aba), b)
(1, 2, 4, b)
(1, b) (2, b) (4, b)
1 3 1,3
2) (2, baba) :
(2, b) 3
(2, ba) ((2, b), a)
(3, a)
4
(2, bab) ((2, ba), b)
(4, b)
(2, baba) ((2, bab), a)
(, a)
6) Design a NFA to accept strings containing the substring,”0101”.
0, 1 0, 1
0 1 0 1
q0 q q q q
1 2 3 4
1.42 Theory of Computation
Q q 0 , q1 , q 2 , q3 , q 4
0,1
q 0 q 0
F q 4
is given as
∑ 0 1
Q
q0 q 0 , q1 q 0
q1 q 2
q2 q 3
q3 q 4
* q4 q 4 q 4
7) Construct a NFA that accepts L x a, b/ x ends with 'aab'
a, b
a a
q0 q1 q2
b q3
M(Q, , , q0 , F) is given as
Q q 0 , q1 , q 2 , q 3
∑ a b
a, b Q
q0 q 0 , q1 q 0
q 0 q 0
q1 q 2
F q3
q2 q3
* q3
Automata Fundamentals 1.43
8) Design a NFA to accept strings over alphabet0, 1, such that the third symbol from
right end is 0.
0, 1
0 0, 1 0, 1
q0 q1 q2 q3
Q q 0 , q1 , q 2 , q3 The transition function, is given as
0,1
∑
0 1
q0 q0 Q
F q3
q0 q 0 , q1 q 0
q1 q 2 q 2
q2 q3 q3
* q3
L x {a, b, c : x contains exactly one b immediately
*
9) Construct a NFA for
following c}.
a, b a, b, c
c a, c
q0 q1 q1
1 b
Trap
a b
q4
10) Construct a NFA that accept L x {0, 1 : x is starting with 1 and | x | is divisible
*
by 3}.
0, 1
q4 Trap
0
q1
1 0, 1
q1
0, 1
q3 0, 1
1.44 Theory of Computation
11) Design a NFA for L = L {x {a, b}* / x contains any number of a‟s followed by
atleast one b}.
a b a, b
b a
q0 q1 q2
Trap
12) Design a NFA for a binary number where the first and the last digits are same.
0, 1
q2
0 q4
0
q1
1 1
q3 q5
0, 1
13) Construct a NFA over 0, 1 such that each „0‟ is immediately preceded and
immediately followed by 1.
1
1
q0 q1
0 1
0
q3 0
q2
0, 1
Trap
0,1
0 1
q0 q1 q2
Every language that can be described by some NFA can also be described by some
DFA. It involves subset construction process for conversion.
Automata Fundamentals 1.45
PROBLEMS
1) Construct a DFA from the following NFA that accepts all strings of 0‟s and 1‟s that
end with „01‟. AU - NOV/DEC 2013, NOV/DEC 2003, MAY/JUNE 2006
Solution:
NFA
0,1
0 1
q0 q1 q2
Here ,
QN q 0 , q1 , q 2
0,1 ∑ 0 1
Q
q 0 q 0
q0 q 0 , q1 q 0
F q 2
q1 q 2
* q2
1.46 Theory of Computation
Subsets
QD , q 0 , q1 , q2 q0 , q1 q0 , q 2 q1 , q 2 q 0 , q1 , q 2
Transition table: D
∑
0 1
Q
→ q 0 q 0 , q1 q 0
q1 q 2
* q 2
Minimised DFA
1 0
0 1
{q0} {q0 , q1} {q0 , q 2}
0
1
Automata Fundamentals 1.47
QN p, q, r,s N : ∑
0 1
Q
0,1 →p p, q p
q0 p q r r
FN s r s
0 0, 1 0, 1
p q r s
Subsets
QD ,p,q,r,s,p, q, p, r,p,sq, r,q,s,r,s,
p, q, r,p, q,s,q, r,s,p, r,s,p, q, r,s
QD 24 16
Transition table
∑
0 1
Q
p p, q p
q r r
r s
*s s s
p, q p, q, r p, r
p, r p, q,s p
*p, s p, q,s p, s
q, r r, s r
*q, s r, s r, s
*r, s s s
1.48 Theory of Computation
0 0
{p} {p, q} {p, q, r}
1 0
1
1 0
{p, r} {p, q, r, s}
0
0 1
1
{p, q, s} {p, r, s}
0
0 1
{pp,,ss}
1
Automata Fundamentals 1.49
∑
0 1
Q
p q, s q
q* r q, r
r s p
*s p
Solution:-
Here,
QN p, q, r,s
0,1
q0 p
FN q,s
0
p
0, 1 0, 1 0
r r s
1 1
1
Subsets:
QD ,p,q,r, s,p, q,p, r,p,s ,q, r,q,s,r,s,p, q, r ,
p, q,sp, r,s,q, r,s,p, q, r,s
FD q,s,p,s,q, r,q,s, r,s,p, q, r,p, q,s, p, r,s,q, r,s,p, q, r,s
Transition table:-
∑
0 1
Q
p q, s q
*q r q, r
1.50 Theory of Computation
*s p
p, q q, r,s p, q, r
p, r q, s p, q
*p, s q, s p, q
q, r r, s p, q, r
*q, s r p, q, r
*r, s s p
p, q, r q, r,s p, q, r
*p, q,s q, r,s p, q, r
*p, r,s q, s p, q
*q, r,s r, s p, q, r
*p, q, r,s q, r,s p, q, r
Minimised transition table:-
∑
0 1
Q
p q, s q
q, s r p, q, r
q r q, r
r s p
p, q, r q, r,s p, q, r
q, r r, s p, q, r
s p
q, r,s r, s p, q, r
*r, s s p
Automata Fundamentals 1.51
DFA diagram:-
1
1
{q, s} {p, q, r}
0 0
{p}
1 {r}
0 1 {r, s}
1 0 1
0
1 {q} 1 {q, r, s}
0
1 {q, r}
{s} 0
0
0 1
q0 q1 q2
0 1
Solution:-
QN = {q0, q1, q2} ∑
0 1
Q
∑ = {0, 1}
→{q0} {q0, q1}
q0 = {q0} {q0} {q2}
FN = {q2} *{q2} {q2}
Construction of DFA:-
QD = {, {q0}, {q1}, {q2}, {q0, q1}, {q0, q2}, {q1, q2}, {q0, q1, q2}}
q0 = {q0}
1.52 Theory of Computation
Transition table:-
∑
0 1
Q
{q0} {q0, q1}
{q1} {q2}
*{q2} {q2}
{q0, q1} {q0, q1} {q2}
*{q0, q2} {q0, q1} {q2}
*{q1, q2} {q2}
{q0, q1, q2} {q0, q1} {q2}
Minimized DFA:-
1
0
0 1
{q0} {q0 , q1} {q2}
5) Convert M = ({q1, q2, q3}, {0, 1}, {q1}, {q3}), where is given by,
(q1, 0) = {q2, q3} (q1, 1) = {q1}
(q2, 0) = {q1, q2} (q2, 1) =
(q3, 0) = {q2} (q3, 1) = {q1, q2}
Construct an equivalent DFA
Automata Fundamentals 1.53
Solution:
Given NFA,
1 0
0
0 0,1
q1 q2 q3
0
1
∑
0 1
Q
DFA Construction:-
∑ = {0, 1}
QD = {, {q1}, {q2}, {q3}, {q1, q2}, {q1, q3}, {q2, q3}, {q1, q2, q3}}
q0 = {q1}
FD = {{q3}, {q1, q3}, {q2, q3}, {q1, q2, q3}}
Transition Table:-
∑
0 1
Q
→
{q1} {q2, q3} {q1}
{q2} {q1, q2}
* {q3} {q2} {q1, q2}
{q1, q2} {q1, q2, q3} {q1}
* {q1, q3} {q2, q3} {q1, q2}
* {q2, q3} {q1, q2} {q1, q2}
* {q1, q2, q3} {q1, q2, q3} {q1, q2}
1.54 Theory of Computation
Minimized DFA:-
0
1
0 0,1 0
{q1} {q2 , q3} {q1, q2} {q1, q 2 , q3}
1
1
D ({q0 }, w) N ({q0 }, w)
For an arbitrary string w, we prove this statement, we use induction principle on w .
Basis of Induction:-
Let w =0
Then w = ε
By the definition of extended transition function,
D ({q0 },) {q0 } ----- (1)
Automata Fundamentals 1.55
Now let us prove that the same is true for a string of length, n+1
Let w = xa, where
a → last symbol of w.
By assumption, we have,
D ({q0}, x) N ({q0}, x)
k
{P1, P2 ,.....Pk } subsets Pi
i1
Now, by the definition of extended transition function of DFA,
D ({q0}, x) D ({q0}, xa )
= D (({q0}, x), a)
= D ({P1, P2, .... Pk}
Ui1
K
N (Pi, a) Bysubset construction
0 0 2
Є CLOSURE {q0} = {q0, q1, q2}
Є CLOSURE {q1} = {q1, q2}
Є CLOSURE {q2} = {q2}
Find Є- CLOSURE of States 1,2 and 4 from the following transition diagram.
AU MAY 2008
Є Є
3 6
2
Є
1 Є
a 7
4 5
Є
c) (s, a) U ECLOSE(r ) m
D j1 j
PROBLEMS
1) Design a DFA that eliminates Є transition from the following Є- NFA.
∑
Є a b c d
QE
q0 q0, q1
q1 q1 q1, q2 q3
q2 q2, q3 q2 q2
*q3 q3 q3 q3
a c,d
Є a
q0 q1 q2
b Є
q3
a,b
Solution :-
Start state of DFA:-
ECLOSE (q0) = {q0, q1} → Start State of DFA
1.58 Theory of Computation
D ({q0 , q1}, b) :
E (q0 , b)
E (q1, b) {q3}
E ({q0 , q1}, b) {q3}
D ({q0 , q1}, b) ECLOSE(q3 )
D ({q0 , q1}, b) {q3}
D ({q0 , q1}, c) :
E (q0 , c)
E (q1 , c)
E ({q0 , q1}, c)
D ({q0 , q1}, c) ECLOSE ()
D ({q0 , q1}, c)
D ({q0 , q1}, d) :
E ( q0 , d)
E ( q1 , d)
E ({q0 , q1}, d)
D ({q0 , q1}, d) ECLOSE ()
D ({q0 , q1}, d)
Automata Fundamentals 1.59
D ({q1, q2 , q3}, a) :
E (q2 , a)
{q1}U{q2 , q3}U{q3}
D ({q1, q2 , q3}, b) :
E (q1, b) {q3}
E (q2 , b)
E (q3 , b) {q3}
D ({q1, q2 , q3}, c) :
E ( q1 , c)
E (q2 , c) {q2}
E ( q3 , c)
D ({q1, q2 , q3}, d) :
E ( q2 , d)
E (q3 , d) {q2}
E ( q3 , d)
1.60 Theory of Computation
Transition Table:-
∑
a b c d
QD
Equivalent DFA:-
a
{q0 , q1} {q1, q2 , q3}
b
b
c, d
{{{qq33}}
a, b {q2 , q3}
a, b c, d
Є C e
q0 q1 q2 q3
Є
b C
q0 Є
q5
a
Solution:-
Start of DFA:-
ECLOSE(q0) ={q0, q1}
↓
Start State of DFA
U{q4} {q1}
Automata Fundamentals 1.63
∑
Є a b c d e
QD
q0 q0, q1
q1 q1 q1 q4 q2
q2 q2 q2 q3
q3 q3, q5 q3
q4 q4, q5 q4 q2
*q5 q5
D ({q0 , q2 ,}, b) :
E ({q0 , q1}, b) E ({q0}, b)UE ({q1}, b)
U{q4}
{q4}
D ({q0 , q1}, b) ECLOSE(q4 )
D ({q0 , q1}, b) {q4 , q5}
D ({q0 , q2 ,}, c) :
E ({q0 , q1}, c) E ({q0}, c)UE ({q1}, c)
U{q2}
{q2}
D ({q0 , q1}, c) ECLOSE(q2 )
D ({q0 , q1}, c) {q2}
D ({q0 , q2 ,}, d) :
E ({q0 , q1}, d) E ({q0}, d)UE ({q1}, d)
D ({q1}, a) :
E ({q1}, a) {q1}
D ({q1}, a) ECLOSE(q1 )
D ({q1}, a) {q1}
D ({q1}, b) :
E ({q1}, b) {q4}
D ({q1}, b) ECLOSE(q4 )
D ({q1}, b) {q4,q5}
D ({q1}, c) :
E ({q1}, c) {q2}
D ({q1}, c) ECLOSE(q2 )
D ({q1}, c) {q2}
D ({q1}, d) :
E ({q1}, d)
D ({q1}, d) ECLOSE ()
D ({q1}, e) :
E ({q1}, e)
D ({q1}, e) ECLOSE ()
{q1}U
{q4}
D ({q4 , q5}, b) :
E ({q4 , q5}, b) E ({q4}, b)UE ({q5}, b)
D ({q4 , q5 }, b) ECLOSE ()
D ({q4 , q5}, c) :
E ({q4 , q5}, c) E ({q4}, c)UE ({q5}, c) {q2 }U
{q2}
D ({q4 , q5}, c) ECLOSE(q2 )
D ({q4 , q5}, c) {q2}
D ({q4 , q5}, d) :
E ({q4 , q5}, d) E ({q4}, d)UE ({q5}, d)
D ({q4 , q5 }, d) ECLOSE ()
D ({q4 , q5}, e) :
E ({q4 , q5}, e) E ({q4}, e)UE ({q5}, e)
D ({q4 , q5 }, d) ECLOSE ()
Successors of {q2} over ∑ = {a, b, c, d, e}:-
D ({q2}, a) :
E ({q2 }, a)
D ({q2}, c) :
D ({q2}, c)
D ({q2}, d) ECLOSE( q2 )
D ({q2}, d) {q2}
D ({q2}, e) :
E ({q2}, e) {q3}
D ({q2}, e) ECLOSE( q3 )
D ({q2}, e) {q3}
D ({q3,q5}, a) :
D ({q3,q5}, d) : V
Transition Table:-
∑
a b c d e
QD
{q0,q1} {q1} {q4,q5} {q2}
{q1} {q1} {q4,q5} {q2}
{q4,q5} {q4,q5} {q2}
{q2} {q2} {q3,q5}
*{q3,q5} {q3,q5}
a
{q0 , q1} {q1}
b
b c e
c
{q4, q5} {q2 , q3} {q3, q5}
a
d
1.68 Theory of Computation
*r
Solution:-
a) – closure of states:-
State - Closure
p {p,q,r}
q {q}
r {r}
b) Є NFA → DFA:-
Start state of DFA, qD
ECLOSE (P) = {p, q, r}
D ({p, q, r}, b) :
E ({p, q, r}, b) E ({p}, b)UE ({q}, b)UE ({r}, b)
{q} U {r} U
{q, r}
Automata Fundamentals 1.69
D ({p, q, r}, c) :
D ({q, r}, b) :
E ({q, r}, b) E ({q}, b)UE ({r}, b)
{r} U
{r}
D ({q, r}, b) ECLOSE(r)
D ({q, r}, b) {r}
D ({q, r}, c) :
E ({q, r}, c) E ({q}, c)UE ({r}, c)
{p, q} U
{p, q}
1.70 Theory of Computation
Transition diagram:-
b
{p,q,r} {q,r}
a,c
{r}