Theory of Computation Unit-1 - Notes
Theory of Computation Unit-1 - Notes
Prepared By,
Dr.P.Vijayalakshmi, Associate Professor
Mrs.R.Kamali, Assistant Professor
Mrs.K.Hemalatha, Assistant Professor
Department of Computer Science and Engineering
Knowledge Institute of Technology
Kakapalayam, Salem
1.1 Need for automata theory
Automata is the kind of machine which takes some string as input and this input
goes through a finite number of states and may enter in the final state.
Example Switch
Push
1. Compiler Design
2. Robotics
3. Artificial Intelligence
4. Knowledge Engineering
1. Symbol
2. Alphabet
3. String
4. Language
Symbol
→ Symbol is a character
Examples
Digits : 0, 1, 2, ................................. 9
Alphabet
(Summation)
Examples
Power of an is the set of all strings of certain length formed form the by
using Exponential notation.
1. Kleen Closure
Example
Sol :
* = 0 U 1 U 2 U 3...............
String
* It is denoted by / W /
Example
/W/ = 5
Empty string
It is denoted by e
Operations on string
1. Concatenation
2. Transpose
3. Palindrome
1. Concatenation of String
In this operation two stings are combined together to form a single string
Example : 1
1. If X abc, Y = degs
Then XY = abcdegs
YX = degsabc
Example 2
If X = {Block }, y = { Red}
Example
W = 1011001
WR = 1001101
3. Palindrome of string
Language
(Or)
It is denoted by L
Operation of Languages
Formal proof is one in which step by step procedure is used to solve the
problem
1. Deductive proof
2. Inductive Proof
1. Deductive Proof
“If H then C “
Where H → Hypothesis
C → Conclusion
Example
Sol
Here, H is x 4 → Hypothesis
C is 2 x x 2 → Conclusion
[ If x = 2 ; 22 22 = 4 4 Condition True
x = 3 ; 23 32 = 8 9 False
x = 4 ; 24 42 = 16 16 True
x = 6 ; 26 62 = 64 36 True
→ In the Same way the C → 2x x2 is true for certain values of x and false for
some other values.
→ If C is false for x = 3
→ So the terms 2X x2
Proof
(i e) (a2 + b2 + c2 + d2) → x2
Example 2
n
Prove 12 + 22 + 32 + ........... n2 = i2 = n (n+1) (2n+1)
Wing
i=i 6
Mathematical induction
AU: May – 07, 16, Mark 6, May – 14, Mark -8
Solution
1. Basis
Let n = O
L.H.S. =O
R.H.S= O
R.H.S = L.H.S
Let n = 1
L.H.S = 12 = 1
1(1+1)(2+1)
R.H.S= =6 = 1
6 6
L.H.S = R.H.S
Hence Proved
Example 1
n
Prove by Induction on n that i = n (n+1)
i=o 2
Prove 1 + 2 + 3+ .................. + n = n (n+1) (AU: May – 12 Mark 6)
2
Sol
1. Bans
Let n = O
L.H.S = O
R.H.S. = 0 (0 + 1) = 0
2
L.H.S. = R.H.S
Let n = 1
L.H.S = 1
R.H.S = 1 (1+1) = 2 = 1
2 2
L.H.S = R.H.S
2. Induction Hypothesis
Let, n = k
1 + 2 + 3 + ............................ + K = K (K + 1) → 2
3. Inductive Step
Now we assume that equations is true for n = k. And we will then check if it is
also true for n = k + 1 or not.
n=K+1
L.H.S = 1 + 2 + 3 +.....................+ K + K + 1
equ 1
K (K+1)(K+2)
= 2
K (K+1)(K+2)
L.H.S = → 2
2
K (K+1)
R.H.S=
2
n = K+1
K (K+1)
= 2
(K+1)
K (K+1)+ 2 (K+1) K (K+1)(K+2)
= R.H.S = → 3
2 2
2 = 3
L.H.S = R.H.S
Hence Proved
Example : 3
R.H.S = 1 (1+1) 2 = 1
4
L.H.S = R.H.S
2. Induction Hypothesis
Let n = K
Then
1
→
13 + 23 + ...................... + K3 = K2 (K+1) 2
4
3. Inductive Step
Now, we will try to prove it for n = K + 1
L.H.S
13 + 23 + ................. + K3 + (K + 1) = K2 (K + 1) 2 + K + 1) 3
equ 1 4
K2 (K+1) 2 + (K + 1) 3 = K2 (K + 1) 2 + (K + 1) 3
4 4
(K + 1) 2 [K2 + 4 (K + 1)] = (K + 1) 2 [K2 + 4 (K+1) ]
4 4
Finite Control
S+
n
Final State
S+
Example
q0 q1
Start
Transition Table
The transition table is the tabular representation of the transition of FA.
Whose rows denoted the states and column denote the input symbols.
Transition table
State / Input a b
→qo q1 -
* q1 qo q1
Transition Function’’
Transition is the process of moving from one state to another state on reading
an input symbol.
Normally the DFA defines a language as the; ET of all strings that result in a
sequence of state transitions from start state to end state.
(q, a) = q1
This means that the state cannot be changed = o another state without reading
an input symbol.
For all strings ‘w’ and an input symbol ‘a’
(q, aw) = ((q, a) = w)
Extended Transition Function ‘’
The transition function is extended to ‘’
Extended transition function ‘’ that operates on strings and states.
It describes what happens when we start in any state and follow any sequence
of inputs.
1 (q.w1 = 1 (q, xy) = (1 (q, x), y)
‘W’ is the string of the form ‘xy4’
5. Language of FA
The language of FA m= (Q,,,qo, F) is denoted by L(m) and it is defined as.
L (m) = { (W/’ (q0, W) is in F)}
That is the language of M is the set of strings ‘W’ that starts with state qo to
reach one of the accepting state.
Types of Automata
DFA, if there is only one path for a specific input from current state to next state.
A = (Q,,,qo, F)
1. Design DFA to L1 = set of all the strings that start with ‘O’
Solution
Transition Diagram
q0 q1
q2
0,1
Dead state
Transition Table
0 1
State / Input
→q0 q1 q2
* q1 q1 q1
q2 q2 q2
Transition Function
Input 001
1 (q0, 001) = 1 ((qo, o), 01)
= 1 (q, 01)
= 1 ((q, 0), 1)
= 1 (q, 1)
= 1 ((q1, 1))
= (q1,)
Construct DFA that accepts input strings of O’S and is that end with 11.
Solution
L = {011, 11, 1011, 0011, 01011, ........................ }
Transition Diagram
0 0 1
Start 1 1
q0 q1 q2
0
Transition Table
0 1
State / Input
→q0 q0 q1
* q1 q0 q2
* q2 q0 q2
Transition Function
Input 011
1 (q0, 011) = 1 ( (q0, 0), 11)
= 1 (q0, 11)
= 1 ((q0, 1), 1)
= 1 (q1, 1)
= 1 ( (q1, 1) )
= (q2, t) = q2 / Final State
3. Design FA which checks whether the given unary number is divisible by 3
Solution
The unary number is made up of ones
L = {111, 111 111, 111111111, ............................ }
Transition Diagram
1 1 1
q0 q1 q2 q3
Start
1
Transition Table
0 1
State / Input
→q0 q0 q1
* q1 q0 q2
Transition Function Input: 111
* q2 q0 q2
(q0, 111) = 1 ( (q0, 1), 11)
= 1 (q1, 11)
= 1 ((q1, 1), 1)
= 1 (q2, 1)
= 1 ( (q2, 1) )
= q3 Final State
String Accepted
Construct DFA for set of all strings with three consecutive O’S at its end
Solution
L = {1000, 0001000, 100011, 0001, ............................. 3)
Transition Diagram
1 0 0 0 0
q0 q1 q2 q3
Start 1 1
5). Construct DFA for all the set of strings with {0, 1} that has even number of
O’S and I’ S
AU: Dec – 10, Magic
Solution
Transition Diagram
1
q0
1 q1
Start 1
0 0 0 0
q2 1 q3
Transition Table
0 1
State / Input
→q0 q2 q1
* q1 q3 q0
* q2 q0 q3
q3 q1 q3
1) Construct a DFA that accepts all the strings on {0, 1} except those Containing
the substring 101
1 0
q3
1
Change Non – Final state into Final State
Final state into non – Final State
0 0 1,0
q0
1 q2 0 q3
1
q4
Start
1 0
q3
1
7. Construct a DFA accepting all string W over {0, 1} such that number of 1’ S in W
is 3 mod 4
Solution
0 0 0 0
q0
1 q2 1 q3
1
q4
1
1
8. Give DFA the following language over the alphabet
1. Number of 1’S is a multiple of 3
2. Number of 1’ S is not a multiple of 3
Solution
1). L = {111, 111111, 111111111 …}
1 1 1
q0 q1 q2 q3
Start
1 1
q4
9. Given = {a, b} Construct a DFA which recognize the language L = {bm abn
:m, n>0}
Solution
L = b+ ab+
b b
b a b
q0 q1 q2 q3
Start
10. Construct DFA for set of all strings {o, 1} with 011 as substring
Solution
L = {1 011, 011, 100110, ................. }
1 0 1/0
0 1 1
q0 q1 q2 q3
0
1. Construct DFA for the set of all strings with equal number of O’S & 1’ S
starting with “0”
L = {01 0101, 0011,...................... }
1 0 0
q0 q1
1
q0
b q1
3. Construct DFA for set of all string S {0, 1} with strings ending with 01
Solution
L = {001, 101, 1101, ..................... }
1 0
0 1
Start q0 q1 q2
0
2. Non – Deterministic Finite Automata (NFA)
NFA allows zero one or more transitions from a state on the same input symbol
The NFA can be formally defined as a collection of 5 – tuples
A = (a,,,qo, F)
1. The finite set of states Q
2. The finite set of input symbol
3. The transition function (QX→ 2Q)
4. The start state qo (q0 Q)
5. A set of final states F (F C Q)
1. Construct a NFA for a language L which accepts all the strings in which the third
symbol from right end is always a over = {a, b}
Solution
L = {a a b a, b a a a, a a b b, .................. }
a/b
a a,b a,b
q0 q1 q2 q3
Transition Table
a b
State / Input
q0 {q0, q1} {q0}
q1 {q2} {q2}
q2 {q3} {q3}
q3 - -
Transition function
Input baaa
(q0, baaa) = 1 ((q0, b) aaa)
= 1 (q0, aaa)
= 1 ((q0, a) aa)
= 1 ((q0, q1) aa)
= 1 ((q0, q) U (q1, a), a)
= 1 (([q0, q1} U {q2}), a)
= 1 ({q0, q1, q2}), a)
= 1 ( (q0, q1, q2), a)
= 1 ((q0, a) U S (q1, a) U S (q2, a))
= 1 ({q0, q, } U { q2 } U {q3})
= 1 q0, q1, q2, q3)
= 1 q0, baaa) F
= q0 q1, q2, q3) {q3}
String Accepted
2. Construct NFA for FA over {a, b} containing substring aabb
AU : May – 09, Mark – 4→
Solution
L = {aaabbb, baabbb,............................. }
Transition Diagram
a,b a,b
a b b b
q0 q1 q2 q3 q4
Transition Table
a b
State / Input
q0 {q0, q1} {q0}
q1 {q2} -
q2 - {q3}
q3 - {q4}
q4 {q4} {q4}
Transition Function
Input aaabb
(q0, baaa) = 1 ((q0, b) aaa)
= 1 (q0, q1), aaa)
= 1 ((q0, q1), a), abb)
= 1 ((q0, q, q2), abb)
= 1 ((q0, q1, q2), a) bb)
= 1 ( q0, a) US (q1, a) US (q2, a), bb)
= 1 ({qo, q1, q2,} bb)
= 1 (((q0, q1, q2) b) b)
= 1 ((q0, b) U S (q1, b) U (a, b), b)
= ({q0, q3}, b)
= 1 ((q0, q3), b)
= 1 ( ({q0, q4}, }
= {q0, q4}
= 1 (q0 aaabb) F
= {q0, q4} {q4}
= {q4} Final state
String Accepted
3. Construct NFA that end with string II for set of all strings {0, 1}
Solution
L = {0 11, 1011 111, 0011, .................... }
0/1 1
q0 1 q1 1 q2
E q1 E
q0 q2
Start
Finition of - closure of q0 ( - closure (q0)) denotes set of all states P such that there
is a with (or) transition from q0 to P on - transition.
4). Construct NFA for set of all strings {0, 1} that end with three consecutive I’ S at
its end
Solution
L = {1111, 0111, 1011,. .............. }
0/1 1
1 1 1
q0 q1 q2 q3
Start
0 0
5. Construct NFA with 011 as substring solution
L = {011, 10110, 10111, .................. }
1/0 1/0
0 1 1
q0 q1 q2 q3
Transition Table
a b c
State / Input
-
q0 q0 q1
q1 q1 q2
q2 q2
Closure
- Closure (q0) – {q0, q1, q2}
Self state + E – reachable state
- Closure (q1)- {q1, q2}
Self state (q1) + q2 is a state obtained from q1 with input
- Closure (q2)- {q2}
Transition Function
Input = aabbcc
(q0, aabbcc = Ⱶ (q0, aabbcc)
= Ⱶ (q0, abbcc)
= Ⱶ (q0, bbcc)
= Ⱶ (q0, bcc)
= Ⱶ (q0, cc)
= Ⱶ (q1, c)
= Ⱶ (q2, E)
= q2 Final State
String Accepted
2. Consider the following NFA - Closure of all input symbols for each state and
check whether the string “abb” is accepted.
a b c
q0 q1 q2
a b
Solution
- Closure of all the state
- Closure (q0) = {q0, q1, q2}
- Closure (q1) = {q1, q2}
- Closure (q2) = {q2}
Transition Table
a b c
State / Input
q0 {q0, q1} {q}
q1 {q1, q2} {q2}
q2 {q2}
Transition Function
Input string = abb
( q0, ) = closure (q0) = {q0, q1, q2}
(q0, a) = closure ( ( (q0, ), a))
= closure ( (q0, q1, q2), a)
= closure ( (q0, a) U (q`, a) U (q2, a) )
= Closure (q0, q1)
= closure (q0) U closure (q1)
q1 1 q2 q3 1 q4
q0
Construct NFA with all as substring for H1 the set of all string {0, 1}
0,1 0,1
q1 0 q2 q3 1 q4 1
q0 q5 q6
a, b a, b
q1 a q2 q3 b
q0 q4
q1
q0 q2
Solution
Transition table for NFA
0 1 2
State / Input
→ q0 {q0} {q}
q1 {q1} {q2}
q2 {q2}
Step 1
- Closure (q0) = { q0, q1, q2}
- Closure (q1) = { q1, q2}
- Closure (q2) = {q2}
Step 2: Processin g state q0 :
(q0, ) = Closure (q0) = { q0, q1, q2}
(q0, 0) = Closure ( ((q0, ), 0)
= Closure ( (q0, q1, q2), 0)
= Closure ((q0, 0) U (q1, 0) U (q2, 0))
= Closure (q0)
(q2, 2) = q2
Transition table for DFA: without:
0 1 2
State / Input
{q0, {q1, q2} {q2}
→ q0
q1,q2}
{q2}
q1 {q1, q2}
q2 {q2}
0,1 q1 1,2
q0 q2
0/1
0 1
q0 q1 q2
Solution
= (q0, q1) = B
(A, 1) = (q0, 1)
(q0) = A
Step 2:
= (q0, 0) U (q1, 0)
= (q0, q1) = B
= (q0, 1) U (q1, 1)
= (q0, q2) = C
Step 3:
= (q0, 0) U (q2, 0)
= (q0, q1) = B
= (q0, 1) U (q2, 1)
= (q0) = A
0 1
State / Input
→ q0 [q0, q1]
[q0]
1 0 1
[q0,q2]
0 1
→P {p, q} {p}
q {r} {r}
r {r}
{s}
*s {s}
Solution
Transition diagram for NFA
0, 1 0,1
0 0 0
p q r s
1
= (q1, 0) U (q, 0)
= (p1 q1 r) → C
= (p1) U (q, 1)
= (p, r) → D
Step 3:
= (p, q, r, s) → E
(C 1) = ((p1 q1 r), 1)
= (p r) → D
Step 4:
= (p, 0) U (r, 0)
= (p, q, s) → F
= (p, 1) U (r, 1)
= [P] → A
Step 5:
= (p, q, r, s) → E
(E 1) = ((p, q, r, s), 1)
= [p, r, s] → G
Step 6:
= (p, q, r, s) → E
(F 1) = ((p, q, s), 1)
= [p, r, s] → G
Step 7:
(G 1) = ((p, r, s), 1)
= [p, s] → H
Step 8:
= (p, 0) U (s, 0)
= (p, q, s) → F
(H 1) = ((p, s), 1)
= (p, 1) U (s, 1)
= [p, s] → H
State / Inputs 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, s] [p, s]
* [ p, r, s] [p] [p, s]
Transition Diagram for DFA :
1 1
[ p] 0 [p, q] 0 [p, q, r] 1 [p, r]
0 0
[p, q, r, s] 0 [p, q, s]
1 0 0
[p, q, s] 0 0
1 [p, q]
M = [ {q0, q1}, {a, b}, , q0, {q1}) with the state table diagram for given
below
a b
q0 [q0, q1] [q1]
q1 [q0, q1]
Solution
State / Inputs a b
→ [q0] {q0, q1} {q1}
* q1 {q0, q1}
Here starting state is [q0]
Step 1:
(A, a) = (q0, a)
= [q0, q1] → B
(A, b) = (q0, b)
= [q] → C
Step 2
= (q0, a) U (q1, a)
= {q0, q1} → B
= (q0, b) U (q1, b)
= (q0, 4) → B
Step 3
=
(C, b) = (q1, b)
= (q0, q1) → B
a b
→ [q0] {q0, q1} {q1}
[q0, q1) [q0, q1] {q0, q1}
[q1] [q0 q1]
a [q0,q1 a, b
q0 ]
b b
[q]
4. Construct NFA that accepts the set of all strings {a, b} ending with “aba” as and
contract
DFA
Solution
Transition diagram for NFA
a,b
a b q2 a
q0 q1 q3
Transition table for NFA:
State / Input a b
→ q0 {q0, q1} {q0}
q1 {q2}
q2 {q3}
* q3
State / Input a b
→ [q0] [q0, q1] [q0]
[q0, q1] [q0, q1] [q0, q2]
[q0, q2] [q0, q1, q3] [q2]
* [q0, q1, q3] [q0, q1] [q0, q2]
b b a
a
b
Construct DFA for the following NFA
0 1
q0 0 q1 1 q2
Solution
Transition table for NFA
State / Input 0 1
→ q0 {q0, q1}
q1 {q2}
q2 {q2}
0 1
q0 q1
Solution
Transition Table for NFAE
State / Input 0 1
→ q0 {q0} {q1}
q1 {q2}
Step 1
- Closure {q0} - {q0, q1}
- Closure {q1}- {q1}
Step 2
(q0, ) = - Closure (q0) = {q0, q1}
(q0, 0) = - Closure ( ( (q0, ) ), 0)
= - Closure ((q0, 0) U (q1, 0))
= - Closure {q0, U }
= - Closure {q0}
(q0, 0) = {q0, q1}
(q0, 1) = - Closure ( ( (q0, ) ), 1)
= - Closure ((q0, q1) 1)
= - Closure {q0, 1) U (q1, 1))
= - Closure ( {} U {q1})
= - Closure (q1)
(q0, 1) = {q1}
Step 3 : Processing state q1
(q1, ) = - Closure (q1) = {q1}
(q1, 0) = - Closure ( ((q0, )), 0)
= - Closure ( (q1, 0))
= - Closure ()
(q1, 0) =
(q1, 1) = - Closure ( ( (q1, ), 1))
= - Closure ( (q1, 1))
= - Closure (q1)
(q1, 1) = {q1}
Transition Table for NFA
State / Input 0 1
→ q0 {q0, q1} {q1}
* q1 {q1}
Transition Diagram
0 1
q0 0, 1 q1
Note
\ State {q0} and {q1} becomes final state because - Closure of q0, q0 contains
q2
Convert the following NFA with to NFA without
b
a
q0 q1 q2
State / Input a b E
→ q0 {q1}
* q2 {q2}
Step 1
- Closure (q0) - {q0}
- Closure (q1) - {q1, q 2}
- Closure (q2) - {q2}
Transition Diagram
a b b
q0 q1 q2
a
Note : State q1, q2 becomes the final state because - Closure, q1 and q2 contains the
final state of q2.
4. Convert the following NFA with to NFA without
5
4
8 9
0 → 1 → 2 → 3
6 → 7
Solution
Transition Table for NFA –
State / Input a b E
→0 {1}
1 {2}
2 {3, 9}
3 {4, 6}
4 {5}
5 {8}
6 {7}
{8}
8 {3 9}
*9
Step 1
- Closure (0) = {0}
- Closure (1) = {1}
- Closure (2) = {2, 3, 4, 6, 9}
- Closure (3) = {3, 4, 6}
- Closure (4) = {4}
- Closure (5) = {3, 4, 5, 6, 8, 9}
- Closure (6) = {6}
- Closure (7) = {3, 4, 6, 7, 8, 9}
- Closure (8) = { 3, 4, 6, 8, 9}
- Closure (9) = {9}
State / Input a b
→0 {1}
1 {2, 3, 4, 6, 9}
*2 {3, 4, 7, 6, 8, 9}
3 {3, 4, 5, 6, 8, 9} {3, 4, 7, 6, 8, 9}
4 {3, 4, 5, 6, 8, 9}
*5 {3, 4,5, 6, 8, 9} {3, 4, 7, 6, 8, 9}
6 {3, 4, 6,7, 8, 9}
*7 {3, 4, 4, 5, 6, 8, {3, 4, 6, 7, 8, 9}
9}
*8 {3, 4, 5, 6, 8, 9} {3, 4, 6, 7, 8, 9}
*9
a b a,b
5
→ 0 1 2 3 4
b
8
a,b
a, b 6
a, b
9
b a
q0 q1 q2
a
b
Solution
Transition Table
State / Input a b
→ q0 {q0} {q1}
q1 {q3} {q2}
* q2 {q1} {q0}
Step 1
- Closure {q0} - {q0, q1, q2}
Step 2
- Closure {q0} – {q0, q1, q2}
= - Closure (q0)
Processing state B
Transition Diagram
b a a
q0, q1, q2 q1, q2
b
Consider following NFA with
State / Input a b c E
→p {p} { q} {r}
q {q} {r} {p}
• r {r} {p} {q}
ab a
p q
c c b e
Step 1
- Closure (p) = { p}
- Closure (q) = {p, q}
- Closure (r) = {q, r}
Step 2
Processing state A
= - Closure (p)
(A, a) = {p}
= - Closure (q)
(A, b) = {q, p}
= - Closure (r)
(A, c) = {q, r} → C
Processing state B
= - Closure (p, q)
(B, a) = {p, q}
= - Closure (q, r)
(B, b) = {p, q, r} →D
= - Closure (r,)
= - Closure (r)
(B, c) = {q, r}
Processing state C
= - Closure (q u r)
(C, a) = {p,q, r}
= - Closure (r)
(C, b) = {q, r}
= - Closure (, u p)
= - Closure (p)
(C, c) = {P}
Processing state D
= - Closure (p u q u r)
(D, a) = {p, q, r}
= - Closure (q u r u )
(D, b) = {p, q, r}
= - Closure (r u u p)
Transition Table
State / Input a b c
→{p} {p} { p, q} {q, r}
{p, q} {p, q} {p, q, r} {q, r}
* {q, r} {p, q, {p, q, r} {p, q, r}
r}
Transition Diagram
a
p
c b
q, r
c
b c
a b abc
p, q p, q, r
Consider the following NFA - for an identifier consider the each state and find it’s
equivalent DFA
5 6
Letter
7 10
1 2 3 4
8 9
Digit 1 AU: Dec -15, Mark 10
Solution
Transition Table
Step 1
- Closure (1) = {1}
- Closure (2) = {2, 3, 4, 5, 8, 10}
- Closure (3) = {3, 4, 5, 8, 10}
- Closure (4) = {4, 5, 8}
- Closure (5) = {5}
- Closure (6) = {6, 7, 10, 4,5, 8}
- Closure (7) = {7, 10}
- Closure (8) = { 8}
- Closure (9) = {9, 7, 9, 5, 8, 10}
- Closure (10) = {10}
Step 2
= - Closure (2)
=
(A, digit) =
Processing state B
= - Closure (6)
= - Closure (9)
= {9, 7, 4, 5, 8, 10}
Processing state C
= - Closure (6)
= - Closure (9)
(C, digit) = {4, 5, 7, 8, 9, 10}
Processing state D
= - Closure (6)
= - Closure (9)
Transition Diagram
Letter
→ A B
digit Letter
digit Letter
D C
digit letter
The two states C and D are equivalent. Similarly state B and C are equivalent
B = C = D
Letter letter/digit
→ A B
4). Convert the following NFA - to NFA and then convert the resultant NFA to
DFA
1 1 0 1
A B C
E E
Solution
Step 1
Processing State A
= - Closure ()
(A, 0) =
(A, 1) = {A, B, C, D}
Processing State B
= - Closure ()
(B, 0) =
= - Closure (D, C)
(B, 1) = {D, C}
Processing State C
= - Closure ()
(C, 0) =
= - Closure (C)
(C, 1) = {C}
Processing State D
= - Closure (B)
(D, 0) = {B, C}
= - Closure ()
(D, 1) = {}
Transition Table
→→A 1 B
1 1 1 1
D C
0 1
Initial state A
(A, 0) =
(A, 1) = {a, 1}
(A, 1) = {A, B, C, D} → P
= ( U U U {B, C})
(P, 0) = {B, C} → Q
(P, 1) = {A, B, C, D}
(Q, 0) = (Q, 0)
= ((B, C), 0)
(Q, 0) =
(Q, 1) = {C, D} → R
(R, 0) = (R, 0)
= ((C, D), 0)
(R, 0) = {B, C}
(R, 1) = (R, 1)
= ((C, D), 1)
(R, 1) = {C,}
(R, 1) = {C} → S
(S, 0) = (C, 0)
(C, 0) =
(S, 1) = (C, 1)
(S, 1) = C
Transition Table
Transition Diagram
1
→ A 1 P
0 1
Q 1 R 1 S
In this method we try to remove all the - transitions from given NFA
1. Find out all the transitions from each state from Q. That will be called as
- Closure {q}where q; Q
2. Then ’ transitions can be obtained the ’ transitions means an - closure
on moves.
3. Step 2 is repeated for each input symbol and each state of given NFA
4. Using the resultant states the transition table for equivalent NFA without
can be built.
Theorem:
Proof
We will apply the method of induction with input x the X will not be
because.
1 (q0,) = {q0}
Basis
1 (q0, a) = ” (q0, a)
Induction
By inductive hypothesis
1 (q0, w) = ” (q0, w) = P
But
As P = ” (q0, w)
q in P
Thus by definition”
Theorem
(Or)
Proof
The Q’ = 2Q
F’ be the set of all the final states in M
The elements in Q’ will be denoted by [q1, q2, q3 ................... q1] and elements in Q are
denoted by {q0, q1, q2, ........................}The [q1, q2, ...................... q1] will be assumed
as one state in Q’ if in the NFA q0 is initial state it is denoted in DFA as q0’ = [q0]
We defined
’ (q1, q2, q3, ........................qi], a) = [ P1, P2, P3,................. P3] if and only if
This means that whenever in NFA at the current states {q1, q2, q3..............................qi}
if we get input a and it goes to the next states {P1, P2, .........Pj} then while
constructing DFA for in the current state is assumed to be [P1, P2 ......................Pj]
On applying function on each of the states q1, q2, q3................qi the new
states may be any of the states from [P1, P2, ................. Pj]
The theorem can be proved with the induction method by assuming length of
input string X
Basis
If and only if
Induction
If we assume that the hypothesis is trust for the input string of length in or less
than m.
If and only if
By definition of ’
If and only if
Thus
If and only if
Step 3
Consider M – (Q,,, qo, F) is a NFA with we have to convert this NFA with
to equivalent DFA denoted by
Then obtain
Step 2
We will obtain transitions on [P1, P2, P3 .......................... Pn] for each input
n
= U - Closure d (P;, a)
i=1
Where a is input e
Step 3
The states obtained [P1, P2, P3……………….Pn] QD. The states containing
final state in Pi is a find state in DFA
Let us prove P U Q = Q U P
Proving LHS
Proving RHS
Proof by contradiction
3. Counter Examples
Example 1
Condition Conclusion
Example 2
MINIMIZATION OF AUTOMATA
DFA minimization stands for converting a given DFA to its equivalent DFA
with minimum number of states. DFA minimization is also called a optimization of
DFA and uses positioning algorithm.
Automation of DFA
All thase states which can never be reached from the initial state are called as
inaccessible states.
PROBLEMS
Final the equivalence and Minimization of finite automata for the following FA
Start 0 1 1 0
→ A B C D
2 1 0
E G H
→ F 1
Solution 0
Accepting state = C
We do not compare
(A, C) (B, C)
(G, C) (H, C)
B
X X
C
X
D
X
E
X √
F
X
G
X
H
A B C D E F G
States / Input O 1
A B F
B G C
*C A C
D C G
E H F
F C G
G G E
H G C
(H, O) = G (H, 1) = C
II Pair(D, F)
(A, O) = B (A, 1) = F
(B, O) = G (B, 1) = C F, N, F
IV Pair (A, D)
(D, O) = C (P, 1) = G
F, N, F N, F
Pair (A, E)
V Pair (A, E)
(E, O) = C (E, 1) = G
E N, F
VI Pair (A, F)
(F, O) = C (F, 1) = G
F, N, F N, F
VII Pair (A, D)
(G, O) = G (G, 1) = E
F, N, F N, F
III Pair (A, H)
(H, O) = C (H, 1) = C
N, F F + N, F
B
X X
C
X X
D
√ X
E
X X √
F
X X
G
X X
H
A B C D E F G
I Pair (B, D)
(D, O) = C (D, 1) = G
II Pair(B, E)
(E, O) = H (E, 1) = F
(F, O) = C (F, 1) = G
IV Pair (B, G)
(G, O) = G (G, 1) = E
VI Pair (D, E)
(E, O) = H (E, 1) = F
(G, O) = G (G, 1) = E
(H, O) = G (H, 1) = C
VI Pair (E, G)
(G, O) = G (G, 1) = E
(H, O) = G (H, 1) = C
I Pair (F, G)
(G, O) = G (G, 1) = E
I Pair (F, H)
(G, O) = G (H, 1) = C
Pair (G, H)
(H, O) = G (H, 1) = C
States / Input O 1
A B D
B G C
*C A C
D C G
B X
C X X
D X X X
E √ X X √
F X X X √ X
G X X X X X X
H X √ X X X X X
A B C D E F G
1 0
A=E G D=F
0 0 0 1 0
B =H C
1
1
2. Minimize the AU: Dec – 18
b
4
a a
2
b b
5
a a
1
6
b a a b
3 b
b
7
Solution
Accepting state = 1, 2, 7
3 X X
4 X X
5 √ X
6 X X
7 √ √ X X X X
1 2 3 4 5 6
States / Input a b
2 3
*2 4 5
3 6 7
4 5 4
5 7 5
6 2 7
*7 7 4
Steps
i) Pair (3, 4)
(4, a) = 5 (4, b) = 4
N, F F, N, F
ii) Pair (3, 5)
(5, a) = 7 (5, b) = 5
F, N, F F, N, F
(6, a) = 2 (6, b) = 7
F, N, F F
(5, a) = 7 (5, b) = 5
F, N, F N, F
(6, a) = 2 (6, b) = 7
F, N, F F, N, F
(6, a) = 2 (6, b) = 7
F N, F
The only equivalent pair (1, 2), (1, 7), (2, 7) we eliminate state and 7 by
replacing them by 1.
Minimized Transition
States / Input a b
→ 1 3
3 6 1
4 5 4
5 1 5
6 1 1
a b a
3 6
1 b
a,b
5 b
4
a
b
→A B E
B C F
*C D H
D E H
E F I
*F G B
G H B
H I C
*I A E
Accepting state = C, F, I
Non Accepting state = A, B, D, E, G, H
Equivalent state = { (C, F) (C, I) (F, I)}
We do not compare the states = (A, C)(B, C)(D, C)(E, C) (G, E)(H, C)
(A, F)(B, F) (D, F)(E, F) (G, F)(H, F)
(A, I) (B, I) (D, I) (E, I) (G, I) (H, I)
B X
C X X
D X
E X
F X X √ X X
G X X
H X X X
I X X √ X X √ X X
A B C D E F G H
Steps
i) Pair(G, H)
(H, O) = I (H, 1) = C
F, N, F F, N, F
(G, O) = H (G, 1) = B
F, N, F F, N, F
(H, O) = I (H, 1) = C
v) Pair (D, E)
(E, O) = F (E, 1) = I
F, N, F F, N, F
v) Pair (D, G)
(G, O) = H (G, 1) = B
F, N, F F, N, F
i) Pair(D, H)
(H, O) = I (H, 1) = C
F, N, F F, N, F
(D, O) = E (D, 1) = H
F, N, F F, N, F
(E, O) = F (E, 1) = I
(G, O) = H (G, 1) = B
Final + NF F + N.F
(H, O) = I (H, 1) = C
F+F N+F
i) Pair(A, B)
(B, O) = C (B, 1) = F
NF + F FF + F
(D, O) = E (D, 1) = H
N, F + N F N, F
(A, O) = B (A, 1) = E
(E, O) = F (E, 1) = I
NF+F FN+NF
(G, O) = H (G, 1) = B
Equivalent
v) Pair (A, H)
(A, O) = H (A, 1) = E
(H, O) = I (H, 1) = C
F, N, F F, N, F
B X
C X X
D √ X X
E X √ X X
F X X √ X X
G √ X X √ X X
H X √ X X √ X
I X X √ X X √ X X
A B C D E F G H
A = G = D
B = H = E
C = I = F
State / Input 0 1
→A B B
B C C
• C A B
Minimized transition diagram for DFA
0, 1
A=G=D B=H=E
→ 1
C=I=F
0 0,1
1 0 1 0 0
A
→ 0 B C D 0 E 1
0 1
F
H G
1 0
1 0
Solution
Initial state : A
Final state : D
We do not compare the state : (A, D) (B, D)(C, D)(E,D) (F, D)(G, D)
(H, D)
D X X X
E X
F X
G X
H X
A B C D E F G
Transition Table
State / Input 0 1
→A B A
B A A
• C D B
• D D A
E D F
F G E
G F G
H G D
i) Pair(A, B)
(B, O) = A (B, 1) = C
NF NF
(A, O) = B (A, 1) = A
(C, O) = D (C, 1) = B
F, N, F NF
(A, O) = B (A, 1) = A
(E, O) = D (E, 1) = F
F, N, F NF
(A, O) = B (A, 1) = A
(F, O) = G (F, 1) = E
i) Pair(A, G)
(G, O) = F (G, 1) = G
(H, O) = G (H, 1) = D
FNF
i) Pair(B, C)
(C, O) = D (C, 1) = B
F, N. F
(E, O) = D (E, 1) = F
i) Pair(B, F)
(F, O) = D
i) Pair(B, G)
(G, O) = F (G, 1) = G
(G, O) = F
v) Pair (B, H)
(H, O) = G (H, 1) = D
F, N.F
i) Pair(C, E)
(E, O) = D (E, 1) = F
F Equivalent
(C, O) = D (C, 1) = B
(F, O) = G (F, 1) = E
F, N.F
(G, O) = F (G, 1) = G
F, N.F
(C, O) = D (C, 1) = B
(H, O) = G (H, 1) = D
i) Pair(E, F)
(E, O) = D (C, 1) = B
(F, O) = G (H, 1) = D
(E, O) = D (E, 1) = F
(F, O) = G (F, 1) = E
F.N.F
iii) Pair (E, G)
(E, O) = D (E, 1) = F
(G, O) = F (G, 1) = G
F, N.F
(E, O) = D (E, 1) = F
(G, O) = F (G, 1) = G
(H, O) = G (H, 1) = D
F, N.F
N.F (G, O) = F
(F, O) = G (F, 1) = E
(H, O) = G (H, 1) = D
F, N.F
(H, O) = G (H, 1) = D
F, N.F
B X
C X X
D X X X
E X X √ X
F X √ X X X
G √ X X X X X
H X X X X X X X
A B C D E F G
State
0 1
/ Input
A B A A=G
B A C B=F
C=E
C D B
*D D A
H A D
1 0 1
A=G B=F C, E
0 1
0 1 1 0
H D
1 0