Unit 1 Toc
Unit 1 Toc
Theory of Computation:
1. The theory of computation describes the basic ideas and models underlying computation.
2. Computation is the process of execution of an algorithm such that it involves taking
inputs and performing required operation on it to produce an output.
3. So computation is a sequence of steps that can be performed by the computer.
4. The applications of Theory of computation are compiler design, Robotics, Artificial
Intelligence etc.,
1. Finite automata involves states and transitions among states in response to inputs.
2. It is a useful model for many kinds of hardware and software.
1. In addition to models, it has become traditional for a course on automata theory to cover
methodologies of formal proof.
2. Under this formal proof, we have several methods.
1. Deductive proof.
2. Reduction to definition
1. A deductive proof consists of a sequence of statements whose truth leads us from some
initial statement called ‘hypothesis’ or the given statements to a ’conclusion’ statement.
Theorem 1: If x ≥ 4 then 2x ≥ x2
Proof:
Given Hypothesis, H= x ≥ 4
If x = 4 => 24 ≥ 42
=> 16 ≥ 16
If x = 5 => 25 ≥ 52
=> 32 ≥ 25
Therefore, C is true
( ) ( )
2 2
x+ 1 x+ 1
R.H.S x2 grows by the ratio , by mathematical induction, 1,4,9,25,36...(x+1)2 =
x x
( )
2
2 x+ 1
x =
x
( )
2
4 +1
If x ≥ 4,
4
()
2
5
=
4
= (1.25)2
= 1.5625
( )
2
x+ 1
cannot be greater than 1.5625
x
Conclusion: Since 1.5625 < 2, each time x increase above 4, the L.H.S 2x grows more than the
R.H.S. x2 .
Theorem 2:
Statement Justification
1. x = a2+b2+c2+d2 Given
2. a≥1, b≥1,c≥1,d≥1 Given
3. a2≥1, b2≥1,c2≥1,d2≥1 (2) and properties of arithmetic
4. x ≥ 4 (1),(3), and properties of arithmetic
5. 2x ≥ x2 (4) andTheorem 2.
Hence it is justified
1. Reduction to definition states that “If you are not sure how to start a proof convert all
terms in the hypothesis to their definition”
Theorem 1: Let S be a finite subset of some infinite set U. Let T be the complement of S with
respect to U. Then T is infinite.
Consider,
U = { 1,2,3,4,…….}
S = {2,3,4}
S∈U
T = {1,5,6,7,…}
T is infinite
Hence it is justified
The other most common forms of statements that we need to prove are as follows:
1. The simple “if H then C” form implies: if hypothesis H is true for a given value of
parameter then conclusion C is true for the same value.
2. The other ways of “If H then C “ are
1. H implies C
2. H only if C
3. C if H
4. Whenever H holds C follows
Example :
1. x ≥ 4 implies 2x ≥ x2
2. x ≥ 4 only if 2x ≥ x2
3. 2x ≥ x2 if x ≥ 4
4. Whenever x ≥ 4 holds 2x ≥ x2 follows
2. If –And-Only-If statements:
1. The statement of the form “A if and only if B” and other forms of this statements are
“A iff B”, A is equivalent to B” , or A exactly when B”
2. This statements is actually two if –then statements: “if A then B”, and “if B then A”.
We prove “A if and only if B” by proving these two statements”
2. The only-if part: “if A then B”, which is often stated in the equivalent form “A
only if B”.
Theorem: Let x be a real number. Then x= x if and only if x is an integer.
Note:
1. x , the floor of real number x, is the greatest integer equal to or less than x.
2. x , the ceiling of real number x, is the integer equal to or greater than x.
Proof:
Only-if part:
x ≤ x --------------- 1
x ≥ x -------------- 2
We get x ≤ x
x ≥ x
By Arithmetic Inequality
x = x
If part:
Assume x is an integer, to prove x = x. By the definition of floor and ceiling, when x
is an integer, both x and x are equal to x and therefore equal to each other.
In some cases, the theorems appear not to have a hypothesis that are all comes under this
case.
Description: In this theorem, the hidden hypothesis is that, θ is an angle and therefore the
functions sine and cosine have their usual meaning for angles.
3. Proofs by contradiction.
4. Proofs by counterexample.
The sets are set of character strings, and the sets are called “languages”
Statement Justification
1. x is in R∪ ( S ∩ T) Given
2. x is in R or x is in S ∩ T (1) and definition of union
3. x is in R or x is in both S and T (2) and definition of intersection
4. x is in R∪S (3) and definition of union
5. x is in R∪T (4) and definition of union
6. x is in (R∪S) ∩ (R∪T) (4),(5) and definition of intersection
Only-if –part:
Statement Justification
1. x is in (R∪S) ∩ (R∪T) Given
2. x is in R∪S (1) and definition of intersection
3. x is in R∪T (2) and definition of intersection
4. x is in R or x is in both S and T (2),(3), and reasoning about unions
5. x is in R or x is in S ∩ T (4) and definition of intersection
6. x is in R∪ ( S ∩ T) (5) and definition of unoin
The contrapositive of the statement “if H then C” is “if not C then not H”. A statement
and its contrapositive are either both true or both false.
Example: If x ≥ 4 then 2x ≥ x2
Another way to prove a statement of the form “if H then C” is to prove the statement “H
and not C implies falsehood”.
Theorem: Let S be a finite subset of some infinite Set U. Let T be the complement of S with
respect to U. Then T is infinite.
Proof:
Given:
S∪T = U
||T|| = m
= n+m
This contradicts the given statement that there is no integer p equal to ||U||
Hence proved.
Theorems generally are statements about an infinite number of cases, perhaps values of
its parameters. A statement that just misses being a theorem are comes under this case.
Alleged Theorem: All primes are odd. (formally if integer x is a prime, then x is odd)
Disproof:
Alleged Theorem: There is no pair of integers a and b such that a mod b = b mod a .
2 mod 3 = 3 mod 2
2≠1
In case, if a = b =2
2 mod 2 = 2 mod 2
0=0
Consider the statement p(n),where n is an integer varying over the natural number 1,2,3,
…n. The statement p(n) is true for all natural numbers by proving two things.
Problems:
Solution:
Assume n = 1
L.H.S., n = 1
n(n+1)
R.H.S =
2
1(1+1)
=
2
= 2/2
=1
L.H.S = R.H.S
P(1) is true
b) Induction Step:
Assume n = k
K ( K +1)
1+2+3+….k = ----------------1
2
Assume n = k+1
( K +1 ) (K +1+1)
1+2+3+….k+k+1 = --------2
2
Substitute 1 in 2
L.H.S = 1+2+3+….k+k+1
K ( K +1)
= +k + 1
2
K ( K +1 )+ 2( K +1)
=
2
( K +1 ) (K +2)
=
2
( K +1 ) (K +1+1)
=
2
L.H.S = R.H.S
n
n ( n+1 ) (2 n+1)
2. Prove that 1 + 2 + 3 + …….+n = ∑ i =
2 2 2 2 2
i=1 6
Solution:
a) Basis:
L.H.S = n2
n=1
L.H.S = 12
=1
n ( n+1 ) (2 n+1)
R.H.S =
6
1 ( 1+1 ) (2(1)+1)
=
6
(2)(3)
=
6
(6)
=
6
R.H.S =1
L.H.S = R.H.S
P(1) is true
b) Induction Step:
Assume n = k
k ( k +1 ) (2 k +1)
12 + 22 + 32 + …….+k2 = ---------- 1
6
Assume n = k+1
(k + 1) ( k +1+1 ) (2 (k +1)+ 1)
12 + 22 + 32 + …….+k2 +(k+1)2 = ---------- 2
6
Substitute 1 in 2
k ( k +1 ) (2 k +1)
= +(k+1)2
6
k (2 k +1)
= (k+1)[ + k+1]
6
k ( 2 k +1 ) +6 k +6
= (k+1)[ ]
6
2
2 k + k +6 k + 6
= (k+1)[ ]
6
2
2 k + 7 k +6
= (k+1)[ ]
6
2
2 k + 4 k +3 k +6
= (k+1)[ ]
6
2 k ( k +2 ) +3(k +2)
= (k+1)[ ]
6
( k +2 ) (2 k +3)
= (k+1)[ ]
6
( k +1+1 ) +2 ( k +1 ) +1
= (k+1)[ ]
6
= R.H.S
3. Prove that all natural numbers of the form n3 + 2n are divisible by 3 using principle of
induction.
Solution:
P(n) = n3 + 2n
Let n = 1
b) Induction:
Assume n = n+ 1
= n3 + 3n2 + 5n +3
= n3 + 2n + 3n2 + 3n +3
= (n3+2n) + 3(n2+n+1)
n3 + 2n is divisible by 3 which is proved in basis step. The other term 3(n2+n+1) is a multiple of
3, which means it is also divisible by 3.
The most important definitions of terms that pervade the theory of automata are:
Alphabets:
An alphabet is a finite nonempty set of symbols denoted by the symbol “∑”. Common
alphabet include
String:
A string (or sometimes word) is a finite sequence of symbol chosen from some alphabets.
1. The length of the string is the number of positions for symbols in the string.
2. It is common to say that the length of a string is “the number of symbols” in the
string.
3. The standard notation for the length of a string w is |w|.
Example: w = 111011
|w| = 6
Empty String:
1. Empty string is the string with ‘0’ occurrences of symbols which is denoted by epsilon ‘ε
’.
2. Length of the empty string is ‘0’, |ε | = 0
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
If ∑ = {a,b,c} then
∑1 = {a,b,c}
∑2 = {aa,ab,ac,ba,bb,bc,ca,cb,cc}
∑3 = {aaa, aab,aac,……}
Another way,
∑+ = ∑1 U ∑2 U ∑3 …… (Positive Closure)
x = a1a2……ai
y = b1b2……bj
xy = a1a2……ai b1b2……bj
Example:
xy = 11010011
yx = 00111101
Languages:
Problems:
1. Given ∑ = {a,b} obtain ∑* .
i) Give an example of a finite language in ∑.
ii) Given L = { an bn; n≥ 0}, check if the string aabb, abb are in the language L.
Solution:
Given ∑ = {a,b}
∑* = {ε, a,b,ab,ba,aaa,….}
i) L = {ab, aabb, aaabbb}
ii) Given L = { an bn }
L = aabb (a2b2)
Here, n = 2
So, aabb is a string in the language L.
L =abb
Number of a’s are not equal to number of b’s, so this string is not in the language L
It is classified in to
A = (Q, ∑, δ, q0, F )
Where
A is the name of the DFA
Q = Finite set of “states”
∑ = Finite set of symbols called “Input alphabet”
δ = Transition Function
q0 = Start state
F = Set of Final states or Accepting states
1. Transition Diagram
2. Transition Table
Transition Diagram:
b) For each state q in Q and input symbol a in ∑, let δ (q,a) = p. Then transition diagram
has an arc from node q to node p, labeled a.
c) There is an arrow into the start state q0, labeled start. This arrow does not originate at
any node.
1 0 0,1
q0 0 1
q2 q1
Fig: The transition diagram for the DFA accepting all strings with a substring 01.
Transition Table:
1. A transition table is a conventional, tabular representation of a function δ that takes two
arguments and returns a value.
2. The rows of the table correspond to the states, and the columns correspond to the input.
0 1
q0 q2 q0
*q1 q1 q1
q2 q2 q1
Fig: Transition table for the DFA of above diagram
If δ is the transition function, the extended transition function ǧ is a function that takes a
state q and string w and returns a state p – the state that the automaton reaches when starting in
state q and processing the sequence of inputs w.
ǧ(q,w) = δ(ǧ(q,x),a)
L(A) = {w | ǧ(q0,w) is in F}
That is, The language of A is the set of strings w that take the start state q0 to one of the
accepting states.
Problems:
q0 q1
a
b
b
b b
a
q2 q3
a b
q0 q1 q2
q1 q0 q3
Transition q2 q3 q0 function:
*q3 q2 q1
δ(q0 , a) = q1
δ(q0 , b) = q2
δ(q1 , a) = q0
δ(q1 , b) = q3
δ(q2 , a) = q3
δ(q2 , b) = q0
δ(q3 , a) = q2
δ(q3 , b) = q1
ii) δ(q0, ababa) = δ(q1, baba)
= δ(q3, aba)
= δ(q2, ba)
= δ(q0, a)
δ(q0, ababa) = q1
δ(q1, b3 ) = δ(q1, bbb)
= δ(q3, bb)
= δ(q1, b)
= q3
δ(q1, b4 ) = δ(q3, bbbb)
= δ(q1, bbb)
= δ(q3, bb)
= δ(q1, b)
= q3
δ(q3, ε) = q3
Solution: i)
1
q0
∑* = { ∑0 U ∑1 U ∑3,……}
0 = ε ( empty set)
ii)
1
q0 q1
3. Design a DFA that accepts the string defined by the language L = { an b ; n≥1} ( Epsilon do
not accepted)
b
q0 q1
4. Design a DFA that recognizes the set of all strings on ∑ = { a, b} starting with the prefix ab.
a,b
a b
q0 q1 q2
5. Construct the DFA that will accept the string on {a, b} where the number of b’s divisible by 3.
Draw also the transition table.
Transition Table:
δ a b
q0 q0 q1
q1 q1 q2
q2 q2 q0
1. In NFA, for a given input symbol there are zero, one or more number of transitions to
next state from a given state.
2. A Non- Deterministic Finite Automaton (NFA) in a 5-tuple notation
A = (Q, ∑, δ, q0 , F )
where
Q = Finite set states
∑ = Finite set of input symbols
δ = Transition Function
q0, a member of Q, is the start state
F⊆ Q Set of Final states
Difference between NFA and DFA.
S. No NFA DFA
1 δ is a transition function that takes a state and The transition function returns
input symbol as argument but returns a zero, one exactly one state
or more states.
2 Q×(∑U{ε})2Q Q×∑Q
NFA:
0
0
q1
q0
DFA:
1
q1
q0
L(A) = { w| δ(q0,w) ∩ F ≠ ∅}
L(A) is the set of strings w in ∑* such that δ(q0,w) contain at least one accepting state.
Problems:
1 1,0
q0 q1 q2
Find 01010.
δ(q0,01010) = δ(q0,1010)
= δ({q0,q1}, 010)
= δ(δ(q0,0)U δ(q1,0),10)
= δ({q0}U{q2}, 10)
= δ({q0,q2},10)
= δ(δ(q0,1)U δ(q2,1),0)
= δ({q0,q1}U{∅ },0)
= δ(δ(q0,0)U δ(q1,0))
= {q0 U q2}
= (q0, q2 ) ∩ F ≠ ∅
= (q0, q2 ) ∩ q2
= q2 (Which is a final state)
The given string 01010 is accepted by NFA.
2. Obtain an NFA which should accept a language L, given by L {x ∈{ a,b}* :| x | 3 }and
third symbol of x from the right is {‘a’}.
The conditions are
(a) the last two symbols can be ‘a’ or ‘b’.
(b) third symbol from the right is ‘a’
(c) symbol in any position but for the last three position can be ‘a’ or
‘b
3. Determine an NFA accepting all strings over {0,1} which end in 1 but does not contain the
substring 00.
The conditions to be satisfied are:
(a) String should end in a 1
(b) String should not contain 00.
L = {1,11,1101,101…}
4. Construct an NDFA for all strings over alphabet ∑ = {a,b} that contains a substring ‘ab’.
a,b a,b
a b
q0 q1 q2
Theorem: Let L be a set accepted by NFA, then there exists a DFA that accepts L.
L(D) = L(N)
This proof uses a method “Subset construction” because it involves constructing all subset of the
set states of the NFA.
i.e., QD=2Q N
δD ([q1,q2,q3…qi],a) = [p1,p2,p3…pj]
if and only if ,
δN ({q1,q2,q3…qi},a) =[p1,p2,p3…pj ]
So we claim that
δD ([q1,q2,q3…qi],w) = [p1,p2,p3…pj]
if and only if
δN ({q1,q2,q3…qi},w) ={p1,p2,p3…pj}
Basis:
δD({q0},ε) = q0
δN(q0,ε) = q0
Induction Step:
Let w be the length n+1, Break w up as w = xa, where a is the final symbol of w.
δD(q0,xa) = δD(δD(q0,x),a)
δD(q0,x) = [p1,p2,p3…pj]
if and only if
δN(q0,x) = [p1,p2,p3…pj]
By the definition of δD
δD([p1,p2,p3…pj],a) = [r1,r2,r3…rk]
δN({p1,p2,p3…pj},a) ={r1,r2,r3…rk}
Thus,
δD(q0,xa) = [r1,r2,r3…rk]
δN(q0,xa) = [r1,r2,r3…rk]
δ 0 1
p {p,r} {q}
q {r,s} {p}
*r {p,s} {r}
*s {q,r} ∅
Solution:
δ(p,0) = {p,r}
δ(p,1) = {q}
δ({p,r},0) = δ(p,0) U δ(r,0)
= {(p,r) U (p,s)}
={p,r,s}
δ({p,r},1) = δ(p,1) U δ(r,1)
= {q U r}
= {q,r}
δ(q,0) = {r,s}
δ(q,1) = {p}
δ({p,r,s},0) = δ(p,0) U δ(r,0) U δ(s,0)
= {(p,r) U (p,s) U (q,r)}
= {p,q,r,s}
δ({p,r,s},1) = δ(p,1) U δ(r,1) U δ(s,1)
= {q U r U ∅ }
= {q,r}
δ({q,r},0) = δ(q,0) U δ(r,0)
= (r,s) U (p,s)
= {p,r,s}
δ({q,r},1) = δ(q,1) U δ(r,1)
= {p U r}
= {p,r}
δ({r,s},0) = δ(r,0) U δ(s,0)
= (p,s) U (q,r)
= {p,q,r,s}
δ({r,s},1) = δ(r,1) U δ(s,1)
= {(r) U ∅ }
= {r}
δ({p,q,r,s},0) = δ(p,0) U δ(q,0) U δ(r,0) U δ(s,0)
= {(p,r) U (r,s) U (p,s) U (q,r)
= {p,q,r,s}
δ({p,q,r,s},1) = δ(p,1) U δ(q,1) U δ(r,1) U δ(s,1)
= {q U p U r U∅ }
= {p,q,r}
δ({p,s},0) = δ(p,0) U δ(s,0)
= (p,r) U (q,r)
= {p,q,r}
δ({p,s},1) = δ(p,1) U δ(s,1)
= {qU ∅ }
= {q}
δ({p,q,r},0) = δ(p,0) U δ(q,0) U δ(r,0)
= (p,r) U (r,s) U (p,s)
= {p,r,s}
δ({p,q,r},1) = δ(p,1) U δ(q,1) U δ(r,1)
= {qUpUr}
= {p,q,r}
Transition Table:
δ 0 1
{p} {p,r} q
{p,r} {p,r,s} {q,r}
q {r,s} P
{p,r,s} {p,q,r,s} {q,r}
{q,r} {p,r,s} {p,r}
{r,s} {p,q,r,s} {p,s}
{p,q,r,s} {p,q,r,s} {p,q,r}
{p,s} {p,q,r} q
{p,q,r} {p,r,s} {p,q,r}
Transition Diagram:
0 0
p q3
p,r p,r,s
1
0
1
q
1 p,q,r,s
0 1
0
0
q,r 0 r,s
p,q,r
p,s
0 1
1.9 Finite Automata with Epsilon transitions:
1. A states in Q and
2. A member of ∑∪ { ϵ } , i.e., either an input symbol or the symbol ϵ.
Epsilon Closure:
ϵ - closure of a state is that all transitions out of that state that are labeled ϵ.
Example:
0 1 0
ϵ ϵ 1
q0 q1 q2 q3
Theorem: A Language L is accepted by some ε-NFA if and only if L is accepted by some DFA.
Proof : If Part
Suppose L= L(D) for some DFA, turn D in to an ε-DFA E by adding δ(q, ε) = for all
states q of D.
Then, we must also convert the transition on D on input symbol e.g δD(q, a) = p in an
NFA – transition to the set containing only p, i.e δE(q, a) ={p}. Thus the transition of E and D
are same.
Only if part:
L(D) = L(E)
δE(q0, w) = δD(qD, w)
Basis:
If |w| = 0, then w = ε
δE(q0, ε) = ε-closure(q0 )
Induction:
consider,
δE(q0, x) = {p1,p2,……. pk }
= ε-closure r1 U r2 U…rj
= ¿ j=1¿ m❑ ϵ-closure rj
δE(q0, w) = δD(qD, w)
• Hence proved.
1. Consider the NFA with ϵ- moves, the transition diagram is given by
q2 q4
a
b b a
ϵ ϵ ϵ
q0 q1 q3 q5
Solution:
i) δ(q0,ϵ) = ϵ - closure q0
= { q0,q1,q3,q5 }
Eliminating ϵ - Transitions:
a b c
ϵ ϵ
q0 q1 q2
a b c
a,b
q0 q1 c,b q2
a,b,c
1. Consider the following ϵ - NFA. Compute the ϵ - closure of each state and find it equivalent
DFA.
ϵ a b c
P {q,r} {q} {r}
q {p} {r} {p,q}
r {r}
b
c
ϵ
p q
a,c
b
ϵ
c
r
ϵ-closure(p) = {p,q,r}
ϵ-closure(q) = {q}
ϵ-closure(r) = {r}
DFA construction:
1. Start state p = ϵ-closure(p) = {p,q,r}
2. Find the transitions for new states
ϵ-closure (p,a) = ϵ-closure δ{(p, ϵ),a)
= ϵ-closure δ{(p,q,r),a}
= ϵ-closure δ(p,a) U δ(q,a)U δ(r,a)
= ϵ-closure()U (p)U ()
= ϵ-closure(p)
= {p,q,r}
ϵ-closure δ{(p,q,r),a} = ϵ-closure δ{(p,q,r),a}
= ϵ-closure δ(p,a) U δ(q,a)U δ(r,a)
= ϵ-closure()U (p)U ()
= ϵ-closure(p)
= {p,q,r}
ϵ-closure δ{(p,q,r),b} = ϵ-closure δ{(p,q,r),b}
= ϵ-closure δ(p,b) U δ(q,b)U δ(r,b)
= ϵ-closure(q)U (r)U ()
= ϵ-closure(qUr)
= ϵ-closure (q) U ϵ-closure(r)
= {q,r}U{r}
={q,r}
ϵ-closure δ{(p,q,r),c} = ϵ-closure δ{(p,q,r),c}
= ϵ-closure δ(p,c) U δ(q,c)U δ(r,c)
= ϵ-closure (r) U (q,r) U (r)
={p,q,r}
ϵ-closure δ{(q,r),a} = ϵ-closure δ{(q,r),a}
= ϵ-closure δ(q,a)U δ(r,a)
= ϵ-closure (p)U ()
= ϵ-closure(p)
= {p,q,r}
ϵ-closure δ{(q,r),b} = ϵ-closure δ{(q,r),b}
= ϵ-closure δ(q,b)U δ(r,b)
= ϵ-closure (r)U ()
= ϵ-closure(r)
= {r}
ϵ-closure δ{(q,r),c} = ϵ-closure δ{(q,r),c}
= ϵ-closure δ(q,c)U δ(r,c)
= ϵ-closure (p,q)U (r)
= {p,q,r}
ϵ-closure δ(r,a) = ϵ-closure
=
ϵ-closure δ(r,b) = ϵ-closure
=
ϵ-closure δ(r,c) = ϵ-closure(r,c)
= ϵ-closure r
= {r}
b
c
r q,r
a,c
p,q,r b
a,c