Updated TOC Material

Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

2014-15 | Sem-VI | Basic Mathematical Objects

160704 – Theory of Computation

Q.1 Define the following terms.


1 Complement
A complement of a set A is the set A’ of everything that is not an element of A. This makes sense
only in the context of some “Universal Set” U containing all the elements
For Eg. :- A’ = { x 𝜖 U | x ∉ A }
2 Set Difference
Considering two sets A and B. The difference A – B is the set of everything in A but not in B.
For Eg. :- A – B = { x | x 𝜖 A and x ∉ B }
3 Symmetric Difference
For the two set A and B the symmetric difference can be given as the A ⨁ B
For Eg. :- A ⨁ B = (A – B) ⋃ (B - A)
4 Preposition
A preposition is a declarative statement that is sufficiently objective, meaningful and precise to have
a truth value.
For Eg. :- Fourteen is an even integer
5 Conjuction
The conjuction p ∧ 𝑞 of p and q is read as “ p and q”
It is denoted by ∧
P Q P∧Q
T T T
T F F
F T F
F F F
6 Disjuction
The disjunction p ∨ q of p and q is read as “p or q”
It is denoted by ∨
P Q P∨Q
T T T
T F T
F T T
F F F
7 Negation
The negation ¬p of p is read as the “not p”.
It is denoted by ¬

p Q ¬p
T - F
F - T

Dixita Kagathara Page 1


Basic Mathematical Objects 160704 – Theory of Computation

8 Conditional ( if_ _ _ then)


The proposition p → q is commonly read as “if p then q”
For Eg.:-
P Q P →Q
T T T
T F F
F T T
F F T
9 Logical equivalence
if P and Q have exactly the same truth values in each case we say P and Q are logically equivalence.
For Eg.:- p ↔q
10 Logical Implication
If q is true in each case in which the p is true then we say p logically implices
For Eg.:- P => Q
11 Existential Qualifier:-
For the proposition x2 < 4 we consider that “there exist an x “ such that the phrase “ there exist “ is
called the Existential Qualifier.
For Eg.:- ∃ x (x2 < 4)
12 Universal Quantifier
In the proposition x2< 4 considering the phrase “for every x, x2< 4” then the phrase “for
everything” is called the Universal Quantifier.
For Eg.:- ∀x (x2 < 4)
13 Onto function / Surjective / Surjection
For the function f : A →B, if f(A) = B (the range and codomain of f are equal and every element of
the codomain is actually one of the values of the functions), the function f is said to be a onto
function.
14 One-to-One Function / Injective / Injection
Again assuming that f : A →B, we say f is one-to-one if no single element y of B can be f(x) for more
than one x in A.
15 Bijection Function
For the function f : A →B, f is bijection if f is one-to-one as well onto function
16 Composite function
Suppose we have function f : A → B and g : B → C. the function h : A → C defined by h(x) = g
(f(x)) is called the composite of g and f
For Eg.:- h = gof
17 Inverse Function
For f: A → B, then for any y 𝜖B there is at least one x 𝜖 A with f(x) = y and f is onto function and for
any y 𝜖 B there is at most one x 𝜖A with f(x) = y where f is one-to-one.
Therefore for any y 𝜖B it makes sense to speak of the element x 𝜖 A for whichf(x = y)
-1
We denote it x by f (y). For Eg.:- f : A → B f -1 : B → A
18 Relation Function
A relation R on a set A is a subset of A × A

Dixita Kagathara Page 2


Basic Mathematical Objects 160704 – Theory of Computation

For Eg.:- x < y R = { (4,7) , (1,2) }


19 Equivalence Relations
Assume that R is a relation on a set A; in other words, R⊆ A × A
Then
1. R is reflexive if for every a ∈ A, aRa.
2. R is symmetric if for every a and b in A if aRb then bRa
3. R is transitive if for every a, b and c in A if aRb and bRc then aRc.
4. R is equivalence on A if R is reflective, symmetric and transitive
20 Transitive closure of a Relation
Let R be a relation on a set A. R may or may not have some property P. property P, such as
reflexivity, symmetry, or transitivity. If there is a relation S with property P containing R such that S
is a subset of every relation with property P containing R, then S is called the closure of R with
respect to P
21 Tautology
If all the entries of the truth table for any compound proposition are truth then the proposition is
termed as tautology.
For Eg.:- P ⇔ Q is a tautology proposition
Q.2 In the given relation determine the properties(reflexivity, symmetry
,transitivity), which ones the relation has: R = {(1,1),(2,2),(3,3),(1,2)} and R=ϕ
1. R = {(1,1),(2,2),(3,3),(1,2)}
Above relation is Reflexive, not Symmetry ,Transitive
2. R=ϕ
Above relation is not Reflexive, but Symmetry & Transitive
3. R={(1,1),(2,2),(2,3),(3,2),(4,2),(4,4)}
Above relation is not reflexive, not Symmetry and not Transitive
Q.3 Prove that associative law holds true for symmetric difference.
The symmetric difference for 3 variables A, B and C can be given as,
A ⨁ (B ⨁ C) = ( A⨁ B ) ⨁ C.
We have to prove the above statement.
A⨁(B⨁C)=A⨁[(B–C)∪(C–B)]
=[(A–B–C)∪(C–B–A)] → [1]
(A⨁B)⨁ C=[(A–B)∪(B–A)⨁ C
=[(A–B–C)∪(C–B–A)] → [2]
From the equation [1] and [2],
LHS = RHS
A⨁(B ⨁C)=(A ⨁B)⨁C
Hence proved

A C
=
B C A B

Dixita Kagathara Page 3


Basic Mathematical Objects 160704 – Theory of Computation

Q.4 Give quantified statement saying that p is prime.


 Let us consider that statement “P is prime” involving the free variable p over the universe N of
natural number.
 We take our definition of a prime number, a number greater than 1 whose only divisor are itself
and 1.
 The first statement is now to express the fact that one number is a divisor of another.
 The statement “k is a divisor of p” means that p is a multiple of k or that there is an integer m
with
P=m*k
 Next saying that the only divisors of p are p and 1 is the same as saying that every divisor of p
is either p or 1.
 Adapting the statement that “for every k, if k is a divisor of p, then k is either p or 1”.
 Considering all these together we get that “p is prime”.
{ ( P > 1 ) ∧ ∀ k (∃m ( p = m * k ) )→ (k = 1) ∨ (k = p ) }
Q.5 Prove that f: R → R, f(x) = x2 is not one-to-one and not onto function
The range and codomain of f(x) = x2 are not equal or every element of codomain is not actually one
of the function. So function f is not onto function.
The function is not one to one because f(-1) = f(1) =1.
Q.6 Prove that f: R → R+, f(x) = x2 is not one-to-one and onto function
The range and codomain of f(x) = x2 are equal or every element of codomain is actually one of the
function. So function f is onto function.
The function is not one to one because f(-1) = f(1) =1.
Q.7 Prove that f: R+ → R, f(x) = x2 is one-to-one and not onto function
The range and codomain of f(x) = x2 are not equal or every element of codomain is not actually one
of the function. So function f is not onto function.
Given function is one to one because no single element of codomain can be f(x) for more than one
element in domain.
Q.8 Prove that f: R+ → R+, f(x) = x2 is one-to-one and onto function(bijection).
f: R+ → R+,f(x) = x2
The range and codomain of f(x) = x2 are equal or every element of codomain is actually one of the
values of the function. So, function f is onto function
There is no single y = x2 of domain R+ can be f(x) for more than one x in range R+.So, it is one-to-
one function.
The function f(x) = x2 is onto function as well as one-to-one function. So, it is called as bijection
function.
Q.9 Show that for any language L, L*=(L*)*=(L+)*=(L*)+
For any language L, we have L⊆ L+⊆ L*. We obtain L*⊆(L+)*⊆(L*)*. We also have L*⊆(L*)+⊆(L*)*.
Therefore in order to show that all four languages are equal, it is sufficient to show that (L*)* ⊆L*,
but an element of (L*)* is formed by concatenating zero or more element of L*, each of which is the
concatenation of zero or more element of L. the result is concatenation of zero or more element of
L.

Dixita Kagathara Page 4


2014-15 | Sem-VI |Mathematical Induction & Recursive Definition

160704 – Theory of Computation

Q.1 What is Proof?


 A proof of a statement is essentially just a convincing argument that the statement is true.
 There are several methods for establishing a proof, some of them are
1. Direct Proof
2. By Contradiction
3. By Mathematical Induction
Q.2 For any integers a and b, if a and b are odd, then ab is odd.
Proof:
 We start by saying more precisely what our assumption means. An integer n is odd if there
exists an integer x so that n=2x+1.
 Now let a and b be any odd integers. Then according to this definition, there is an integer x
so that a=2x+1, and there is an integer y so that b=2y+1.
 We wish to show that there is an integer z so that ab=2z+1. Let us therefore calculate ab:
=(2x+1)(2y+1)
=4xy+2x+2y+1
=2(2xy+x+y)+1
 Since we have shown that is a z. namely, 2xy+x+y, so that ab=2z+1, the proof is
complete.
 since the statement we proved is the quantified statement “for any integer a and b ….,”
 Example:
X=45 & y= 11
xy= 2(2xy+x+y)+1
= 2(2(45)(11)+45+11)+1
= 2(1046)+1
xy=2093
hence prove
Q.3 To Prove: For every three positive integers i, j, and n, if i*j = n, then i ≤ or j

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

integer i, j, and n, if it is not the case that i ≤ or j ≤ , then i*j≠n.

 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

Dixita Kagathara Page 1


Mathematical Induction & Recursive Definition 160704 – Theory of Computation

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

Dixita Kagathara Page 2


Mathematical Induction & Recursive Definition 160704 – Theory of Computation

𝑘 𝑘+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.

Dixita Kagathara Page 3


Mathematical Induction & Recursive Definition 160704 – Theory of Computation

0 0
P(0) =
0+1
=1=0
1 1
=0 =0
𝑖 𝑖+1 0+1

And, this is obviously true.


Step-2:Induction Hypothesis
k >= 0 and
1 1 1 1 1 𝑘
p(k)= + + + +⋯+ =
2 6 12 20 𝑘 𝑘+1 𝑘+1
Step-3:Proof of Induction
1 1 1 1 1 1
p(k+1) = + + + + ⋯+ +
2 6 12 20 k k+1 k+1 k+1+1
1 1 1 1 1 1
= + + + + ⋯+ +
2 6 12 20 k k+1 k+1 k+2

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 2 + k + k + 1)/(k + 1)(k + 2)


=(k 2 + 2k + 1)/(k + 1)(k + 2)
k+1 k+1
=
k+1 k+2
k+1
=
k+2
k+1
=
k+1 +1
Hence proved.
Q.9 Prove 7+ 13+19+…..+(6n+1)= n(3n+4)
Step-1:Basic
We must show that p(0) is true.
P(0)= 0(3(0)+4)=0
And, this is obviously true.
Step-2:Induction Hypothesis
k >= 0 and
p(k) = 7+13+19+…..+(6k+1)=k(3k+4)
Step-3:Proof of Induction
P(k+1) = 7+13+19+…..+(6k+1)+(6(k+1)+1)
= k(3k+4)+(6(k+1)+1)

Dixita Kagathara Page 4


Mathematical Induction & Recursive Definition 160704 – Theory of Computation

= 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.

Dixita Kagathara Page 5


Mathematical Induction & Recursive Definition 160704 – Theory of Computation

Q.12 Prove that 2n>n3 where n>=10,Using Principle of Mathematical Induction.


Step-1:Basic step
We must show that p(10) is true.
210=1024 and 103=1000
So,1024>1000
And, this is obviously true.
Step-2:Induction Hypothesis
For k>=10
P(k)= 2k>k3
Statement to be shown in Induction step is,
P(k+1)=2k+1>(k+1)3
Step-3:Proof of Induction
2k+1>(k+1)3
Where, 2k+1=(2k )(2)>2k (1.331)
𝟏
>2k (1+ )3
𝟏𝟎
𝟏
>2k(1+ )3 for k>=10
𝒌
𝒌+𝟏 3
>( ) (2k)
𝒌
𝒌+𝟏 3
>( ) (k3) ,because 2k>k3
𝒌

(2k )(2)>(k+1)3
2k+1>(k+1)3 ;k>=10
Hence proved.

Q.13 Prove n(n2+5) is divisible by 6 for n>=0, Using Principle of Mathematical


Induction.
Step-1:Basic step
We must show that p(0) is true.
P(0)=0(02+5)=0*6/6=0
And, this is obviously true.
Step-2:Induction Hypothesis
For k>=0 and
P(k)=k(k2+5) is divisible by 6.
Statement to be shown in Induction step is,
P(k+1)=(k+1)[(k+1)2+5] is divisible by 6.
Step-3:Proof of Induction
(k+1)[(k+1)2+5]
=k[(k+1)2+5]+1[(k+1)2+5]
=k(k2+2k+1+5)+(k2+2k+1+5)
=k3+2k2+k+5k+(k2+2k+6)
=k(k2+5)+k(2k+1)+(k2+2k+6)
= k(k2+5)+2k2+k+k2+2k+6
= k(k2+5)+3k2+3k+6

Dixita Kagathara Page 6


Mathematical Induction & Recursive Definition 160704 – Theory of Computation

= 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.

Dixita Kagathara Page 7


2014-15 | Sem-VI | Regular Language & Finite Automata

160704 – Theory of Computation

Q.1 Regular language & Regular Expression.


Regular Language :-
A Regular Language over an alphabet ∑ is one that can be obtained from these basic language using
the operation of Union, Concatenation and Kleene (*).
Regular Expression :-
 Regular Language can be described by an explicit formula.
 It is common to simplify the formula slightly by leaving out the set brackets {} or replacing
them with parenthesis () and replace U by +. The result is called Regular Expression.
Language Regular Expression
1. {^} ^
2. {0} 0
3. {001} 001
4. {0,1} 0+1
5. {0,10} 0+10
6. {1,0}110 (1+0)110
7. {110}*{0,1} (110)*(0+1)
8. {1}*{10} (1)*(10)
9. {10,111,11010}* (10+111+11010)*
10. {0,10}*({11}*U{001,^}) (0+10)*((11)*+(001+^))
More Examples of regular Expression
1. 0 or 1
0+1
2. 0 or 11 or 111
0+11+111
3. Regular expression over ∑={a,b,c} that represent all string of length 3.
(a+b+c)(a+b+c)(a+b+c)
4. String having zero or more a.
a*
5. String having one or more a.
a+
6. All binary string.
(0+1)*
7. 0 or more occurrence of either a or b or both
(a+b)*
8. 1 or more occurrence of either a or b or both
(a+b)+
9. Binary no. end with 0
(0+1)*0
10. Binary no. end with 1

Dixita Kagathara Page 1


Regular Lang. & Finite Automata 160704 – Theory of Computation

(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))*

Dixita Kagathara Page 2


Regular Lang. & Finite Automata 160704 – Theory of Computation

31. String start with 1 and has even length.


1(0+1)((0+1)(0+1))*
32. Even no of 1
(0*10*10*)*
33. String of length 6 or less
(0+1+^)6
34. String ending with 1 and not contain 00.
(1+01)+
35. All string begins or ends with 00 or 11.
(00+11)(0+1)*+(0+1)*(00+11)
36. Language of all string containing both 11 and 00 as substring.
((0+1)*00(0+1)*11(0+1)*)+ ((0+1)*11(0+1)*00(0+1)*)
37. Language of C identifier.
(_+L)(_+L+D)*
38. The set of all string not congaing 101 as a substring.
0*(1+000*)*0*
39. Give the language for (1+01)*(0+10)*
Above language not containing string 00x11
Q.2 Definition of Finite Automata
A finite Automata or finite state machine is a 5-tuple(Q,∑.q0,A,δ) where
Q is finite set
∑ is finite alphabet of input symbol
q0 ∈ Q (Initial state)
A (set of accepting states)
δ is a function from Q×∑ to Q(Transition function)
For any element q of Q and any symbol a ∈ ∑, we interpret δ(q,a) as the state to which the Finite
Automata moves, if it is in state q and receive the input a.
Application of finite automata
Finite automata are used to solving several common types of computer algorithm. Some of them are:
1. Design of digital circuit
2. String matching
3. Communication protocols for information exchange.
4. Lexical analysis phase of a compiler.

Q.3 The Extended transition function δ* for FA


Let M=(Q,∑,q0,A,δ) be an Finite Automata. We define the function δ*:Q×∑*Q as follow.
1) For any q ∈ Q, δ*(q,^)=q
2) For any q ∈ Q, y ∈ ∑*, and a ∈ ∑
δ*(q,ya)= δ(δ*(q,y),a)
Example:

Dixita Kagathara Page 3


Regular Lang. & Finite Automata 160704 – Theory of Computation

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

Q.4 Acceptance by an Finite Automata


Let M= (Q1, ∑, q0, A, δ) be a Finite Automata. a string x ∈ ∑* is accepted by M if δ*(q0,x) ∈ A. if string
is not accepted, we say it is rejected by M. the language accepted by M, or the language recognized by
M, is the set L(M)={x ∈ ∑*/x is accepted by M} If L is any Language over ∑, L is accepted or
recognized by M if and only if L=L(M).
Q.5 Draw Finite Automata for following
The string with next to last symbol as 0.

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

Dixita Kagathara Page 4


Regular Lang. & Finite Automata 160704 – Theory of Computation

The string ending in 10 or 11.

0 C
1
1 0
A B
0
1 D
0

The string corresponding to Regular expression {00}*{11}*

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

Q.6 Finding a Regular Language corresponding to an Finite Automata

0,1
1
0 D
0
0 0 0
1
A 1
1 B
1
(00)*(11)*

Dixita Kagathara Page 5


Regular Lang. & Finite Automata 160704 – Theory of Computation

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

Sring containing either ab or bba

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

Dixita Kagathara Page 6


Regular Lang. & Finite Automata 160704 – Theory of Computation

Q.9 Define Dead end state.


Dead state are those non accepting states whose transitions for every input symbols terminate on
themselves.

0.1 0,1 0,1 0,1


q1 q2 q3 q4
q0

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

Dixita Kagathara Page 7


Regular Lang. & Finite Automata 160704 – Theory of Computation

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))


= BQ
δ((A,P),1) = (δ(A,1), δ(P,1))
= AP
δ((B,Q),0) = (δ(B,0), δ(Q,0))
= CQ
δ((B,Q),1) = (δ(B,1), δ(Q,1))
= AR
δ((C,Q),0) = (δ(C,0), δ(Q,0))
= CQ
δ((C,Q),1) = (δ(C,1), δ(Q,1))
= CR
δ((A,R),0) = (δ(A,0), δ(R,0))
= BQ
δ((A,R),1) = (δ(A,1), δ(R,1))
= AP
δ((C,R),0) = (δ(C,0), δ(R,0))
= CQ
δ((C,R),1) = (δ(C,1), δ(R,1))
= CP
δ((C,P),0) = (δ(C,0), δ(P,0))
= CQ
δ((C,P),1) = (δ(C,1), δ(P,1))
= CP

1 1

AP BP CP
0 1
0
AQ BQ 0 CQ
1 0
1
0
AR 1 BR CR

Dixita Kagathara Page 8


Regular Lang. & Finite Automata 160704 – Theory of Computation

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

Q.12 Draw Finite Automata for following language


L1={x/x 11 is not substring of x, x ∈ {0,1}*}
L2={x/x ends with 10, x ∈ {0,1}*}
Draw finite Automata for L1∩ L2 and L1-L2.
(Most IMP)
M1

0 1 0,1

A B 1 C
0

M2

Dixita Kagathara Page 9


Regular Lang. & Finite Automata 160704 – Theory of Computation

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

Dixita Kagathara Page 10


Regular Lang. & Finite Automata 160704 – Theory of Computation

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

Q.13 Draw the Finite Automata recognizing the following language


 L1 ∩ L2s
 L1 - L2
L1

1
0,1

A 0 B 0 C

1
L2

Dixita Kagathara Page 11


Regular Lang. & Finite Automata 160704 – Theory of Computation

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

Dixita Kagathara Page 12


2014-15 | Sem-VI | Nondeterminism & Kleene’s Theorem

160704 – Theory of Computation

Q.1 Definition: Nondeterministic Finite Autometa

A nondeterministic finite automaton (NFA) is a 5-tuple (Q,Ʃ, q0,A, δ),Where Q and Ʃ are nonempty

finite sets, q0 ∈Q, A ⊆Q,and δ : Q × Ʃ2Q

Q is a finite set of states;

Ʃ is a finite input alphabet;


q0 ∈Q is the initial state;
A ⊆ Q is the set of accepting states;

δ :Q × (Ʃ∪ {Λ}) →2Qis the transition function.

Q.2 Definition :Nonrecursive Definition of δ* for an NFA

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}.

2) For any q ∈ Q, y ∈Ʃ*, and a ∈Ʃ,

δ*(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 Ø Ø

Dixita Kagathara Page 1


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

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};

δ*( q0,11) = U δ( r,1)


r∈δ*{ q0,1}

= U δ( r,1)
r∈{ q0, q1}

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

δ*( q0,01) = U δ( r,1)


r∈δ*( q0,0)

= U δ( r,1)
r∈( q0)

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

δ*( q0,111) = U δ( r,1)


r∈δ*( q0,11)

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


= {q0, q1, q2, q3}

δ*( q0,011) = U δ( r,1)


r∈δ*( q0,01)

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

Dixita Kagathara Page 2


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

Q.6 Definition: A Nondeterministic Finite Automaton with Λ - Transition.

A nondeterministic finite automata with Λ - Transition is a 5-tuple (Q,Ʃ, q0,A, δ), where Q and Ʃ are

finite sets, q0∈ Q, A ⊆Q, and δ : Q × (Ʃ∪ { Λ }) →2Q

Q.7 Definition: Nondeterministic Definition of δ* for an NFA- Λ


For an NFA- ΛM= (Q,Ʃ, q0,A, δ), states p,q∈ Q, and a string x = a1a2….an ∈Ʃ*, we will say M moves

from p to q by a sequence of transition corresponding to x if there exist an integer m ≥ n, a

sequence b1b2….bm ∈Ʃ∪ { Λ}satisfying b1b2….bm=x, and a sequence of states p= p0, p1… pm=q so

that for each I with 1 ≤ I ≤ m, pi ∈( pi-1 , bi ).

For x ∈Ʃ* and p ∈δ*( p,x) is the set of all states q ∈ Q such that there is a sequence of

transition corresponding to x by which M moves from p to q.


Q.8 Definition:Λ- Closure of a Set of States

Let M=(Q,Ʃ, q0,A, δ), be an NFA – Λ, and let S ne any subset of Q. The Λ- closure of S is the set

Λ(s) defined as follows.


1) every element of S is an element of Λ(s);
2) For any q ∈Λ(s), every element of δ(q, Λ) is in Λ(s).
3) No other elements of Q are in Λ(s).
Q.9 Definition: Recursive Definition of δ* for an NFA- Λ
Let M=(Q, Ʃ, q0,A, δ), be an NFA – Λ, the extended transition function δ*: Q × Ʃ*→2Q is defined as

follows.
1) For any q ∈ Q, δ(q, Λ)= Λ({q}).

2) For any q ∈ Q, y∈Ʃ*, and a∈ Λ,

δ*(q,ya)= Λ( U δ(r,a))
r∈ δ*(q,y)

A string x is accepted by M if δ*(q0,x)n A ≠ Ø. The language recognized by M is the set L(M) of


all strings accepted by M.
Q.10 Compare FA, NFA and NFA-^.
Parameter NFA FA NFA-^
Transition Non deterministic Deterministic Non deterministic
No. of states NFA has a fewer More, if NFA contains It allows transition on
number of states. Q states then the no input.
corresponding FA will
have <=2Q states.
Power NFA is as powerful as FA is powerful as an It’s powerful as FA
DFA NFA
Design Easy to design due to More difficult to Allow flexibility in
non-determinism design handling NFA
problem.
Acceptance It is difficult to find It is easy to find ^-transition is useful

Dixita Kagathara Page 3


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

whether w € L as whether w € L as in constructing a


there are several transition are composite FA with
paths. deterministic. respect to union,
Backtracking is concatenation, star.
required to explore
several parallel paths.
Q.11 Applying Definition of ^(S) and δ*

0 1
P 1 0 S
r
^ ^

^ W
q0

^ ^
0 0
t u v
1
0

δ*(q0,^) = ^({q0})
= { q0,p,t}

δ*(q0,0) =^( U δ(p,0))


r∈δ*( q0,^)
= ^ (δ(q0,0)U δ(p,0)U δ(t,0))
= ^ (ØU{p}U{u})
= ^ ({p,u})
= {p,u}

δ*(q0,01) =^( U δ(p,1))


r∈δ*( q0,0)
= ^ (δ(p,1)U δ(u,1))
= ^ ({r})
= {r}

δ*(q0,010) =^( U δ(p,0))


r∈δ*( q0,01)
= ^ (δ(r,0)
= ^({s})
= {s,w,q0,p,t}

Dixita Kagathara Page 4


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

Q.12 Convert following NFA to FA.

2
a b

b 4
1

a a
3

q δ(q,a) δ(q,b)
1 {2,3} {4}
2 {Ø} {4}
3 {4} {3}
4 {Ø} {Ø}

δ*( 1,a) = {2,3}


δ*( 1,b) = {4}
δ*({2,3},a) = δ(2,a) U δ(3,a)
= {4}
δ*({2,3},b) = δ(2,b) U δ(3,b)
= {3,4}
δ*(4,a) = {Ø}
δ*(4,b) = {Ø}
δ*({3,4},a) = δ(3,a) U δ(4,a)
= {4}
δ*({3,4},b) = δ(3,b) U δ(4,b)
= {3}
δ*(3,a) = {4}
δ*(3,b) = {3}

a b 3,4
1 2,3

b a a
b

4 3
a

Dixita Kagathara Page 5


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

Q.13 Convert NFA - ^ to FA


q δ (q,^) δ (q,0) δ(q,1)
A {B} {A} Ø
B {D} {C} Ø
C Ø Ø {B}
D Ø {D} Ø

C
0 1 0
0
^ ^
A B D

δ*(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,D}
={A,B,C,D}
δ*(A,1) =^( U δ(r,1))
r∈δ*( A,^)
=^( U δ(r,1))
r∈δ(A,B,D)
= ^(δ(A,1)U δ(B,1)U δ(D,1))

δ*(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,˄)

Dixita Kagathara Page 6


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

=^( 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

Dixita Kagathara Page 7


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

δ({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

Q.14 Convert NFA - ^ to FA

q δ (q,^) δ (q,0) δ(q,1)


A {B,D} {A} Ø
B Ø {C} {E}
C Ø Ø {B}
D Ø {E} {D}
E Ø Ø Ø

Dixita Kagathara Page 8


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

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}

δ*(A,1) =^( U δ(r,1))


r∈δ*( A,^)
=^( U δ(r,1))
r∈δ(A,B,D)
= ^(δ(A,1)U δ(B,1)U δ(D,1))
= ^(E,D)
= {ED}

δ*(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))

Dixita Kagathara Page 9


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

=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) =Ø

Dixita Kagathara Page 10


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

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}

Dixita Kagathara Page 11


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

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

Q.15 Kleene’s Theorem Part-1 or


Prove: Any Regular Language can be accepted by a finite automata.
Any regular language can be accepted by finite Automata
Proof:
 On the basis of statement L can be recognized by FA,NFA and NFA-^ transition .It I
sufficient to so that every regular language can be accepted by NFA- ^.
 Set of regular language over alphabet δ identified to obtain the basic language.
Ø,{^},and {a}(a ∈ ^) to be closed under operation of union, concatenation, and Kleene*.
 This allows us to prove using structural induction that every regular language over Ʃ can be
accepted by an NFA-^.
 The basis step of the proof is to show that the three basic languages can be accepted by
NFA-^s.
 The induction Hypothesis is that L1 and L2 are language that can be accepted by NFA-^s,
and the induction step is to show that L1 U L2, L1L2, and L1* can also be.
 NFA-^ for the three basic languages is shown below.

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)

Dixita Kagathara Page 12


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

 By renaming state if necessary, we may assume that Q1 ∩ Q2 = Ø. we will construct NFA-


^s Mu, Mc, and Mk, recognizing the language L1 U L2, L1L2, and L1*, respectively
Construction Of Mu

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 ε-

Dixita Kagathara Page 13


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

transition from each state in A1 to q2.


 In other words, for any q not in A1, and α ∈ ε U {^},δc(q,α) is defined to be either δ1(q,α)
or δ2(q,α), depending on whether q is in Q1 and Q2, for q ∈ A1.
δc(q,α)= δ1(q,α) for every a ∈ ε, and δc(q,˄)= δ1(q,˄)U{q2}
 On an input string x1x2, where xi ∈ Li for both value of I, Mc can process x1, arriving at a
state A1; jump from this state to q2 by a ˄-transition; and then process x2 the way M2
would, so that x1x2 is accepted. Conversely, if x is accepted by M c, there is a sequence of
transition corresponding to x that begins at q1 and ends at an element of A2. one of them
must therefore be from an element of Q1 to an element Q2, and according to the definition
of δc, this can only be a ˄- transition form an element of A1 to q2. Because Q1 ∩ Q2= Ø, all
the previous transition are between elements of Q1 and all the subsequent ones are
between elements of Q2. it follows that x=x1˄x2=x1x2, where x1 is accepted by M1 and
x2 is accepted by M2; in other words, x ∈ L1L2.
Construction Of Mk

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*.

Dixita Kagathara Page 14


Nondeterminism & Kleen’s Theorem 160704 – Theory of Computation

 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)*

Dixita Kagathara Page 15


2014-15 | Sem-VI | Regular & Non Regular Language

160704 – Theory of Computation

Q.1 Explain procedure to minimize Finite Automata


S-1 : Make final state and non-final state as distinguish.
S-2 : Recursively interacting over the pairs of state for any transition for
δ(p,x) = r
δ(q,x) = s
and for x ∈ ε. If r and s are distinguishable make p and q as distinguish.
S-3 : If any iteration over all possible state pairs one fails to find a new pair of states that are
distinguishable terminate.
S-4: All the states that are not distinguished are equivalence.

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

Dixita Kagathara Page 1


Regular & Non regular Language 160704 – Theory of Computation

pair(1,2) is not distinguish


Consider pair (1,3)
δ(1,a)=3 δ(1,b)=2
δ(3,a)=5 δ(3,b)=4
pair (5,3) is distinguish, so (1,3) is distinguish.
Consider pair (1,4)
δ(1,a)=3 δ(1,b)=2
δ(4,a)=4 δ(4,b)=4
Consider pair (2,3)
δ(2,a)=4 δ(2,b)=1
δ(3,a)=5 δ(3,b)=4
pair (5,4) is distinguish, so (2,3) is distinguish.
Consider pair (2,4)
δ(2,a)=4 δ(2,b)=1
δ(4,a)=4 δ(4,b)=4
Consider pair (3,4)
δ(3,a)=5 δ(3,b)=4
δ(4,a)=4 δ(4,b)=4
pair (5,4) is distinguish, so (3,4) is distinguish.

b a
3

1,2,4 b a
a

b 5

Q.3 Minimize the following DFA (If Possible)


a

2 b
a b

a 5
1
a

b a b
3 4
b a

Dixita Kagathara Page 2


Regular & Non regular Language 160704 – Theory of Computation

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

Consider pair (1,4)


δ(1,a)=2 δ(1,b)=3
δ(4,a)=3 δ(4,b)=5
pair (3,5) is distinguish, so (1,4) is distinguish.
Consider pair (2,3)
δ(2,a)=3 δ(2,b)=5
δ(3,a)=4 δ(3,b)=3
pair (5,3) is distinguish, so (2,3) is distinguish.
Consider pair (2,4)
δ(2,a)=3 δ(2,b)=5
δ(4,a)=3 δ(4,b)=5
Consider pair (3,4)
δ(3,a)=4 δ(3,b)=3
δ(4,a)=3 δ(4,b)=5
pair (3,5) is distinguish, so (3,4) is distinguish.

b
b
a
b
1,3 2,4 5

a a

Dixita Kagathara Page 3


Regular & Non regular Language 160704 – Theory of Computation

Q.4 For following FA find minimum FA accepting same language.

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

Final state is {2,6}


And, Non-Final state is {1,3,4,5,7}
(2, 1), (2, 3), (2, 4), (2, 5), (2, 7), (6, 1), (6, 3), (6, 4), (6, 5), (6, 7) are distinguish pairs.
Consider pair (1,3)
δ(1,a)=2 δ(1,b)=3
δ(3,a)=6 δ(3,b)=7
Consider pair (1,4)
δ(1,a)=2 δ(1,b)=3
δ(4,a)=4 δ(4,b)=5
pair (2,4) is distinguish, so (1,4) is distinguish.
Consider pair (1,5)
δ(1,a)=2 δ(1,b)=3
δ(5,a)=6 δ(5,b)=7
Consider pair (1,7)
δ(1,a)=2 δ(1,b)=3
δ(7,a)=6 δ(7,b)=7

Dixita Kagathara Page 4


Regular & Non regular Language 160704 – Theory of Computation

Consider pair (2,6)


δ(2,a)=4 δ(2,b)=5
δ(6,a)=4 δ(6,b)=5
Consider pair (3,4)
δ(3,a)=6 δ(3,b)=7
δ(4,a)=4 δ(4,b)=5
pair (6,4) is distinguish, so (3,4) is distinguish.
Consider pair (3,5)
δ(3,a)=6 δ(3,b)=7
δ(5,a)=6 δ(5,b)=7
Consider pair (3,7)
δ(3,a)=6 δ(3,b)=7
δ(7,a)=6 δ(7,b)=7
Consider pair (4,5)
δ(4,a)=4 δ(4,b)=5
δ(5,a)=6 δ(5,b)=7
pair (6,4) is distinguish, so (4,5) is distinguish.
Consider pair (4,7)
δ(4,a)=4 δ(4,b)=5
δ(7,a)=6 δ(7,b)=7
pair (6,4) is distinguish, so (4,7) is distinguish.
Consider pair (5,7)
δ(5,a)=6 δ(5,b)=7
δ(7,a)=6 δ(7,b)=7

a
b
a
b a
1,3,5,7 4 2,6

Q.5 Find the minimized FA for following (if possible)

2 ×
3 × ×
4 × × ×
5 × × × ×
6 × × × × ×
1 2 3 4 5

Dixita Kagathara Page 5


Regular & Non regular Language 160704 – Theory of Computation

3
b b
a

b b

a a a a
1 2 4 5 6
b
a

Final states are {2,5}


And, non final states are {1,3,4,6} so,
(2,1), (2,3), (2,4), (2,6), (5,1), (5,3), (5,4),(5,6) are distinguish pairs.

Consider pair (1,3)


δ(1,a)=2 δ(1,b)=1
δ(3,a)=2 δ(3,b)=5
pair (1,5) is distinguish, so pair (1,3) is distinguish.

Consider pair (1,4)


δ(1,a)=2 δ(1,b)=1
δ(4,a)=6 δ(4,b)=3
pair (1,3) is distinguish, so pair (1,4) is distinguish.

Consider pair (1,6)


δ(1,a)=2 δ(1,b)=1
δ(6,a)=5 δ(6,b)=2
pair (2,5) is distinguish, so pair (1,5) is distinguish.

Consider pair (3,4)


δ(3,a)=2 δ(3,b)=5
δ(4,a)=6 δ(4,b)=3
pair (2,6) is distinguish, so pair (3,4) is distinguish.

Consider pair (3,6)


δ(3,a)=2 δ(3,b)=5
δ(6,a)=5 δ(6,b)=2
pair (2,5) is distinguish, so pair (3,6) is distinguish.

Dixita Kagathara Page 6


Regular & Non regular Language 160704 – Theory of Computation

Consider pair (4,6)


δ(4,a)=6 δ(4,b)=3
δ(6,a)=5 δ(6,b)=2
pairs (5,6) and (2,3) is distinguish, so pair (4,6) is distinguish.
Here, no states are equivalent, so, minimization is not possible.
Q.6 Define pumping lemma and its application.
Suppose L is a regular language. Then there is an integer n so that for any x€ L with |x|>=n,
there are strings u, v, and w so that
1. x=uvw
2. |uv|<=n
3. |v|>0
4. For any m>=0, uvmw € L

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.

Dixita Kagathara Page 7


2014-15 | Sem-VI | Context-Free Grammars

160704 – Theory of Computation

Q.1 Define: Context Free Grammar


A context free grammar is a 4-tuple G=(V,Ʃ,S,P) where
V &Ʃ are disjoint finite set
S is an element of V and
P is a finite set formulas of the form Aα where A ∈ V and α∈(vUƩ)*
V Nonterminal
Ʃterminal
Sstart symbol
pproduction rule
Application of Context Free Grammar(CFG):
1) CFG are extensively used to specify the syntax of programming language.
2) CFG is used to develop parser
Q.2 Define: Context Free Language
Language generated by CFG is called context free language
Let G= (V, Ʃ, S, P) be a CFG. The Language generated by G is
L(G):{x∈Ʃ*/S⟹G* x}
A language L is a context free Language(CFL) if there is a CFG G so that L=L(G)
Q.3 Give Recursive Definition for following CFG.
1. Recursive Definition of Palindrome (pal)
 ˄,a,b∈ pal
 for any S ∈ pal , aSa∈ pal and bSb∈ pal
 no other string are in pal
we can describe pal by the context-free grammar with the grammar rules,
S˄/a/b/aSa/bSb
2. The language {anbn / n≥0}
 ˄∈ L
 for every x ∈ L, axb∈L
 nothing else in L
we can describe above language with the following grammar rules
S˄/aSb
3. Set of positive integers divisible by 5.
 1∈ S, 2∈ S, 3∈ S, 4∈ S.
 If x ∈ S then x+5 ∈ S.
 Nothing else in L
Q.4 Find out the language generated by the context free grammar with indicated
production
1) SaSa/bSb/˄
The language of even length Palindrome over {a,b}
2) SaSa/bSb/a/b/˄

Dixita Kagathara Page 1


Context Free Grammar 160704 – Theory of Computation

The language of even &odd length palindrome over {a,b}


3) SaS/bS/a
The set {a,b}*{a}
4) SSaS/b
(ba)*b
5) SaT/bT/˄
TaS/bS
{a,b}* even length string
6) SaSb/bSa/˄
No. of a and no. of b are same
7) SXaXaX
XaX/bX/˄
(a+b)*a(a+b)*a(a+b)*
8) SaX
XaX/bX/˄
a(a+b)*
9) S-> SS | XaXaX | ^
X->bX | ^
(b*ab*ab*)*
Q.5 Find a CFG for each of the Language defined by the following Regular Expression
1) ab*
SaX
X˄/bX

2) a*b*
SXY
XaX/˄
YbY/˄

3) L={aibjck | i=j or j=k} (Most IMP)


For i=j for j=k
S->AB S->CD
A->aAb | ab C->aC | a
B->cB | c D->bDc | bc

4) L={ aibjck | j>i+k} (Most IMP)


SABC
AaAb |˄
BbB | b
CbCc |˄

5) L={ 0i1j0k | j>i+k} (Most IMP)

Dixita Kagathara Page 2


Context Free Grammar 160704 – Theory of Computation

SABC
A0A1 |˄
B1B | 1
C1C0 |˄
6) Write CFG for (011+1)*(01)*
SAB
A011A | 1A | ^
B01B | ^
7) Write CFG which contains at least three times 1.
SA1A1A1A
A0A | 1A | ^
8) CFG should start and end with same symbol.
S0A0 | 1A1
A0A | 1A | ^
Q.6 Define: Regular Grammar
A grammar G=(V,Ʃ,S,P) is regular if every production takes one of the two forms
BaC

Ba
for variable B and C and terminal a
Q.7 Converting Finite Automata to Grammar

1
0

1 0
A B C

Equivalent CFG
A0A
A1B
B1B
B0C
B0
C0A
C1B

Dixita Kagathara Page 3


Context Free Grammar 160704 – Theory of Computation

Q.8 Define: Derivation Trees & Ambiguity


Let Consider the CFG with the Production SS+S | S-S | S*S | S/S |(S)| a
Left Most Derivation Right Most Derivation
A derivation of a string W in a grammar G is a A derivation of a string W in a grammar G is a
Left most derivation if at every step the left Right most derivation if at every step the right
most nonterminal is replaced most nonterminal is replaced
Consider string a*a-a Consider string: a-a/a
 SS-S SS-S
S*S-S S-S/S
a*S-S S-S/a
a*a-S S-a/a
a*a-a a-a/a
 Equivalent left most derivation tree  Equivalent Right most derivation tree

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 SS+S / S-S / S*S / S/S /(S)/a (IMP)
String : a+a+a
SS+S SS+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
SbSS SSSb
baS bSSSb
baSSb baSSb
baaSb baaSb
baaab baaab
 We have two left most derivation for string baaab hence, proved that above grammar is
ambiguous.

Q.9 Dangling “else” problem


 A standard example of ambiguity in programming language is the “dangling else”
phenomenon. Consider the production
<statement> if (<expression>) <statement> |
if (<expression>) <statement> else <statement> | <other statement>
 Describing the if statement as well as the related if-else statement, both part of the C
language. Now consider the statement
if(expr1) if (expr2) f(); else g();
 This can be derived in two ways form the grammar rules. in figure (a) the else goes with the
first if, and in the other, illustrated in fig (b), it goes with the second. a C compiler should
interpret the statement the second way, but not as a result of the syntax rules given; this is
additional information with which the compile must be furnished.

<statement>

<statement>
if else
( <expression> ) <statement>

<exp1> g();
) <statement>
( <expression>
if

f();
<exp2>
Figure (a)

Dixita Kagathara Page 5


Context Free Grammar 160704 – Theory of Computation

<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
AB1B2…..Bn where B1B2…Bn are nullable variable, then A is nullable.
3) No other variable in V are nullable.
Eliminate ˄ production :
1) SaX/Yb
XS/˄
YbY/b
Ans:
SaX/Yb/a
XS
YbY/b
2) SXaX/bX/Y
XXaX/XbX/˄
Yab
Ans:
SXaX/bX/Y/aX/Xa/a/b
XXaX/aX/Xa/a/XbX/Xb/bX/b
Yab

Dixita Kagathara Page 6


Context Free Grammar 160704 – Theory of Computation

Definition of Unit Production


Unit production is of form AB where A&B are non terminals.
Eliminate Unit Production:
1) SABA/BA/AA/AB/A/B
AaA/a
BbB/b
Ans:
unit production are SA and SB
so, A and B are variable
SABA/BA/AA/AB/aA/a/bB/b
SaA/a
SbB/b
2) SAa/B
Aa/bc/B
BA/bB
Ans:
Unit production are SB,AB and BA
SAa/A/bb
SAa/a/bc/bb

Aa/bc/B
Aa/bc/A/bb
Aa/bc/bb

BA/bb
Ba/bc/bb
So CFG after removing unit production is
SAa/a/bc/bb
Aa/bc/bb
Ba/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 ABC
Aa
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)

Dixita Kagathara Page 7


Context Free Grammar 160704 – Theory of Computation

Q.11 Convert following CFG to CNF


SaX/Yb
XS/˄
YbY/b
Step-1: Eliminate ˄-Production:
nullable production is X˄, new CFG without ˄-production
SaX/a/Yb
XS
YbY/b
Step-2: Eliminate Unit Production:
Unit Production is XS, new CFG without Unit Production
SaX/a/Yb
XaX/a/Yb
YbY/b
Step-3:Replace all mixed string with solid NT:
SAX/YB/a
XAX/YB/a
YBY/b
Aa
Bb
Step-4 : Shorten the string of NT to length 2
All NT string on the RHS in the above CFG are already the required length.
So, CFG is in CNF
Q.12 Convert following CFG to CNF
SAACD
AaAb/˄
CaC/a
DaDa/bDb/˄
Step-1: Eliminate ˄-Production:
nullable production is A˄ and D˄, new CFG without ˄-production
apply for A˄
SAACD/ACD/CD
Aab/aAb
CaC/a
DaDa/bDb/˄
apply for D˄
SAACD/ACD/CD/AAC/AC/C
Aab/aAb
CaC/a
DaDa/bDb/aa/bb
Step-2: Eliminate Unit Production:

Dixita Kagathara Page 8


Context Free Grammar 160704 – Theory of Computation

Unit Production is SC, new CFG without Unit Production


SAACD/ACD/CD/AAC/AC/aC/a
Aab/aAb
CaC/a
DaDa/bDb/aa/bb
Step-3:Replace all mixed string with solid NT:
SAACD/ACD/CD/AAC/AC/PC/a
APQ/PAQ
CPC/a
DPDP/QDQ/PP/QQ
Pa
Qb
Step-4 : Shorten the string of NT to length 2
SAT1, T1AT2 ,T2CD
SAU1,U1CD
SAV1,V1AC
SCD/AC/PC/a
APQ
APW1, W1AQ
CPC/a
DPP/QQ DPY1, Y1DP
DQZ1, Z1DQ
Pa
Qb
Q.13 Convert following CFG to CNF
SS(S)/˄
Step-1: Eliminate ˄-Production:
nullable production is S^, new CFG without ˄-production
SS(S)/(S)/S()/()
Step-2: Eliminate Unit Production:
SS(S)/(S)/S()/()
Step-3:Replace all mixed string with solid NT:
SSXSY/XSY/SXY/XY
X(
Y)
Step-4 : Shorten the string of NT to length 2
SST1, T1XT2, T2SY
SXV1 V1SY
SSU1 U1XY
SXY
X(
Y)

Dixita Kagathara Page 9


Context Free Grammar 160704 – Theory of Computation

Q.14 Convert following CFG to CNF


SAaA/CA/BaB
AaaBa/CDA/aa/DC
BbB/bAB/bb/aS
CCa/bC/D
DbD/˄
Step-1: Eliminate ˄-Production:
nullable production is D˄, new CFG without ˄-production
SAaA/CA/BaB
AaaBa/CDA/aa/DC/CA/C
BbB/bAB/bb/aS
CCa/bC/D
DbD/b
Step-2: Eliminate Unit Production:
Unit Production is AC and CD new CFG without Unit Production
SAXA/CA/BaB
AaaBa/CDA/aa/DC/CA/Ca/bC/bD/b
BbB/bAB/bb/aS
CCa/bC/bD/b
DbD/b
Step-3: Replace all mixed string with solid NT:
SAXA/CA/BXB
AXXBX/CDA/XX/DC/CA/CX/YC/YD/b
BYB/YAB/YY/XS
CCX/YC/YD/b
DYD/b
Xa
Yb.
Step-4 : Shorten the string of NT to length 2
SAP1 P1XA
SBQ1 Q1XB
SCA
AXX/DC/CA/CX/YC/YD/b
AXR1, R1XR2, R2BX
ACS1, S1DA
BYB/YY/XS
BYT1, T1AB
CCX/YC/YD/b
DYD/b
Xa
Yb

Dixita Kagathara Page 10


2014-15 | Sem-VI | Push Down Automata

160704 – Theory of Computation

Q.1 What is Pushdown Automata?


 Pushdown automata is a computational model equivalent to context free grammar
 A pushdown Automata is essentially a finite Automata with a stack data structure as shown
below.

I/P Finite Accept/Reject


Stack
Control

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.2 Deterministic Pushdown Automata.


 M= (Q,Ʃ,┌,q0,Z0,A, δ) be a pushdown Automata.
 M is deterministic if there is no configuration for which M has a choice of more than one
move.
 In other words M is deterministic if it satisfies both of the following condition.
1) For any q ∈ Q, q ∈ Ʃ U {˄} and X∈┌, the set δ(q,a,x)has at most one element.
2) for any q ∈ Q and X∈┌, if δ(q,˄,x) ≠0 then δ(q,a,x)= Ø for every a∈Ʃ

Dixita Kagathara Page 1


Push Down Automata 160704 – Theory of Computation

Q.3 Give a Transition Table and Transition Diagram for following CFG.
SaSa/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

Dixita Kagathara Page 2


Push Down Automata 160704 – Theory of Computation

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

Dixita Kagathara Page 3


Push Down Automata 160704 – Theory of Computation

Q.5 Design PDA for L={anbn/a,b∈Ʃ,n≥0} or PDA for Number of a’s and b’s are same.

Move State i/p Stack Symbol Move


No.
1 q0 ˄ Z0 (q2, ˄)
2 q0 a Z0 (q0,aZ0)
3 q0 a a (q0,aa)
4 q0 b a (q1, ˄)
5 q1 b a (q1, ˄)
6 q1 ˄ Z0 (q2, ˄)

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 SSS/[S]/{S}/˄

Move No. State i/p Stack Symbol Move


1 q0 [ Z0 (q1,[Z0])
2 q0 { Z0 (q1,{Z0})
3 q1 { { (q1,{{)
4 q1 [ { (q1,[{)

Dixita Kagathara Page 4


Push Down Automata 160704 – Theory of Computation

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

Design PDA to accept string with more a’s than b’s


Q.7
OR
Design PDA for given Language L={x∈{a,b}*/na(x)>nb(x)}

Move State i/p Stack Symbol Move


No.
1 q0 a Z0 (q1,aZ0)
2 q0 b Z0 (q0,bZ0)
3 q0 a b (q0,˄)
4 q0 b b (q0,bb)
5 q1 a a (q1,aa)
6 q1 b a (q0,˄)
7 q0 ˄ a (q1,a)

Dixita Kagathara Page 5


Push Down Automata 160704 – Theory of Computation

a,a/^
b,z0/ bz0
^,a/a
a,z0/ az0
q0 q1
a,a/ aa
b,b/^
b,a/ ^

Q.8 Design PDA for {anbn+m am | n,m>=0}

Move No. State i/p Stack Symbol Move


1 q0 a Z0 (q1, aZ0)
2 q0 b Z0 (q4, bZ0)
3 q1 a a (q1, aa)
4 q1 b a (q2, ^)
5 q2 b a (q2, ^)
6 q2 ^ Z0 (q3, Z0)
7 q3 b Z0 (q4, bZ0)
8 q4 b b (q4, bb)
9 q4 a b (q5, ^)
10 q5 a b (q5, ^)
11 q5 ^ Z0 (q6, Z0)
All other combination (none)
Q.9 PDA For L={x={a,b,c}*/Na(x)<Nb(x) or Na(x)<Nc(x)}
Move State Input Stack Move
NO.
1 q0 a z0 (q0,az0)
2 q0 b z0 (q1,bz0)
3 q0 c z0 (q1,cz0)
4 q0 a a (q0,aa)
5 q0 b a (q0,^)
6 q0 c a (q0,^)
7 q1 a b (q0,^)
8 q1 b b (q1,bb)
9 q1 a c (q0,^)
10 q1 c c (q1,cc)
11 q0 ^ b (q1,b)
12 q0 ^ C (q1,c)

Dixita Kagathara Page 6


Push Down Automata 160704 – Theory of Computation

Q.10 Design PDA for {aibjck | i,j,k>=0 & j=i or j=k}

Move No. State i/p Stack Symbol Move


1 q0 ^ Z0 (q1, Z0)( q4, bZ0)
2 q1 ^ Z0 (q3, Z0)
3 q1 a Z0 (q1, aZ0)
4 q1 a a (q1, aa)
5 q1 b a (q2, ^)
6 q2 b a (q2, ^)
7 q2 ^ Z0 (q3, Z0)
8 q3 c Z0 (q3, Z0)
9 q3 ^ Z0 (qf, Z0)
10 q4 ^ Z0 (qf, Z0)
11 q4 a Z0 (q4, Z0)
12 q4 b Z0 (q5,bZ0)
13 q5 b b (q5, bb)
14 q5 c b (q6, ^)
15 q6 c b (q6, ^)
16 q6 ^ Z0 (qf, Z0)
All other combination (none)
Q.11 Top-Down PDA corresponding to a CFG
 Let G=(V,Ʃ,S,P) be a CFG, we define M=(Q,Ʃ,┌,q0,Z0,A, δ) as follow:
Q={ q0,q1,q2,} A={ q2} ┌=VUƩU{Z0}
 The initial move of M is to place S on the stack and move to q1:
δ(q0,˄, Z0)={(q1, SZ0)}
 The only move to the accepting state q2 is fromq1, when stack is empty except for
Z0: δ(q1,˄, Z0)={ q2, Z0}
 Otherwise, the only moves of M are as follows
1) for every A∈ V, δ(q1,˄,A )={ (q1, α)/Aα is a production in G}

Dixita Kagathara Page 7


Push Down Automata 160704 – Theory of Computation

2) foe every a∈Ʃ, δ(q1,a,a)= (q1,˄)


Example:
Sa/aS/bSS/SSb/SbS
Move No. Stat i/p Stack Symbol Move
e
1 q0 ˄ Z0 (q1,SZ0)
2 q1 ˄ S (q1,a) (q1,aS) (q1,bSS)
(q1,SSb) (q1,SbS)
3 q1 a a (q1,˄)
4 q1 b b (q1,˄)
5 q1 ˄ Z0 (q2, Z0)
(q0,abbaaa, Z0)
⊢(q1,abbaaa, SZ0)
⊢(q1,abbaaa, SbSZ0)
⊢(q1,abbaaa, abSZ0)
⊢(q1,bbaaa, bSZ0)
⊢(q1,baaa, SZ0)
⊢(q1,baaa, bSSZ0)
⊢(q1,aaa, SSZ0)
⊢(q1,aaa, aSZ0)
⊢(q1, aa,SZ0)
⊢(q1,aa, aSZ0)
⊢(q1, a, SZ0)
⊢(q1, a, aZ0)
⊢(q1,˄, Z0)
⊢(q2,˄, Z0)
Q.12 Bottom-Up PDA for simple Algebraic Expressions
SS+T
ST
TT*a
Ta

Move Production Stack Unread i/p


Z0 a+a*a
shift - aZ0 +a*a
reduce Ta TZ0 +a*a
reduce ST SZ0 +a*a
shift - +SZ0 a*a
shift - a+SZ0 *a
reduce Ta T+SZ0 *a
shift - *T+SZ0 a
shift - a*T+SZ0 -

Dixita Kagathara Page 8


Push Down Automata 160704 – Theory of Computation

reduce Ta*T T+SZ0 -


reduce SS+T SZ0 -
(POP(S)) Z0 -
accept
Q.13 The Non Deterministic Bottom-Up PDA For G.

SS+T
ST
TT*a
Ta
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

Dixita Kagathara Page 9


Push Down Automata 160704 – Theory of Computation

Q.15 The language pal={x ϵ {a,b}* | x= xr } cannot be accepted by any DPDA.


Proof:
 Suppose for the sake of contradiction that M= (Q,{a, b},Г,q 0,Z0,A,δ ) is a DPDA accepting
pal . We can easily modify M if necessary. So, that every move is either one of the form

δ (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

(q0, u1, Z0) ├* (q, ˄, Aβ1)


And
(q0, u2, Z0) ├* (q, ˄, Aβ2)
 For some q ϵ Q, some A ϵ Г, and some string β1, β2 ϵ Г*. If we now look at longer string of
the form u1z and u2z , we have

Dixita Kagathara Page 10


Push Down Automata 160704 – Theory of Computation

(q0, u1z, Z0) ├* (q, z, Aβ1)


And
(q0, u2z, Z0) ├* (q, z, Aβ2)
 And the symbol A is never removed from the stack as a result of processing the string z. The
reason this is useful is that although the stack contents may not be the same in two cases,
the machine can never notice the difference.
 The ultimate result of processing the string u1z must be exactly the same as that of
processing u2z: Either both strings are accepted or neither is.
 Now however, we have the contradiction we are looking for. On the one hand, M threats u1z
and u2z the same way; on the other hand, the two strings u1 and u2 are distinguishable with
repeat to pal, so that for some z, one of the string u1z, u2z is in pal and the other is not.
This is impossible if M is accepts pal

Dixita Kagathara Page 11


2014-15 | Sem-VI | CFL & NFL

160704 – Theory of Computation

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
SABC AaAb|˄ BbB|b CcC|˄
Similarly, L2is generated by the CFG with productions
SAC AaAc|B BbB|˄ CcC|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

G1 = (V1, Ʃ, S1,P1) and G1 = (V2, Ʃ, S2,P2) ,

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

necessary so that V1 n V2= Ø and we define


Vu= V1 U V2 U {Su}
where Su is a new symbol not in V1 or V2. Then we let
Pu= P1 U P2 U { Su-> S1 | S2 }
On the one hand, if x is in either L1 or L2, then Su =>*x in the grammar Gu , because we can
start a derivation with either Su -> S1or Su -> S2 and continue with the derivation of x in G1
or G2 . Therefore,
L1 U L2⊆ L(Gu)
On the other hand, if x is derivable from Su in Gu, the first step in any derivation must be
Su=>S1 or Su=>S2
In the first case, all subsequent production used must be production in G1 , because no
variables in V2 are involved, and thus x∈ L1;in the second case, x ∈ L2. Therefore,
L(Gu) ⊆L1 U L2

Dixita Kagathara Page 1


CFL & NFL 160704 – Theory of Computation

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.

A grammar G* = (V, Ʃ, S, P) generating L1 *.Let

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)* .

Dixita Kagathara Page 2


2014-15 | Sem-VI | Turing Machine

160704 – Theory of Computation

Q.1 What is Turing machine? Explain its capabilities.


A Turing machine is a 5-tuple T=(Q,∑, Γ,q0, δ) where,
 Q is a finite set of states not to contain ha and hr.
 ∑ and Γ are finite sets, the input and tape alphabets respectively
 q0 is initial state
 δ is a partial function
Capabilities
 Turing machine is capable of performing computations on inputs and producing a new result.

B B a b # c a B

Finite
control

 An abstract model of a Turing machine is shown in above figure.


 Input to Turing machine is provided through a long tape. Turing machine provided with
read/write head.
 The tape is divided into square; each square holds a single symbol.
 The head is capable of performing 3 operations:
1. Reading a symbol being scanned
2. Modifying a symbol being scanned
3. Shifting either to previous square or next square
Q.2 Define Universal Turing Machine
A general purpose computer can be programmed to solve different types of problem.
A TM can also behave like a general purpose computer. General purpose computer solves a problem
as given below :
1. A program written in a high level language and its machine code obtained with the help of
compiler.
2. Machine code is loaded in to main memory.
3. Input to the program can be also loaded into main memory.
4. Program stored in a memory is executed line by line
 We can follow a similar approach for a TM. Such, a TM is known as Universal Turing
Machine (UTM). UTM can solve all sorts of solvable problem.

Finite control

I/P

Tape
000101000….

State

Dixita Kagathara Page 1


Turing Machine 160704 – Theory of Computation

 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

∆/∆,R Even pal

Dixita Kagathara Page 2


Turing Machine 160704 – Theory of Computation

Q.5 Draw Finite Automata For a TM Accepting {a,b}*{aba}{a,b}*

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

Q.7 Design Turing Machine for Accepting {x∈{a,b,c}* / n a(x)=n b(x)=nc(x)}

x/x,R x/x,L x/x,R


x/x,R x/x,L x/x,L
b/b,R b/b,L a/a,R a/a,L b/b,R a/a,L
c/c,R c/c,L c/c,R c/c,L a/a,R b/b,L

∆/∆,R a/x,L ∆/∆,R b/x,L ∆/∆,R c/x,L


q0 R q1 q2 q3 q4 q5 q6

∆/∆,L
∆/∆,R

q7 ha
∆/∆,S

x/x,L

Dixita Kagathara Page 3


Turing Machine 160704 – Theory of Computation

Q.8 Design a TM for Accepting {SS | S ∈ {a,b}*}

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

Dixita Kagathara Page 4


Turing Machine 160704 – Theory of Computation

Q.9 Design a Turing machine to copy a string.

Q.10 Design a Turing machine to delete a symbol

Dixita Kagathara Page 5


2014-15 | Sem-VI | Computable Functions

Chapter160704 – Theory of Computation


wise weightage

Q.1 Define following terms.


1. Initial Function
1. Constant functions: For each k ≥ 0 and each a ≥ 0, the constant function 𝐶𝑎𝑘 : Nk→ N is
defined by the formula
𝐶𝑎𝑘 (X) = a for every X 𝜖 Nk
In the case k = 0 we may identify the function 𝐶𝑎𝑘 with the number a.
2. The successor function s : N → N is defined by the formula
s(x) = x + 1
3. Projection functions: For each k ≥ 1 and each i with 1 ≤ i ≤ k, the projection function
𝑝𝑖𝑘 :Nk→ N is defined by the formula
𝑝𝑖𝑘 (x1, x2, … , xi, …., xk) = xi
2. Composition
Suppose f is a partial function from Nk to N, and for each i with 1 ≤ i ≤ k, gi is a partial function
from Nm to N. The partial function obtained from f and g 1, g2, ... , gk by composition is the partial
function h from Nm to N defined by the formula
h(X) = f(g1(X), g2(X), .. , gk(X)) (X ε Nm)
3. Primitive Recursion Operation
Suppose n ≥ 0, and g and h are functions of n and n + 2 variables, respectively. The function
obtained from g and h by the operation of primitive recursion is the function f : N n+1→ N defined by
the formulas
f(X,0) = g(X)
f(X, k + 1) = h(X, k, f(x, k))
for every X 𝜖 Nn and every k ≥ 0.
4. Primitive Recursive Functions
The set PR of primitive recursive functions is defined as follows.
1. All initial functions are elements of PR.
2. For any k ≥ 0 and m ≥ 0, if f : Nk→ N and g1, g2, ... , gk : Nm→ N are elements of PR, then
the function f(g1, g2, ... , gk) obtained from f and g1, g2, ... , gk by composition is an element
of PR.
3. For any n ≥ 0, any function g : Nn+1→ N in PR, and any function h : Nn+2→ N in PR, the
function f : Nn + 1→ N obtained from g and h by primitive recursion is in PR.
4. No other functions are in the set PR.
5. Bounded Quantifications
Let P be an (n + 1)-place predicate. The bounded existential quantification of P is the (n + 1)-place
predicate Ep defined by
Ep(X, k) = (there exists y with 0 ≤ y ≤ k such that P(X, y) is true)
The bounded universal quantification of P is the (n + 1)-place predicate AP defined by
AP(X, k) = (for every y satisfying 0 ≤ y ≤ k, P(X, y) is true)

Dixita Kagathara Page 1


Computable Function 160704 – Theory of Computation

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 :NN 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

Dixita Kagathara Page 2


Computable Function 160704 – Theory of Computation

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.

Dixita Kagathara Page 3


2014-15 | Sem-VI | Measuring & Classifying Complexity

160704 – Theory of Computation

Q.1 Define following terms.


1. Notation for Comparing Growth Rates
Suppose f, g: N → N are partial functions and each is defined at all but a finite number of points. We
write
f(n) = O(g(n))
or simply f = O(g), if there are constants C and n0 so that for every n ≥ n0, f(n) and g(n) are
defined and f(n) ≤ Cg(n). We write
f = Θ(g)
to mean that f = O(g) and g = O(f). Finally,
f(n) = o(g(n))
or f = o(g) means that for every positive constant C, there is a constant n0 so that for every n ≥ n0,
f(n) ≤ Cg(n).
2. The Time and Space complexity of a Turing Machine
Let T be a Turing machine. The time complexity of T is the function τ T defined on the natural
numbers as follows. For a natural number n, τT (n) is the maximum number of moves T can make
on any input string of length n. If there is an input string x with |x| = n so that T loops forever on
input x, τT (n) is undefined.
The space complexity function sT of T is defined as follows. If no input string of length n causes T to
use an infinite number of tape squares, sT (n) is the maximum number of tape squares used by T for
any input string of length n. (If T is a multitape TM, the "number of tape squares" means the
maximum of the numbers for the individual tapes.) Otherwise (if some input of length n causes T to
loop forever, and this infinite loop causes an infinite number of tape squares to be used), s T(n) is
undefined.
3. The Time and Space complexity of a Nondeterministic Turing Machine
Let T be a nondeterministic TM accepting a language L ⊆ Σ*. For an input string x, we define the
computation time τxas follows. First, τx is undefined if it is possible for T to loop forever on input x;
otherwise, if x 𝜖 L, τx is the minimum number of moves required for T to accept input x, and if x ∉ L,
τx is the minimum number of moves required for T to reject x. The nondeterministic time complexity
of T is the function τT, where τT (n) is the maximum value of τx over strings x with |x| = n. Thus τT
(n) is defined unless there is a string of length n on which T might loop forever.

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.

Dixita Kagathara Page 1


Measuring & Classifying Complexity 160704 – Theory of Computation

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.

Dixita Kagathara Page 2


2014-15 | Sem-VI | Tractable and Intractable Problems

160704 – Theory of Computation

Q.1 Define Polynomial-time Reducibility


If L1 and L2 are languages, over alphabets Σ1 and Σ2, respectively, we say L1 is polynomial-time
∗ ∗
reducible to L2, written L1 ≤p L2, if there is a function f : 1 → so that for any x 𝜖 ∗, x 𝜖 L1 if
and only if f(x) 𝜖 L2 and f can be computed in polynomial time-that is, there is a TM with polynomial
time complexity that computes f.
Q.2 Define NP-hard and NP-Complete Language
A language L is said to be NP-hard if L1 ≤p L for every L1 ε NP. (In other words, every decision
problem in NP is polynomial-time reducible to the one represented by L.) The language L is NP-
complete if L ε NP and L is NP-hard.
Q.3 Define The sets P, NP, Pspace, NPspace

P = U Time (Cnk)
c>0,k>=0

PSpace = USpace (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.

Dixita Kagathara Page 1


Tractable & Intractable Problems 160704 – Theory of Computation

 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

Q.6 Difference between NP-Hard & NP Complete Problem


Sr.No. NP-Hard Problem NP-complete Problem
1. A problem L is said to be NP-hard A decision problem L is NP-complete if it
if for any problem L1 in NP, there is in the set of NP problems and also in
is a polynomial-time reduction of the set of NP-hard problem
L1 to L.
2. If symbols, Pi is NP-hard if, for In symbols, Pi is NP-complete if Pi is NP-
every Pj 𝜖 NP,Pj Pi hard and Pi 𝜖 NP
3. An NP-hard need not be in NP An NP-complete problem must be in NP
4. NP hard problems are not NP All NP complete problems are NP hard
complete

Q.7 Explain Halting Problem


 The halting problem of a Turing machine states:
 Given a Turing machine M and an input ω to the machine M, determine if the machine M will
eventually halt it is given input ω.
 Halting problem of a Turing machine is unsolvable.
Proof:
 Moves of a Turing machine can be represented using a binary number. Thus, a Turing

Dixita Kagathara Page 2


Tractable & Intractable Problems 160704 – Theory of Computation

machine can be represented using a string over ε*(0, 1).


 Unsolvable of halting problem of a Turing machine can be proved through the method of
contradiction.
Step 1:Let us assume that the halting problem of a Turing machine is solvable. There exists a
machine H1 (say). H1 takes two inputs:
1. A string describing M.
2. An input ω for machine M.
H1 generate an output “halt” if H1 determines that M stops on input ω; otherwise H
outputs “loop”. Working of the machine H1 is shown below.

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 will do the opposite of the output of H2.


Step 4:Let us give H3 itself as inputs to H3.

H3
H3

If H3 as input then H3 would loop (that is how we constructed it).


If H3 loops forever on H3 as input H3 halts (that is how we constructed it).
In either case, the result is wrong.
Hence,
H3 does not exist.
If H3 does not exist than H2 does not exist.
If H2 does not exist than H1 does not exist.

Dixita Kagathara Page 3


Tractable & Intractable Problems 160704 – Theory of Computation

Q.8 Explain Cook’s Theorem


 Cook’s theorem states that any problem in class NP can be reduced to an instance of SAT in
polynomial time. Alternatively, it states that the Boolean satisfiability problem is NP-
complete.
 That is any problem in NP can be reduced in polynomial time by a deterministic Turing
machine to a problem of determining whether a Boolean formula is satisfiable.
 An important consequence of this theorem is this, if there were a deterministic polynomial
time algorithm for solving a Boolean satisfiability, and then there would exist a deterministic
polynomial time algorithm for solving all problems in NP. Crucially, the same follows for any
complete problem as there are also in NP.
 The question of whether such an algorithm exists is called P= NP problem and it is widely
considered the most important unsolved problem.
 A decision problem is NP-hard if the time complexity of a deterministic machine is within a
polynomial factor of the complexity of any problem in NP.
 A problem is NP-complete if it is NP-hard and in NP.
 Cook’s theorem proved SATISFIABILITY was NP-hard by using a polynomial time reduction
translating each problem in NP into an instance of SAT.
 Since, a polynomial time algorithm for SAT would simply a polynomial time algorithm for
everything in NP, SAT in NP-hard since we can guess a solution to SAT, it is in NP and thus
NP-complete.
 We had to show that all problems in NP could be reduced to SAT to make sure we did not
miss a hard one.
 But now that we have a known NP-complete problem in SAT. For any other problem, we can
prove it NP-hard by polynomial transforming SAT to it.
 Since the composition of two polynomial time reduction can be done in polynomial time, all
we need show is that SAT that is, any instance of SAT can be translated to an instance of X
in polynomial time. Yes

All SAT Problem Problem


Problem X X solver
in NP

No
Cook’s theorem
Polynomial reduction form
SAT to X

Dixita Kagathara Page 4

You might also like