Updated TOC Material
Updated TOC Material
Updated TOC Material
p Q ¬p
T - F
F - T
A C
=
B C A B
Proof:
the statement we wish to prove is of the general form “for every x, if p(x) then q(x).” for
each x, the statement “ if p(x) then q(x)” is logically equivalent to “ if not p(x) then not
q(x).” and therefore the statement we want to prove is equivalent to this : For any positive
If it is not true that i ≤ or j ≤ , then i > and j> . A generally accepted fact
from mathematical is that if a and b are number with a> b, and c is a number >0, then
ac>bc.
Applying this to the inequality i> with c=j, we obtain i*j > * j. since n>0, we know
that >0, and we may apply the same fact again to the inequality j> , this time
letting c= , to obtain j > =n. we now have i*j > j >n, and it follow that i*j
≠ n.
Q.4 𝟐 (root two) is irrational number (Most IMP)
Suppose for the sake of contradiction that 𝟐 is rational. Then there are integers m’ and n’
with 𝟐= m’/ n’.
By dividing both m’and n’ by all the factors that are common to both, we obtain 𝟐=m/n,
for some integer m and n having no common factors. Since m/n= 𝟐, m= n 𝟐 . squaring
both sides of this equation , we obtain m2=2n2 , and therefore m2 is even .
If a and b are odd, then ab is odd. Since a conditional statement is logically equivalent to
its contrapositive, we may conclude that for any a and b, if ab is not odd, then either a is
not odd or b is not odd.
However, an integer is not odd if and only if it is even, and so for any a and b, if ab is
even, m must be even.
This means that for some k, m=2k. Therefore, (2k) 2=2n2.
Simplifying this and canceling 2 from both side, we obtain 2k2=n2. Therefore n2 is even.
The same argument that we have already used shows that n must be even, and so n=2j
for some j.
We have shown that m and n are both divisible by 2. This contradicts the previous
statement that m and n have no common factor. The assumption that 𝟐 is rational
therefore leads to a contradiction, and the conclusion is that 𝟐 is irrational.
Q.5 Principle of Mathematical Induction
Suppose P(n) is a statement involving an integer n. Then to prove that P(n) is true for every
n>=n0, it is sufficient to show these two things:
1. P (n0) is true.
2. For every k>= n0, if P(k) is true, P(k+1) is true.
Examples of PMI
Q.6 Prove
Step-1:Basic step
We must show that p(0) is true.
0 = 0(0+1)/2
And, this is obviously true.
Step-2:Induction Hypothesis
k >= 0 and
𝑘 𝑘+1
1+2+3+4…..+k = =
2
Step-3:Proof of Induction
𝑘+1 𝑘+2
p(k+1) = 1+2+3+….+k+(k+1) =
2
𝑘 𝑘+1
= + (k+1) by induction hypothesis
2
𝑘 𝑘+1 +2 𝑘+1
=
2
𝑘+1 𝑘+2
=
2
𝑘+1 ( 𝑘+1 +1)
P(k+1) =
2
Hence proved.
Q.7
Prove
Step-1:Basic
We must show that p(0) is true.
0 0+1 2 0 +1
P(0)= =0
6
And, this is obviously true.
Step-2:Induction Hypothesis
k >= 0 and
P(k) = 1+4+9+….k2
𝑘 𝑘+1 2𝑘+1
P(k)=
6
Step-3:Proof of Induction
P(k) = 1+4+9+….k2
𝑘 𝑘+1 2𝑘+1
P(k+1) = + (k+1)2
6
𝑘 𝑘+1 2𝑘+1 +6 𝑘+1 2
=
6
𝑘+1
= 𝑘 2𝑘 + 1 + 6 𝑘 + 1
6
𝑘+1
= 2𝑘2 + 𝑘 + 6𝑘 + 6
6
𝑘+1
= 2𝑘2 + 7𝑘 + 6
6
𝑘+1
= 2𝑘2 + 4𝑘 + 3𝑘 + 6
6
𝑘+1
= [2𝑘 𝑘 + 2 + 3(𝑘 + 2)]
6
𝑘+1
= 𝑘+2 2𝑘 + 3
6
𝑘+1 𝑘+2 2𝑘+3
=
6
𝑘+1 (𝑘+1 +1) 2𝑘+2+1
=
6
𝑘+1 (𝑘+1 +1) 2(𝑘+1)+1
=
6
Hence proved.
Q.8
Prove
Step-1:Basic
We must show that p(0) is true.
0 0
P(0) =
0+1
=1=0
1 1
=0 =0
𝑖 𝑖+1 0+1
k 1
= +
k+1 k+1 k+2
k k+2 +1
=
k+1 k+2
k( k+1 +1)+1
=
k+1 k+2
(k k+1 +k+1)
=
k+1 k+2
= k(3k+4)+(6k+6+1)
= 3k2+4k+6k+7
= 3k2+10k+7
= 3k2+3k+7k+7
= 3k(k+1)+7(k+1)
= (k+1)(3k+7)
= (k+1)(3k+3+4)
= (k+1)(3(k+1)+4)
Hence proved.
Q.10 Prove
Step-1:Basic
We must show that p(0) is true.
P(0)= (0+1)! =(1)! = 1
And, this is obviously true.
Step-2:Induction Hypothesis
k >= 0 and
p(k) = 1+(1+4+18+…..+(k*k!)) = (k+1)!
Step-3:Proof of Induction
P(k+1) = 1+(1+4+18+…..+(k*k!) + (k+1)*(k+1)!)
= (k+1)! + (k+1)(k+1)!)
= (k+1)! (1+(k+1))
= (k+1)! ((k+1)+1)
= ((k+1) + 1)!
Hence proved.
𝒏
Q.11 Prove 𝒊=𝟏 𝟐𝐢 − 𝟏 = 𝟏 + 𝟑 + 𝟓 + ⋯ + 𝟐𝐧 − 𝟏 = 𝒏𝟐
Step-1:Basic
We must show that p(1) is true.
P(1) = (1)2 = 1
And, this is obviously true.
Step-2:Induction Hypothesis
k >= 0 and
p(k) = 1+3+5+…..+(2k-1)=k2
Step-3:Proof of Induction
P(k+1) = 1+3+5+….+(2k-1)+(2(k+1)-1)
= k2 + (2(k+1)-1)
= k2 + (2k+2-1)
= k2 + 2k+1
=(k+1)2
Hence proved.
(2k )(2)>(k+1)3
2k+1>(k+1)3 ;k>=10
Hence proved.
= k(k2+5)+3k(k+1)+6
Here, k(k2+5) is divisible by 6 ,given in induction hypothesis.
In Second term k and k+1 consecutive. So, one number is even and one is odd. So, even
number is always multiple of 2 and here 3 is also present .So, second term having (2*3) is
also divisible by 6.
Last term 6 is obviously divisible by 6.
Hence proved.
Q.14 Strong Principle of Mathematical Induction
Suppose p(n) is a statement involving on integer n then to prove that p(n) is true for every n>=
n0. It is sufficient to show these two condition
1) P(n0) is true
2) For any k >=n0 , if p(n) is true for every n satisfying n0<=n<=k then p(k+1) is true.
Q.15 Prove that Integer Bigger than 2 have prime factorization using strong PMI
Basic step.
P(2) is the statement that 2 is either a prime or a product of two or more primes. This is
true or more primes.
Induction hypothesis.
K ≥ 2, and for every n with 2≤n≤k,n is either prime or a product of two or more primes.
Statement to be shown in induction step.
K+1 is either prime or a product of two or more primes.
Proof of induction step.
We consider two cases. If k+1 is prime, the statement p(k+1) is true. Otherwise, by
definition of a prime, k+1 = r*s, for some positive integer r and s, neither of which is 1 or
k+1. It follows that 2 ≤ r ≤ k and 2 ≤s ≤ k. therefore, by the induction hypothesis; both r
and s are either prime or the product of two or more primes.
Therefore, their product k+1 are the product of two or more primes. And p(k+1) is true.
(0+1)*1
11. Binary no. starts and end with 1.
1(0+1)*1
12. String starts and ends with same character.
0(0+1)*0 or a(a+b)*a
1(0+1)*1 b(a+b)*b
13. All string of a and b starting with a
a(a/b)*
14. String of 0 and 1 end with 00.
(0+1)*00
15. String end with abb.
(a+b)*abb
16. String start with 1 and end with 0.
1(0+1)*0
17. All binary string with at least 3 characters and 3rd character should be zero.
(0+1)(0+1)0(0+1)*
18. Language which consist of exactly Two b’s over the set ∑={a,b,}
a*ba*ba*
19. ∑={a,b} such that 3rd character from right end of the string is always a.
(a/b)*a(a/b)(a/b)
20. Any no. of a followed by any no. of b followed by any no of c.
a*b*c*
21. It should contain at least 3 one.
(0+1)*1(0+1)*1(0+1)*1(0+1)*
22. String should contain exactly Two 1’s
0*10*10*
23. Length should be at least be 1 and at most 3.
(0+1)+ (0+1) (0+1)+ (0+1) (0+1) (0+1)
24. No.of zero should be multiple of 3
(1*01*01*01*)*+1*
25. ∑={a,b,c} where a are multiple of 3.
((b+c)*a (b+c)*a (b+c)*a (b+c)*)*
26. Even no. of 0.
(1*01*01*)*
27. Odd no. of 1.
0*(10*10*)*10*
28. String should have odd length.
(0+1)((0+1)(0+1))*
29. String should have even length.
((0+1)(0+1))*
30. String start with 0 and has odd length.
0((0+1)(0+1))*
a b c
q q1 q2 q3
δ*(q,abc)
δ(δ*(q,ab),c)
δ(δ*( δ*(q,a),b),c)
δ(δ(δ* (q,^a),b),c)
δ(δ(δ(δ*(q,^),a),b),c)
δ(δ(δ(q,a),b),c)
δ(δ(q1,b),c)
δ(q2,c)
q3
1 C
0 B 1
A
1
0 D
1
The string with number of 0s and number of 1s are odd
odd 0 1
odd 0
odd 1 even 1
1
0 0 0 0
1 even1
odd1 even 0
even 0
1
0 C
1
1 0
A B
0
1 D
0
0,1
1
0 D
0
0 0 0
0
1
1
A 1 B
1
1
Draw FA for regular expression : (111+100)*0
C
1 1 0 0,1
1
A B F
0
1
0
0 D
0,1
E
0,1
1
0 D
0
0 0 0
1
A 1
1 B
1
(00)*(11)*
b
a B
a
b
b
A C
b
b
a
a
a
E D
(a+b)*baaa
P b
a,b
a t
q0 a
a
b
b n S b
Q.7 Find a string of minimum length in {0,1}* not in the language corresponding to the
regular expression: 1*(0+10)*1*
The smallest string = 0110
Q.8 Draw a DFA that recognize the language of all string of 0’s and 1’s of length at
least 1 that, if they were interpreted as a binary representation of integers, would
represent evenly divisible by 3. Your DFA should accept the string 0 but no other
string with leading 0.
0,1
q0
1 0 E
0
q0 B qC
A 0
1
0 1
0 qF
0 0,1
0,1 1
q
D0
Ex: all strins of length atmost 3. The string of length >3 should be rejected through a dead state or a
failure state. In above example dead state is q4.
Q.10 Union, Intersection & Compliment operation on Finite Automata
Suppose M1=(Q1,∑,q1,A1,δ1)
M2=(Q2,∑,q2,A2,δ2)
Accept language L1 and L2 respectively let M be an Finite Automata defined by
M=(Q,∑,q,A,δ) where
Q=Q1×Q2
q0=( q1, q2) and transition function δ is defined by the formula
δ((p,q),a)=(δ(p,a), δ(q,a)) for any p ∈ Q1 and q ∈ Q2 and a ∈ ∑ then
1) if A={(p,q) / p ε A1 or q ∈ A2}, M accept the language L1 U L2
2) if A={(p,q) / p ε A1 and q ∈ A2}, M accept the language L1 ∩ L2
3) if A={(p,q) / p ε A1 and q ∉ A2}, M accept the language L1 - L2
Q.11 Draw Finite Automata for following language
L1={x/x 00 is not substring of x, x ∈ {0,1}*}
L2={x/x ends with 01, x ∈ {0,1}*}
Draw finite Automata for L1 U L2, L1∩ L2 and L1-L2.
(Most IMP)
M1
1 0,1
0
A B 0
C
M2
1 0
0 1
P Q R
0
here Q1={A,B,C}
Q2={P,Q,R}
So, Q = Q1×Q2
={AP,AQ,AR,BP,BQ,BR,CP,CQ,CR}
q0=(q1,q2)
q0=(A,P)
1 1
AP BP CP
0 1
0
AQ BQ 0 CQ
1 0
1
0
AR 1 BR CR
L1-L2
BQ 0 CQ
1 1
0
AP 0 0 1 CP
1
1 1
AR CR
L1 U L2
1 BQ 1 CQ
1
0 0
0
AP 0 0 1 CP
1
1
1
AR CR
L1∩ L2
BQ 1 CQ
1 0 1
0
AP 0 0 1 CP
1
1
1
AR CR
0 1 0,1
A B 1 C
0
M2
0 1
1 0 R
P Q
1
0
Here Q1={A,B,C}, Q2={P,Q,R}
So, Q = Q1×Q2 ={AP,AQ,AR,BP,BQ,BR,CP,CQ,CR}
q0=(q1,q2)
q0=(A,P)
δ((A,P),0) = (δ(A,0), δ(P,0))
= AP
δ((A,P),1) = (δ(A,1), δ(P,1))
= BQ
δ((B,Q),0) = (δ(B,0), δ(Q,0))
= AR
δ((B,Q),1) = (δ(B,1), δ(Q,1))
= CQ
δ((A,R),0) = (δ(A,0), δ(R,0))
= AP
δ((A,R),1) = (δ(A,1), δ(R,1))
= BQ
δ((C,Q),0) = (δ(C,0), δ(Q,0))
= CR
δ((C,Q),1) = (δ(C,1), δ(Q,1))
= CQ
δ((C,R),0) = (δ(C,0), δ(R,0))
= CP
δ((C,R),1) = (δ(C,1), δ(R,1))
= CQ
δ((C,P),0) = (δ(C,0), δ(P,0))
= CP
δ((C,P),1) = (δ(C,1), δ(P,1))
= CQ
L1 - L2
0 0
AP BP CP
1 0
1
1 0 1
AQ BQ CQ
0 1
1
0
AR 0 BR CR
L1 ∩ L2
0 0
AP BP CP
1 0
1
1
AQ BQ 1 CQ
0 1
0
1
AR 0 BR CR
1
0,1
A 0 B 0 C
1
L2
1 0,1
A 0 B 0 C
Q1={A,B,C},Q2={A,B,C}
Q=Q1×Q2= {AA,AB,AC,BA,BB,BC,CA,CB,CC}
q0=(q1,q2) q0=(A,A)
δ((A,A),0) = (δ(A,0), δ(A,0))= BB
δ((A,A),1) = (δ(A,1), δ(A,1))= AA
δ((B,B),0) = (δ(B,0), δ(B,0))= CC
δ((B,B),1) = (δ(B,1), δ(B,1))= AA
δ((C,C),0) = (δ(C,0), δ(C,0))= CC
δ((C,C),1) = (δ(C,1), δ(C,1))= CC
L1 - L2
AA BA CA
0
AB BB CB
1
0
0,1
AC BC CC
L1 ∩ L2
1
0,1
0 0
AA BB CC
A nondeterministic finite automaton (NFA) is a 5-tuple (Q,Ʃ, q0,A, δ),Where Q and Ʃ are nonempty
For an NFA M=(Q,Ʃ, q0,A, δ), and any p ∈ Q, δ*(p, Λ)= {p}. for any p ∈ Q and any p ∈ Q and any
x= a1a2….an∈Ʃ* (with n≥1), δ*(p,x) is the set of all states q for which there is a sequence of states
p=p0,p1,….pn-1,pn=q satisfying
Pi ∈δ*( pi-1 , ai) for each i with1 ≤ i ≤ n
Q.3 Definition :Recursive Definition of δ* for an NFA
Let M=(Q,Ʃ, q0,A, δ), be an NFA. The function δ*: Q × Ʃ* 2Q is defined as follows.
1) For any q ∈ Q, δ*(q, Λ) = {q}.
δ*(q,ya)= U δ(r,a)
r ∈δ*(q,y)
Q.4 Definition : Acceptance by an NFA
Let M=(Q,Ʃ, q0,A, δ), be an NFA. The string x ∈Ʃ* is accepted by M if δ*(q0,x)∩ A≠Ø. The language
recognized, or accepted, by M is the set L(M) of all string accepted by M, for any language L ⊆ Ʃ*, L
is recognized by M if L=L(M).
Q.5 Using the Recursive Definition of δ* in an NFA.
Let M=(Q,Ʃ, q0,A, δ), where Q= {q0, q1, q2, q3}, Ʃ={0,1}, A={ q3}, and δ is given by the following
table
Q δ(q,0) δ(q,1)
q0 { q 0} { q0, q1}
q1 { q 2} { q 2}
q2 { q 3} { q 3}
q3 Ø Ø
0,1
0,1 0,1
1
q0 q1 q2 q3
Then M can be represented by the transition diagram. let us try to determine L(M) by calculating
δ*( q0,x) for a few string x of increasing length. First observe that form the nonrecursive definition
of δ* it is almost obvious that δ and δ* agree for string of length 1. we see from the table that
δ*( q0,0)={ q0} and δ*( q0,1)={ q0, q1};
= U δ( r,1)
r∈{ q0, q1}
= δ{ q0,1}U δ( q1,1)
= {q0, q1}U{ q2}
={q0, q1, q2}
= U δ( r,1)
r∈( q0)
= δ( q0,1)
= {q0, q1}
= δ(q0,1)U δ(q1,1)
= {q0, q1, q2}
A nondeterministic finite automata with Λ - Transition is a 5-tuple (Q,Ʃ, q0,A, δ), where Q and Ʃ are
sequence b1b2….bm ∈Ʃ∪ { Λ}satisfying b1b2….bm=x, and a sequence of states p= p0, p1… pm=q so
For x ∈Ʃ* and p ∈δ*( p,x) is the set of all states q ∈ Q such that there is a sequence of
Let M=(Q,Ʃ, q0,A, δ), be an NFA – Λ, and let S ne any subset of Q. The Λ- closure of S is the set
follows.
1) For any q ∈ Q, δ(q, Λ)= Λ({q}).
δ*(q,ya)= Λ( U δ(r,a))
r∈ δ*(q,y)
0 1
P 1 0 S
r
^ ^
^ W
q0
^ ^
0 0
t u v
1
0
δ*(q0,^) = ^({q0})
= { q0,p,t}
2
a b
b 4
1
a a
3
q δ(q,a) δ(q,b)
1 {2,3} {4}
2 {Ø} {4}
3 {4} {3}
4 {Ø} {Ø}
a b 3,4
1 2,3
b a a
b
4 3
a
C
0 1 0
0
^ ^
A B D
δ*(A, ^) = {A,B,D}
δ*(B,^) = {B,D}
δ*(B,0) = ^ ( U δ(r,0))
r∈δ*( B,^)
=^( U δ(r,0))
r∈δ(B,D)
= ^(δ(B,0)U δ(D,0))
= ^{ C,D}
= {C,D}
δ*(B,1) =^( U δ(r,1))
r∈δ*( B,˄)
=^( U δ(r,1))
r∈δ(B,D)
= ^(δ(B,1)U δ(D,1))
=Ø
δ*(C,˄) = {C}
δ*(C,0) =^( U δ(r,0))
r∈δ*( C,˄)
=^( U δ(r,0))
r∈δ(C)
= ^(δ(C,0))
=Ø
δ*(C,1) =^( U δ(r,1))
r∈δ*( C,˄)
=^( U δ(r,1))
r∈δ(C)
= ^(δ(C,1))
= ^{B}
={B,D}
δ*(D,˄) = {D}
δ*(D,0) =^( U δ(r,0))
r∈δ*( D,^)
=^( U δ(r,0))
r∈δ(D)
= ^(δ(D,0))
= {D}
δ*(D,1) =^( U δ(r,1))
r∈δ*( D,^)
=^( U δ(r,1))
r∈δ(D)
= ^(δ(D,1))
=Ø
C
1
0 0 1
0 0
A 0 B 0 D
δ({A},0) = {A,B,C,D}
δ({A},1) =Ø
δ({A,B,C,D},0) = (δ(A,0)U δ(B,0)U δ(C,0)U δ(D,0))
= {A,B,C,D}
δ({A,B,C,D},1) = (δ(A,1)U δ(B,1)U δ(C,1)U δ(D,1))
= {B,D}
δ({B,D},0) = (δ(B,0)U δ(D,0))
= {C,D}
δ({B,D},1) = (δ(B,1)U δ(D,1))
=Ø
δ({C,D},0) = (δ(C,0)U δ(D,0))
= {D}
δ({C,D},1) = (δ(C,1)U δ(D,1))
= {B,D}
δ({D},0) = {D}
δ({D},1) =Ø
0
ABCD 1 BD
0
0
1 1 CD
A
1 0
Ø D
1
0,1 0
1
0
0
^ B 1
A E
^
0
D
1
δ*(A,^) = {A,B,D}
δ*(A,0) =^( U δ(r,0))
r∈δ*( A,^)
=^( U δ(r,0))
r∈δ(A,B,D)
= ^(δ(A,0)U δ(B,0)U δ(D,0))
= ^{A,C,E}
={A,B,C,D,E}
δ*(B,^) = {B}
δ*(B,0) =^( U δ(r,0))
r∈δ*( B,^)
=^( U δ(r,0))
r∈δ (B)
= ^(δ(B,0))
= ^{ C}
= {C}
δ*(B,1) =^( U δ(r,1))
r∈δ*( B,^)
= ^( U δ(r,1))
r∈δ (B)
= ^(δ(B,1))
=E
δ*(C,) = {C}
δ*(C,0) =^( U δ(r,0))
r∈δ*( C,^)
=^( U δ(r,0))
r∈δ(C)
= ^(δ(C,0))
=Ø
δ*(C,1) =^( U δ(r,1))
r∈δ*( C,^)
=^( U δ(r,1))
r∈δ(C)
= ^(δ(C,1))
= ^{B}
={B}
δ*(D,^) = {D}
δ*(D,0) =^( U δ(r,0))
r∈δ*( D,^)
=^( U δ(r,0))
r∈δ(D)
= ^(δ(D,0))
= ^ {E}
= {E}
δ*(D,1) =^( U δ(r,1))
r∈δ*( D,^)
=^( U δ(r,1))
r∈δ(D)
= ^(δ(D,1))
= {D}
δ*(E,^) ={E}
δ*(E,0) =Ø
δ*(E,1) =Ø
1
0 0
B
0 0 1
0,1
A E
0,1
0
D
δ({A},0) = {A,B,C,D,E}
δ({A},1) = {ED}
δ({A,B,C,D,E},0) = (δ(A,0)U δ(B,0)U δ(C,0)U δ(D,0)U δ(E,0))
= {A,B,C,D,E}
δ({A,B,C,D,E},1) = (δ(A,1)U δ(B,1)U δ(C,1)U δ(D,1) U δ(E,0))
= {E,B,D}
δ({E,D},0) = (δ(E,0)U δ(D,0))
= {Ø}U{E}
= {E}
δ({E,D},1) = (δ(E,1)U δ(D,1))
= {Ø}U{D}
= {D}
δ({B,E,D},0) = (δ(B,0)Uδ(E,0)U δ(D,0))
= {C,E}
δ({B,E,D},1) = (δ(E,1)U δ(D,1))
= {D,E}
δ({C,E},0) = (δ(C,0)U δ(E,0))
=Ø
δ({C,E},1) = (δ(C,1)U δ(E,1))
= {B}
δ({D},0) = {E}
δ({D},1) = {D}
δ({B},0) = {C}
δ({B},1) = {E}
δ({E},0) =Ø
δ({E},1) =Ø
δ({C},0) =Ø
δ({C},1) = {B}
ABCDE 1 BDE 0 CE
0
0
1 0,1
0 1
A Ø C
1
1
0,1 0
DE 0 B
E
1
1
0
D
W a W
Ø {^} {a}
Now, suppose that L1 and L2 are recognized bt the NFA-^s M1 and M2, respectively, where
for both i=1 and i=2,
Mi=(Qi,ε,qi,Ai,δi)
f1
qu
f1’
^
qu
f2
^ qu
’
f2
Construction of Mu = (Qu, ε,qu,Au,δu). let qube a new state, not in either Q1 or Q2 and let
Qu = Q1 U Q2 U { qu }
Au = A1 U A2
Now, we define δuso that Mu can move from its initial state to either q1 or q2 by a ^-
transition, and then make exactly the same moves that the respective Mi would. normally
we define
δu(qu,^) = {q1,q2}
δu(qu,a) = Ø for every a ∈ ε and for each q∈Q1 U q2 and a ∈ ε U {^},
δu(qu,a)={ δ1(q,a) if q ∈ Q1} and { δ2(q,a) if q ∈ Q2}
For either value of I, if x∈ Li, then Mu can process x by moving to qi on a ^-transition and
then executing the moves that cause Mi to accept x, on the other hand, if x is accepted by
Mu, there is a sequence of transition corresponding to x, starting at q u and ending at an
element of A1 or A2. the first of these transition must be a ^-transition from qu to either q1
or q2, since there are no other transition from qu. therefore, since Q1 ∩ Q2 = Ø,either all
the transition are between of Q1 or all are between elements of Q 2. it follow that x must be
accepted by either M1 or M2.
Construction Of Mc
f1 f2
^
qc=q1 q2
f1’ ^ f2’
Construction of Mu = (Qc,ε,qc,Ac,δc). in this case we do not need any new states, Let Q c =
Q1 U Q2, qc=q1, and Ac = A2. the transition will include all those of M1 and M2as well as a ε-
q1
^ 1
qk
^ f1 f1’
Construction of Mu = (Qk, Ʃ, qk, Ak,δk). letqk be a new state not in Q1 and let Qk=Q1U{qk}.
Once again all the transitions of M1 will be allowed in M k, but in addition there is a ˄-
transition from qk to q1 and there is a ˄-transition from each elements of A1 to q k. More
precisely,
δk(qk,˄)={q1} and δk(qk,a)= Ø for a ∈ A1 and α=˄.
for q∈A1,δk(qk,˄)= δk(qk,˄)U{qk}.
Suppose x∈L1*. if x=˄ then clearly x is accepted by Mk. otherwise, for some
m≥1,x=x1x2….xm, where xi ∈ L1 for each i. Mk can move from qk to q1 by a ˄-transition:
for each I,Mk moves from q1 to an element fi of A1 by a sequence of transition
corresponding to xi; and for each i, Mk then moves from fi back to qk by a ˄-transition.
It follows that (˄x1˄) (˄x2˄)…… (˄xm˄)=x is accepted by Mk. On the other hand, if x is
accepted by Mk, there is a sequence of transition corresponding to x that begins and ends
at qk. since the only transition from qk is a ˄-transition to q1, and the only transition to qk
are ˄-transition from elements of A1, x can be decomposed in the form
x=(^x1˄) (˄x2˄)…… (˄xm˄)
Where, for each I, there is a sequence of transition corresponding to xi from q1 to an
element of A1. Therefore, x∈ L1*.
Since we have constructed an NFA-˄ recognizing L in each of the three cases, the proof is
complete.
Q.16 Draw NFA-^ for regular expression (00+1)*(10)*
Q.2 Using this procedure convert the following DFA into minimum number of states
DFA (minimized FA)where ε={0,1}
q δ(q,a) δ(q,b)
1 {3} {2}
2 {4} {1}
3 {5} {4}
4 {4} {4}
5 {3} {2}
a
3 a 5
a
b a,b
1
b 4
a
b b
2
2
3 X X
4 X
5 X X X X
1 2 3 4
Final state is {5}
And, Non-Final state is {1,2,3,4}
(1, 5), (2, 5), (3, 5), (4, 5) are distinguish pairs.
Consider pair (1,2)
δ(1,a)=3 δ(1,b)=2
δ(2,a)=4 δ(2,b)=1
b a
3
1,2,4 b a
a
b 5
2 b
a b
a 5
1
a
b a b
3 4
b a
2 X
3 X
4 X X
5 X X X X
1 2 3 4
Final state is {5}
And, Non-Final state is {1,2,3,4}
(1, 5), (2, 5), (3, 5), (4, 5) are distinguish pairs.
Consider pair (1,2)
δ(1,a)=2 δ(1,b)=3
δ(2,a)=3 δ(2,b)=5
pair (3,5) is distinguish, so (1,2) is distinguish.
Consider pair (1,3)
δ(1,a)=2 δ(1,b)=3
δ(3,a)=4 δ(3,b)=3
b
b
a
b
1,3 2,4 5
a a
a 4
2 b
a
a b 5
1 a
b
b a 6 b
3
b a
7
b
2 X
3 X
4 X X X
5 X X
6 X X X X
7 X X X
1 2 3 4 5 6
a
b
a
b a
1,3,5,7 4 2,6
2 ×
3 × ×
4 × × ×
5 × × × ×
6 × × × × ×
1 2 3 4 5
3
b b
a
b b
a a a a
1 2 4 5 6
b
a
Application:
The pumping lemma is extremely useful in proving that certain sets are non-regular. The general
methodology followed during its applications is :
Select a string z in the language L.
Break the string z into x, y and z in accordance with the above conditions imposed by the
pumping lemma.
Now check if there is any contradiction to the pumping lemma for any value of i.
2) a*b*
SXY
XaX/˄
YbY/˄
SABC
A0A1 |˄
B1B | 1
C1C0 |˄
6) Write CFG for (011+1)*(01)*
SAB
A011A | 1A | ^
B01B | ^
7) Write CFG which contains at least three times 1.
SA1A1A1A
A0A | 1A | ^
8) CFG should start and end with same symbol.
S0A0 | 1A1
A0A | 1A | ^
Q.6 Define: Regular Grammar
A grammar G=(V,Ʃ,S,P) is regular if every production takes one of the two forms
BaC
Ba
for variable B and C and terminal a
Q.7 Converting Finite Automata to Grammar
1
0
1 0
A B C
Equivalent CFG
A0A
A1B
B1B
B0C
B0
C0A
C1B
S S
S - S S - S
S * S a a S / S
a a a a
An Ambiguous CFG :
A context free grammar G is ambiguous if there is at least one string in L(G) having two or more
distinct derivation tree.(or, equivalently two or more distinct leftmost derivation or rightmost
derivation)
1) Prove that given grammar is ambiguous SS+S / S-S / S*S / S/S /(S)/a (IMP)
String : a+a+a
SS+S SS+S
a+S S+S+S
a+S+S a+S+S
a+a+S a+a+S
a+a+a a+a+a
S S
S + S S + S
a S + S S + S a
a a a a
Dixita Kagathara Page 4
Context Free Grammar 160704 – Theory of Computation
We have two left most derivation for string a+a+a hence, proved that above grammar is
ambiguous.
2) Prove that S->a | Sa | bSS | SSb | SbS is ambiguous
String: baaab
SbSS SSSb
baS bSSSb
baSSb baSSb
baaSb baaSb
baaab baaab
We have two left most derivation for string baaab hence, proved that above grammar is
ambiguous.
<statement>
<statement>
if else
( <expression> ) <statement>
<exp1> g();
) <statement>
( <expression>
if
f();
<exp2>
Figure (a)
<Statement>
if
( <expression> ) <statement>
else
<statement>
<exp1> ) <statement>
( <expression>
if
f(); g();
<exp2>
Figure (b)
Two interpretation of a “dangling else”
if(exp1) {if(exp2) f();} else g();
forces the first interpretation, where as
if(exp1) {if(exp2) f(); else g();}
Q.10 Simplifies form & Normal forms
Definition:Null able Variable:
a nullable variable in a CFG G=(V,Ʃ,S,P) is defined as follows
1) Any variable A for which P contains A˄ is nullable
2) if P contain production
AB1B2…..Bn where B1B2…Bn are nullable variable, then A is nullable.
3) No other variable in V are nullable.
Eliminate ˄ production :
1) SaX/Yb
XS/˄
YbY/b
Ans:
SaX/Yb/a
XS
YbY/b
2) SXaX/bX/Y
XXaX/XbX/˄
Yab
Ans:
SXaX/bX/Y/aX/Xa/a/b
XXaX/aX/Xa/a/XbX/Xb/bX/b
Yab
Aa/bc/B
Aa/bc/A/bb
Aa/bc/bb
BA/bb
Ba/bc/bb
So CFG after removing unit production is
SAa/a/bc/bb
Aa/bc/bb
Ba/bc/bb
Definition of Chomsky Normal Form
A context free grammar is in Chomsky normal form (CNF) is every production is one of these two
types ABC
Aa
Where A, B, C are nonterminal and a is terminal.
Step to convert CFG into CNF.
1) Eliminate ˄-Production
2) Eliminate Unit Production
3) Restricting the right side of products to single terminal or string of two or more variable
(Replace all mixed string with solid NTs)
4) Final step of CNF
(shorten the string of NT to length 2)
Stack
A PDA can write an unbounded no. of stack symbols on the stack and read these symbols
later.
Writing a symbol on to the stack is called “PUSH” operation.
Removing a symbol off the stack is called “POP” operation.
PDA can accept only the stacks top most symbol.
Definition of Pushdown Automata :-
A pushdown Automata(PDA) is a 7-tuple M= (Q,Ʃ,┌,q0,Z0,A, δ) where
Q is finite sets of state
Ʃ and┌ are finite sets, the i/p and stack alphabet respectively
q0 is initial state
Z0 is initial stack symbol, is an element of ┌.
A is a set of accepting states
δ :Q × (ƩU{˄})×┌ the set of finite subset of Q×┌*
The function δ is called transition function of M.
Acceptance by a PDA:-
if M= (Q,Ʃ,┌,q0,Z0,A, δ) is a PDA and x ∈ Ʃ* , x is accepted by M, If(q0,x,z0) ⊢m*(q,˄,α) for some
α∈┌* and some q∈ A.A language α⊆Ʃ* is said to be accepted by M if L is precisely the set of strings
accepted by M, in this case, we write L=L(M)
Q.3 Give a Transition Table and Transition Diagram for following CFG.
SaSa/bSb/C
OR
Design PDA for L={x∈xr/x∈{a,b}*}The string in L are odd length palindromes
over {a,b}
OR
Design PDA for palindrome with middle symbol c.
Move State i/p Stack Symbol Move
No.
1 q0 a Z0 (q0,aZ0)
2 q0 b Z0 (q0,bZ0)
3 q0 a a (q0,aa)
4 q0 b a (q0,ba)
5 q0 a b (q0,ab)
6 q0 b b (q0,bb)
7 q0 c Z0 (q1, Z0)
8 q0 c a (q1, a)
9 q0 c b (q1, b)
10 q1 a a (q1, ˄)
11 q1 b b (q1, ˄)
12 q1 ˄ Z0 (q2, Z0)
b,z0/bz0 a,a/ ^
a,a/aa
a,z0/az0
c,a/a ^,z0/z0
c,b/b q2
q0 q1
c,z0/z0
a,b/ab b,b/bb
b,b/ ^
b,a/ba
String:abcba
Move No. Resulting State unread i/p Stack
Initial q0 abcba Z0
1 q0 bcba aZ0
4 q0 cba baZ0
9 q1 ba baZ0
11 q1 a aZ0
10 q1 - Z0
12 q2 - Z0
String: ab
Move No. Resulting State unread i/p Stack
Initial q0 ab Z0
1 q0 b aZ0
4 q0 a baZ0
Q.4 Give Transition table& Transition Diagram for the language of palindromes
Design PDA for even-odd length palindrome. (Most IMP)
Here we have to consider the language pal of palindromes over {a,b} both with even-length and
odd-length
Move No. State i/p Stack Symbol Move
1 q0 a Z0 (q0,aZ0) (q1,Z0)
2 q0 b Z0 (q0,bZ0) (q1,Z0)
3 q0 a a (q0,aa) (q1,a)
4 q0 b a (q0,ba) (q1,a)
5 q0 a b (q0,ab) (q1,b)
6 q0 b b (q0,bb) (q1,b)
7 q0 ˄ Z0 (q1, Z0)
8 q0 ˄ a (q1, a)
9 q0 ˄ b (q1, b)
10 q1 a a (q1, ˄)
11 q1 b b (q1, ˄)
12 q1 ˄ Z0 (q2, Z0)
b,b/bb
a,b/ab
b,a/ba
^,b/b
a,a/aa ^,a/a
a,z0/az0 a,a/a b,b/ ^
b,z0/bz0 b,a/a a,a/^
a,b/b
^,z0/z0
b,b/b
q0 q1 q2
b,z0/z0
a,z0/z0
^,z0/z0
String:aba
Move No. Resulting State unread i/p Stack
Initial q0 aba Z0
4 q0 ba aZ0
10 q1 a aZ0
12 q1 ˄ Z0
q2 ˄ Z0
Q.5 Design PDA for L={anbn/a,b∈Ʃ,n≥0} or PDA for Number of a’s and b’s are same.
String:aaabbb
Resulting State unread i/p Stack
q0 aaabbb Z0
q0 aabbb aZ0
q0 abbb aaZ0
q0 bbb aaaZ0
q1 bb aaZ0
q1 b aZ0
q1 ˄ Z0
q2 ˄ Z0
accepted
a,z0/ az0
a,a/ aa
b,a/ ^
b,a/ ^ ^,z0/^
q0 q1 q2
^,z0/ ^
Q.6 Design and Draw a deterministic PDA Accepting “Balance string of brackets”.
OR
Design and Draw a deterministic PDA for following grammar SSS/[S]/{S}/˄
5 q1 { [ (q1,{[)
6 q1 [ [ (q1,[[)
7 q1 ] [ (q1,˄)
8 q1 } { (q1,˄)
9 q1 ˄ Z0 (q0,z0)
{,[/{[
[,z0/[z0 {,{/{{
[,[/[[
{,z0/{z0
q0 q1
[,{/[{
^,z0/z0 ],[/˄
},{/ ^
String: []{}
Resulting State unread i/p Stack
q0 []{} Z0
q1 ]{} [Z0
q1 {} Z0
q1 } {Z0
q1 ˄ Z0
q0 ˄ Z0
a,a/^
b,z0/ bz0
^,a/a
a,z0/ az0
q0 q1
a,a/ aa
b,b/^
b,a/ ^
SS+T
ST
TT*a
Ta
State input Stack symbol Moves
Moves to Reduce S+T to S
q ˄ T (q1,1,˄)
q1,1 ˄ + (q1,2,˄)
q1,2 ˄ S (q,S)
Moves to Reduce T to S
q ˄ T (q,S)
Moves to Reduce T*a to T
q ˄ a (q3,1,˄)
q3,1 ˄ * (q3,2,˄)
q3,2 ˄ T (q,T)
Moves to Reduce a to T
q ˄ a (q,T)
Moves S to accept
q ˄ S (q,˄)
q1 ˄ Z0 (q2,˄)
Q.14 Give the difference between Top Down & Bottom Up parsing.
Top Down Parsing Bottom Up Parsing
A parser is top-down if it discovers a A parser is bottom up if it discovers a
parse tree top to bottom parse tree bottom to top
A top down parser for a given grammar In bottom up parsing, the source string
G tries to derive a string through a is reduced to the start symbol of the
sequence of derivation starting with a grammar. Bottom up parsing method is
start symbol. also called shift reduce parsing.
Top down parsing methods are: Bottom up parsing methods are:
Top down parsing(with Naïve bottom up parsing
backtracking/without Operator precedence parsing
backtracking) LR parsing
Recursive decent parser
LL(1) parser
δ (p, s, X)=(q,˄)
or one of the form
δ (p, s, X)=(q, αX)
where s ϵ {a, b, ˄} and αϵ Г*.
The effect of modification is that M can still remove a symbol from the stack or place
another symbol on the stack, but it cannot do both in the same move.
We observe next that for any string x, M must eventually read every symbol of x.
The any string xxr , for example , is a palindrome, and M must read it completely in order to
accept it. However, because M is deterministic, the moves it makes while processing x in the
course of accepting xxr are exactly the moves it must make on input x, whether or not x is
followed by anything else.
After M has processed a string x, its stack is a certain height, depending on how much M
needs to remember about x. We may consider how much shorter the stack can ever can
gets as a result of reading subsequent input symbols.
For each x, let yx be a string for which this resulting stack height is as small as possible. (If
cannot be 0, because M must still be able to process longer string with prefix xyx.) In other
words,
(q0, xyx, Z0)├* (qx, ˄, αx)
For some state qx and some string αx ϵ Г* with | αx| > 0; and for any string, any state p, and
any string β ϵ Г*,
If (q0, xy, Z0) ├* (p, ˄, β) then |β| ≥ |αx|
Because of our initial assumption about the moves of M, any move that involves removing a
stack symbol decreases the stack height. Therefore, once M, reaches the configuration (qx,
˄, αx), as a result processing the string of xyx, no symbols of string αx will ever be removed
from the stack subsequently.
Let Ax be the first symbol of string αx. The set S of all strings of the form xyx is infinite
(because we may consider x of any length), and the set of all ordered pairs (q x, Ax) is finite
(because the entire set Q×Г is finite).
Therefore, there must be an infinite subset T of S so that for all elements xyx of T, the pairs
(qx , Ax) are equal. In particular, we can choose two different strings u1 = xyx and u2 = wyw
so that
Q.1 Theorem:-There are CFL s L1 and L2 so that L1∩ L2 is not a CFL, and there is a
CFL L. so that L’ is not a CFL.
Proof:
we observed that
L= { aibjck| i < j and i < k }
is not context-free. However, although no PDA can test both conditions i < j and i< k
simultaneously, it is easy enough to build two PDAs that test the conditions separately. Inother
words, although the intersection L of the two languages
L1 = {a i bjck | i < j}
and
L2 = {aibjck | i < k}
is not a CFL, both languages themselves are. Another way to verify that L 1 is a CFL is to check it is
generated by the grammar with productions
SABC AaAb|˄ BbB|b CcC|˄
Similarly, L2is generated by the CFG with productions
SAC AaAc|B BbB|˄ CcC|c
The second statement in the theorem follows from the first and the formula
L1∩ L2 =( L1’U L2’)’
If complements of CFLs were always CFLs, then for any CFLs L1 and L2, the language L1’andL2’
would be CFLs, so would their union, and so would its complement. We know now that this is not
the case.
Q.2 Theorem:- If L1 and L2 are context – free languages, then the language L1 U L2,
L1L2 , and L1* are also CFLs.
The proof is constructive: Starting with CFGs
Generating L1 and L2, respectively, we show how to construct a new CFG for each of the three cases.
A grammar Gu = (Vu, Ʃ, Su, Pu) generating L1 U L2. First we rename the element of V2 if
A grammar Gc= (Vc, Ʃ, Sc, Pc) generating L1L2 . Again we relabel variables if necessary so that
V1 n V2 = Ø and define
Vu = V1 U V2 U {Sc}
This time we let
Pc= P1 U P2 U { Sc-> S1S2 }
If x ∈L1L2 then x = x1x2 , where xi ∈Li for each i. we may then derive x in Gc as follows:
Sc =>S1 S2 => *x1 S2 => * x1x2 = x
Where the second step is the derivation of x1 in G1 and the third step is the derivation of x2
in G2. Conversely, if x can be derived from Sc, then since the first step in the derivation must
be Sc=>S1 S2 , x must be derivable from S1 S2. Therefore, x=x1x2, where for each i, xi can be
derived from Si in Gc. Since V1 n V2 = Ø being derivable from Si in Gc means being derivable
from Si in Gi, and so x ∈ L1L2.
V = V1 U {S}
Where S ∈ V1.The language L1 *contain strings of the form x = x1x2 …xk , where each xi ∈ L1 .
Since each xi can be derived from S1 , then to derive x from s it is enough to be able to
derive a string of k S1‘s . We can accomplish this by including the productions
S ->S1S |
In P. Therefore, let
P = P1U { S ->S1S | }
The proof that L1 * ⊆ L(G*) is straightforward. If x ∈ L(G*) , on the other hand, then either x
= or x can be derived from some string of the form S1k in G* . In the second case, since
the only production in G* beginning with S1are those in G1, we may conclude that
x∈ L(G1)k ⊆ L(G1)* .
B B a b # c a B
Finite
control
Finite control
I/P
Tape
000101000….
State
UTM should be able to simulate every Turing machine. Simulation of a Turing will involve:
1. Encoding behavior of a particular TM as a program.
2. Execution of the above program by UTM.
We can assume the UTM as a 3-tape Turing machine.
1. Input is written on the first tape.
2. Moves of the TM is encoded from is written on the second tape.
3. The current state of TM is written on third tape.
Q.3 Explain Church Turing Thesis.
The Turing machine is a general model of computation. Any algorithmic procedure can be
solved by a TM.
Church Turing thesis can be stated as, the assumption that the intuitive notation of
computable function can be identified with partial recursive functions.
Some enhancement to TM made the church-turing thesis acceptable. This enhancement are:
1. Multi-tape
2. Multi-head
3. Infinite taps
4. Non-determinism
Machine that are closer to modern computers in their operation, the various notational
system that can be used to describe computations. In every case model has been shown to
equivalent to the Turing machine.
Since the introduction of TM, no one has suggested an algorithm that can be solved by a
computer but cannot be solved by a TM.
Q.4 Design a TM for Accepting Palindromes for odd and even length. (Most IMP)
b/b,R
a/a,R
∆/∆,R (odd pal)
∆/∆,L
q2 q3
b/b,L
a/∆,R
a/a,L
a/∆,L
∆/∆,R ∆/∆,R
q0 q1 q4 ha
b/∆,R b/∆,L
∆/∆,L
q5 q6 ∆/∆,R
odd pal
a/a,R
b/b,R
hr
∆/∆,R ∆/∆,R
∆/∆,R
b/b,R
a/a,R
∆/∆,R a/a,R
q0 b/b,R a/a,R
q1 q2 q3 ha
b/b,R
Q.6 Q
Design a Turing machine for accepting {anbncn/ n>=0}
1
a,a/R C/C,R
B/B,L
B,B/R b,b/R C,C/L
c,C/L b/b,L
q2
b,B/R q3 q4 a/a,L
a/A,R
A/A,R
∆/∆,R
q0 q1
∆/∆,S
B/B,R ha
q5
C/C,R ∆/∆,S
B/B,R q6
C/C,R
∆/∆,L
∆/∆,R
q7 ha
∆/∆,S
x/x,L
A/A,R
B/B,R
a/a,R b/b,L
b/b,R a/a,L
b/B,R
B/B,L
∆/∆,R a/A,R A/A,L
q0 q1 q2 q3 q4
∆/∆,L b/B,L
B/B,L
a/A,L
A/A,L ∆/∆,S
A/a,L q5 ha
B/b,L
∆/∆,R
∆/∆,S
q6
b/B,R
a/A,R
a/a,R
b/b,R
B/B,R
q7 q8 a/a,R
A/A,R
b/b,R
∆/∆,R
∆/∆,R
B/∆,L A/∆,L
q9
∆/∆,L
a/a,L
b/b,L
6. Bounded Minimalization
For an (n + 1)-place predicate P, the bounded minimalization of P is the function mp : Nn+1→ N
defined by
min {y | 0 ≤ y ≤ k and P(X, y)} if this set is not empty
mp(X, k) =
k+1 otherwise
The symbol μ is often used for the minimalization operator, and we sometimes write
mP(X, k) = 𝜇𝑘 y[P(X, y)]
An important special case is that in which P(X, y) is (f(X, y) = 0), for some f :Nn+ 1→ N. In this case
mp is written mf and referred to as the bounded minimalization of f.
7. Unbounded Minimalization
If P is an (n + 1)-place predicate, the unbounded minimalization of P is the partial function M P : Nn→
N defined by
Mp(X) = min {y | P(X, y) is true}
Mp(X) is undefined at any X ε Nn for which there is no y satisfying P(X, y).
The notation μy[P(X, y)] is also used for Mp(X). In the special case in which P(X, y) = (f(X, y) = 0),
we write Mp = Mf and refer to this function as the unbounded minimalizationof f.
8. μ – Recursive Functions
The set M of μ - recursive, or simply recursive, partial functions is defined as follows.
1. Every initial function is an element of M.
2. Every function obtained from elements of M by composition or primitive recursion is an
element of M.
3. For every n ≥ 0 and every total function f : Nn+1→ N in M, the function Mf : Nn→ N defined
by
Mf(X) = μy[f(X, y) = 0]
is an element of M.
4. No other functions are in the set M.
9. Gödel Number of a sequence of Natural Numbers
For any finite sequence x0, x1, … , xn of natural numbers, the Gödel Number of the sequence is the
number
Gn(x0, x1, … , xn) = 2x03x15x2 … (PrNo(n))xn
Where PrNo(n) is the nth prime.
Q.2 Theorem: Let f: Ʃ1*Ʃ2*. Then f is computable if and only if f is μ-recursive.
Proof:
As above, we denote by g1 and g2 the Godel-numbering function for the two alphabets, and
by g1’ and g2’ their respective left inverse.
Suppose on the hand that f is computable, and let Tf be a TM (whose tape alphabet contains
the symbols of Ʃ1 and Ʃ2) computing f.
We want to show that pf :NN is μ-recursive, it is sufficient to show that pf that a composite
Turing machine can be constructed form three simpler ones: one that takes the initial tape
∆1n and halts with tape ∆ g1’; the TM Tf, which then halts with tape ∆f(g1’(n)); and a third
that calculates the Godel number of this string to yield the result, g2 (f(g1’(n)))=pf(n).
On the other hand, suppose that f is μ-recursive. Then by definition, pf is μ-recursive. Let T
be a TM computing it. From the formula for pf we have
g2’(pf(n))= g2’(g2(f(g1’(n))))
= f(g1’(n))
for any n. applying this formula when n= g1(x), we obtain
f(x)=f(g1’(g1(x)))= g2’(pf(g1(x)))
Just as before, we can now construct a composite TM Tf to perform this computation, and it
follows that f is computable.
Similarly, sx is undefined if T might loop forever on input x; otherwise it is the minimum number of
tape squares that might be used in accepting x, if x 𝜖 L, and the minimum number of tape squares
that might be used before rejecting input x, if all choices of moves cause T to reject x. As in the
deterministic case, for a multitape TM, "number of tape squares" means the maximum over all the
tapes. The nondeterministic space complexity of T is the function s T, where sT (n) is undefined if T
can loop forever on some input of length n, and otherwise s T (n) is the maximum of the numbers sx
for |xl = n
4. Basic Complexity Classes (Most IMP)
For a function f : N → N, we define the following complexity classes.
1. Time(f) is the set of languages that can be recognized by a Turing machine T with τT ≤ f.
2. Space(f) is the set of languages that can be recognized by a Turing machine T with sT ≤ f.
3. NTime(f) is the set of languages that can be accepted by an NTM T with nondeterministic
time complexity function τT ≤ f.
4. NSpace(f) is the set of languages that can be accepted by an NTM T with nondeterministic
space complexity function sT ≤ f.
5. Step-counting Functions
A function f : N → N is a step-counting function if there is a TM T so that for any n and any input
string of length n, T halts in exactly f(n) moves.
P = U Time (Cnk)
c>0,k>=0
NP = UNTime (Cn ) k
c>0,k>=0
NPSpace = U
NSpace (Cnk)
c>0,k>=0
Q.4 What are P, NP, NP-Hard and NP-Complete problem?
P is set of problems that can be solved by a deterministic Turing machine in Polynomial
time.
NP is set of decision problems that can be solved by a Non-deterministic Turing Machine in
Polynomial time. P is subset of NP
A problem is NP-Hard if Every problem R 𝜖 NP are polynomial time reducible to Q then Q is
NP hard problem.
NP-complete problems are the hardest problems in NP set. A decision problem Q is NP-
complete if:
1) Q is in NP
2) Every problem in NP is polynomial time reducible to Q.
Some of NP- complete problems are:
1. Satisfaction Problem (SAT)
2. Travelling Salesman Problem (TSP)
3. Hamiltonian Circuit Problem (HCP)
4. The Vertex Cover Problem (VCP)
5. K- Colourability Problem
6. The Complete Sub graph Problems
Q.5 P and NP completeness
P denotes the class of all deterministic polynomial language problems and NP denotes the
class of all non-deterministic polynomial language problems. Hence P ⊆ NP.
The question of whether P=NP. Holds, the most famous outstanding problem in the
computer science.
Problem which are lie in P are called tractable problem. And Problem which are lie in NP are
called intractable problem.
The relationship between P and NP is given in below fig.
Let L1 and L2 are two problem then problem L1 reduced to L2 if and only if there is a way to
solve L1 by deterministic polynomial time algorithm, using that algorithm solve L2 in
polynomial time.
A NP problem such that, if it is in P, then NP=P, if a problem has a same property then it is
called NP hard. Then the class of NP complete problem is the intersection of NP and NP-hard
classes
M
Halt
W H1
Loop
Step 2:Let us revise the machine H1 as H2 to take M as both inputs and H2 should be able to
determine if M will halt on M as its input. Please note that a machine can be described as a
string over 0 and 1.
M
Halt
H2
Loop
Step 3:Let us construct a new Turing machine H3 that takes output of H2 as input and does the
following :
1. If the output of H2 is “loop” than H3.
2. If the output of H2 is “halt” than H3 will loop forever.
M
Halt Machine H3 loops forever
H2
Loop Machine H halts
3
H3
H3
No
Cook’s theorem
Polynomial reduction form
SAT to X