sns college of engineering

advertisement
SNS COLLEGE OF ENGINEERING
Kurumbapalayam(Po), Coimbatore – 641 107
Accredited by NAAC-UGC with ‘A’ Grade
Approved by AICTE & Affiliated to Anna University, Chennai
INTERNAL ASSESMENT EXAMINATIONS - III
COURSE: B.E – CSE
CS 6503 – THEORY OF COMPUTATION
Class
: V Sem CSE ‘A & B’
Date: 27.10.2015
Answer key
PART-A
ANSWER ALL QUESTIONS
1. Define: Finite Automata (FA) and Transition Diagram.
finite automaton M is a 5-tuple, (Q, Σ, δ, q0, F), consisting of a finite set of states (Q)a finite
set of input symbols called the alphabet (Σ)a transition function (δ : Q × Σ → Q)an initial
or start state (q0 ∈ Q)a set of accept states (F ⊆ Q) Transition Diagram: It can be directed
graph with vertices of a graph .
2. State the “Principle of Induction”.
Basis of induction
inductive step
3. Give regular expression for the following:
1) L1 = set of all strings of 0 and 1 ending in 00
2) L2 = set of all strings of 0 and 1begining with 0 and ending with 1.
soln:1)(0+1)*00
2)0(0+1)*1
4. Differentiate regular expression and regular language.
A regular grammar is a formal grammar that describes a regular language.
The languages accepted by a finite automation can easily be described by a simple
expression called regular expression.
5. What is an ambiguous grammar? Give example.
A context-free grammar is said to be an ambiguous grammar if there exists a string
which can be generated by the grammar in more than one way.
Example:
we have two derivations for − (id + id ):
E ⇒ − E ⇒ − ( E ) ⇒ − ( E + E ) ⇒ − (id + E ) ⇒ − (id + id )
E ⇒ − E ⇒ − ( E ) ⇒ − ( E + E ) ⇒ − ( E + id ) ⇒ − (id + id )
6. What are the different types of language accepted by PDA and define them?
Acceptance by empty stack
Acceptance by final state.
7. List out the different techniques for Turing machine construction.
Use of States to Store Information
Use of Multiple Tracks
Subroutines
Two-way infinite tape
Turing machine with stationary head.
8. Can we simulate multi - tape Turing Machine to a single tape Turing machine?
Justify.
YES, Can we simulate multi - tape Turing Machine to a single tape Turing machine.
9. Difference between unsolvable problems and computable problems.
A computational problem that cannot be solved by a Turing machine. The associated
function is called an uncomputable function.
Computability is the ability to solve a problem in an effective manner.
10. What are 1) Recursive enumerable language. 2) Recursive set.
Recursively enumerable languages are known as type-0 languages in the Chomsky
hierarchy of formal languages
A set of natural numbers is called recursive set.
PART:B
11(a(i)). Explain the steps in conversion of NFA to DFA. Convert the following NFA to
DFA.
soln:
This can be solved using subset construction method
11(a(ii)). Prove that, if L is accepted by an NFA with ϵ transitions, then L is accepted by
NFA without ϵ transitions.
Theorem:
If L is accepted by an NFA with ϵ transitions, then L is accepted by NFA without ϵ
transitions.
Proof:
If part: If L is the set accepted by NFA ,then there exist a dfa which accepts L.
Only if part: let E=(QE, Σ, δE,qo,FE) D = (QD, Σ, δD, q0, FD)
To prove:L(E)=L(D) by using inductive hypothesis
Basis: If|w|=0
Induction: By using inductive hypothesis the statement is true for all the string of L
so L(E)=L(D) thus theorem is proved.
11(b(i)). Prove that equivalence of NFA and DFA using subset construction.
DFA : M is a 5-tuple, (Q, Σ, δ, q0, F), consisting of a finite set of states (Q) a finite set of
input symbols called the alphabet (Σ) a transition function (δ : Q × Σ → Q) an initial or start
state (q0 ∈ Q) a set of accept states (F ⊆ Q)
NFA: M is a 5-tuple, (Q, Σ, δ, q0, F), consisting of a finite set of states (Q) a finite set of
input symbols called the alphabet (Σ) a transition function (δ : Q × Σ → 2Q) an initial or start
state (q0 ∈ Q) a set of accept states (F ⊆ Q)
11(b(ii) Give Deterministic finite automata accepting the following language over the
alphabet
(1) Number of 1’s is a multiple of 3
(2) Number of 1’s is not a multiples of 3
Valid inputs:
111
111111
1^9
1^12
invalid inputs:
00,11,….
12(a(i) Convert the following NFA into a regular expression
soln:
solve using formula:Rij^(k)=Rij^(k-1)+Rik^(k-1).(Rkk^(k-1))^*Rkj^(k-1)
12(a(ii) Convert the following grammar into GNF. S -> XY1 | 0 ; X -> 00X | Y ; Y -> 1X1
Soln:
conditions for GNF is NT-> t
NT-> t . anyno.of N.T
if it is satisified this conditions thus the given grammar is GNF.
12(b(i)). Discuss the closure properties of regular languages.
Soln:
Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism,
Inverse Homomorphism.
12(b(ii)). Using pumping lemma for regular sets prove that the language
L={0m1n0m+n | m≥1 and n≥1 } is not regular.
soln:
Suppose for contradiction that L were regular. Let N be the pumping length, as guaranteed by
the pumping lemma. Select s = 0N 1 N 0 2N ∈ L. We have that that s = xyz, for some x, y,
and z, y ∈ 0 +, and xyi z ∈ L for all i ≥ 0. But, letting i = 0, observe that xz = 0n1 N 0 2N ,
where n < N. This string is not in L, so it is not regular.
13(a(i)). Give formal pushdown automata that accepts {wcwR | w in (0+1)*} by empty
stack.
soln:
Instantaneous description:
δ(qo,c,a)=(q1,a)
δ(qo,a,zo)=(qo,a,zo)
δ(qo,c,b)=(q1,b)
δ(qo,b,zo)=(qo,b,zo)
δ(qo,a,a)=(q2, ε)
δ(qo,a,a)=(qo,aa)
δ(qo,b,b)=(q2, ε)
δ(qo,a,b)=(qo,ab)
δ(qo,a,a)=( q2, ε)
δ(qo,b,a)=(qo,ba)
δ(qo,b,b)=( q2, ε)
δ(qo,b,b)=(qo,bb)
δ(qo, ε,zo)=( q2, ε)
13(a(ii)). Prove the equivalence of PDA and CFL.
soln:
For a given CFG,G=(V,T,P,S) we can construct a PDA,M that simulates the leftmost
derivation of G.
The PDA accepting L(G) by empty stack is given by
M=({q},T,VUT,δ,q,S,∅)
PDA by
PDA by
final
empty
stack
stack
13(b(i)). Show that L ={anbncn | n ≥ 1} is not a context free language.
CFG
Soln:
|vxy|<=n vy≠ ε if i=0,1,2,…… uv^ixy^i z∈L
for various value of i the power of abc does not match with L
so L is not a CFL.
13(b(ii)). Let L be any CFL. Then there is a constant n, depending only on L, such that
if z is in L and |z| ≥ n, then we can write z = uvwxy such that
(i) |vx| ≥ 1
(ii)
|vwx|≤n
(iii) For all i ≥ 0, uviwxiy ∑ L.
Soln:
If i=0,1,2,…… for various value of i, L does not match so L is not a CFL.
14(a(i)) Explain Turing machine as a computer of integer functions with an example.
soln:
A function f (w) has: Domain D and Result Region: S A function may have many parameters.
Example: Addition function f (x, y) = x + y.
14(a(ii)) Write briefly about the programming techniques for TM.
soln:
Use of States to Store Information
Use of Multiple Tracks
Two-way infinite tape
Subroutines
Turing machine with stationary head
14(a(iii)) Design a Turing machine which reverse the given string {abb}
soln:
a
b
b
B
a
b
x
B
R
a
x
x
b
L
B
a
x
x
b
R
x
x
x
b
b
B
L
b
x
B
x
x
b
R
b
a
B
L
B
x
x
b
B
B
B
b
b
b
a
a
B
B
B
B
x
b
b
a
B
14(b(i))Write short notes on the following:
soln:
1) Two – way infinite tape TM
Two-way infinite tapes do not add any power. Just fold the tape someplace and
simulate it on two tracks of a one-way infinite tape: · · ·
2) Multiple tracks TM
A multi-tape Turing machine with k tapes is defined in nearly the same way as a
conventional single-tape Turing machine, except that it stores k strings
simultaneously, maintains a position in each of the k strings, updates these k
positions independently (i.e. it can move left in one string while moving right in
another), and its state changes are based on the entire k-tuple of symbols that it
reads at any point in time. More formally, a k-tape Turing machine has a finite
alphabet Σ and state set K as before, but its transition function is δ : K × Σ k → (K
∪ {halt, yes, no}) × (Σ × {←,→, −}) k ,
15(a(i)).Write the classes and definition of NP problems
Soln:
Definition.
The class of nondeterministic polynomially acceptable problems, NP, contains all sets in
which membership can be verified in polynomial time.
Classes:
NP is a class of problems that we would love to solve but are unable to do so exactly.
Example:
Consider final examination scheduling.
 A school has n courses and five days in which to schedule examinations.
 An optimal schedule would be one where no student has to take two examinations on
the same day.
 There are O(5n ) possible different schedules.
 200,000,000,000,000,000,000 years! (regardless of the type of machine used)
15(a(ii)Prove that for two recursive languages L1 and L2 their union and intersection is
recursive.
soln:
The union of two recursive languages is recursive:
Proof:
The TM corresponding to this must halt always. Let L1 and L2 be sets accepted by M1 and
M2, respectively. Then L1 ∪ L2 is accepted by TM M, where x = w1 ∪w2, for w1 ∈ L1 and
w2 ∈ L2.
The intersection of two recursive languages is recursive:
Proof:
 Let L1 and L2 be languages recognized by Turing machines M1 and M2,
respectively.
 Let a new TM M∩ is for the intersection L1 ∩L2. M∩ simply executes M1 and M2
one after the other on the same input w: It first simulates M1 on w. If M1 halts by
accepting it, M∩ clears the tape, copies the input word w on the tape and starts
simulating M2. If M2 also accepts w then M∩ accepts.
 Clearly, M∩ recognizes L1 ∩L2, and if M1 and M2 halt on all inputs then also M∩
halts on all inputs.
15(b(i)).Prove that if a language is recursive if and only if it and its complement are
both recursively enumerable.
soln:
w∈L1 YES
M1
YES
w∈Σ*
M3
YES
w∈L^M2
15(b(ii)).Explain about undecidability of PCP.
soln:
Proof:
The membership problem is undecidable for Type 0 grammars. Thus, it is sufficient to show
how from each instance (G, w) of the membership problem for Type 0 grammars, an instance
I can be constructed, such that the PCP has a positive solution at I if and only if w is in L(G).
For the purpose of the proof consider any Type 0 grammar G = <N, , P, S> and any string w
in *. With no loss of generality assume that #, ¢, and $ are new symbols not in N
. Then
let the corresponding instance I = <(x1, y1), . . . , (xk, yk)> of PCP be of the following form.
PCP has a positive solution at I if and only if I can trace a derivation that starts at S and ends
at w.
For each derivation in G of the form S
. , in) of a positive solution
1
m
w, the instance I has a witness (i1, . .
Download