0% found this document useful (0 votes)
200 views

Darshan Institute of Engineering and Technology, Rajkot Mid Semester Exam (March, 2022) B.E. Sem.-VI

This document contains the mid-semester exam questions and solutions for the Theory of Computation course at Darshan Institute of Engineering and Technology in Rajkot, India. The exam contains 4 questions, with multiple parts to each question. Question 1 defines one-to-one, onto, and bijection functions with examples. Question 2 explains equivalence relations with an example. Question 3 provides examples of strings that are members of a given language and writes regular expressions. Question 4 proves an identity using mathematical induction.

Uploaded by

Soham Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views

Darshan Institute of Engineering and Technology, Rajkot Mid Semester Exam (March, 2022) B.E. Sem.-VI

This document contains the mid-semester exam questions and solutions for the Theory of Computation course at Darshan Institute of Engineering and Technology in Rajkot, India. The exam contains 4 questions, with multiple parts to each question. Question 1 defines one-to-one, onto, and bijection functions with examples. Question 2 explains equivalence relations with an example. Question 3 provides examples of strings that are members of a given language and writes regular expressions. Question 4 proves an identity using mathematical induction.

Uploaded by

Soham Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

DARSHAN INSTITUTE OF ENGINEERING AND TECHNOLOGY, RAJKOT

Mid Semester Exam (March, 2022)


B.E. Sem.-VI (Computer Engineering)
Enroll. No.: ____________________
Subject: 3160704 – Theory of Computation (Paper Solution) Date: 07/03/2022

Time: 08:00 a.m. to 09:30 a.m. Total Marks: 42

Instructions: 1. Attempt All Questions.


2. Assume suitable data if necessary.
3. Figure to the right indicate full marks.
Q.1 Attempt any three questions.
1 Define one-to-one, onto, and bijection functions with examples. (3)
Onto function
 If the range of function and codomain of function are equal or every element of the codomain is
actually one of the values of the function, then function is said to be onto or surjective or
surjection.
 Example: 𝑓 : 𝐴 → 𝐵, 𝑓(𝑥) = 𝑥 2 where,
A = {-2,-1,1,2,3,4} and B = {1,4,9,16}
f(-2) = 4
f(-1) = 1
f(1) = 1
f(2) = 4
f(3) = 9
f(4) = 16
The range of function f(A) = {1, 4, 9, 16} = B
One-to-one function
 A function for which every element of the range of the function corresponds to
exactly one element of the domain is known as One-to-One or injective or injection.
 Example: 𝑓 : 𝐴 → 𝐵, 𝑓(𝑥) = 𝑥 2 where,
A = {1,2,3,4} and B = {1,4,9,16,25,36}
f(1) = 1
f(2) = 4
f(3) = 9
f(4) = 16
Bijection function
 If function is both one-to-one and onto then function is called Bijection function.
 Example: 𝑓 : 𝐴 → 𝐵, 𝑓(𝑥) = 𝑥 2 where,
A = {1,2,3,4} and B = {1,4,9,16}
f(1) = 1
f(2) = 4
f(3) = 9
f(4) = 16
2 Explain equivalence relation with example. (3)
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
R is equivalence on A if R is reflective, symmetric and transitive
Example : A={a, b}, R={(a, a), (b, b), (a, b), (b, a)}
Reflexive: {(a, a),(b, b)}
Symmetric: {(a, b), (b, a)}
Transitive: {(a, a), (a, b), (a, b)
(b, b), (b, a), (b, a)
(a, b), (b, b), (a, b)
(a, b), (b, a), (a, a)
(b, a), (a, b), (b, b)
(b, a), (a, a), (b, a)
3 1. Let L = {ab, aa, baa}. Which of the following strings are in L*? (3)
i. abaab
ii. aaabaa
iii. aaaabaaaa
iv. baaaaabaaaab
v. baaaaabaa
strings are in L* are: aaabaa, aaaabaaaa, baaaaabaa
Write a regular expression for the language of all strings containing exactly two
0’s.
1*01*01*
2. Write CFG for (001+1)*(01)*
S→AB
A→001A | 1A | ^
B→01B | ^
4 Using principle of mathematical induction, prove that for every n>=1, (3)
7+13+19+…..+(6n+1)=n(3n+4)
Step-1: Basic step
We must show that p(1) is true.
P(1)= 6n+1=(6(1)+1)=7
P(1)= n(3n+4) =1(3(1)+4)=7
And, this is obviously true.
Step-2: Induction Hypothesis
k >= 1 and p(k) = 7+13+19+…..+(6k+1)=k(3k+4)
Step-3: Proof of Induction
P(k+1)= 7+13+…..+(6k+1)+(6(k+1)+1)
= k(3k+4)+(6(k+1)+1)
= 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.2 Attempt any three questions.


1 Prove that √𝟐 is irrational by method of contradiction. (4)
 Definition: A real number is rational if there are two integers 𝑚 and 𝑛 so that 𝑥 = 𝑚/𝑛.
Proof:
 Suppose for the sake of contradiction that √2 is rational.
 Then there exist some integers 𝑚′ and 𝑛′ such that √2 = 𝑚′ /𝑛′.
 By dividing both 𝑚′ and 𝑛′ by all the factors that are common to both, we obtain √2 = m/𝑛, for
some integers 𝑚 and 𝑛 having no common factors.
 Since √2 = m/𝑛, m = 𝑛√2. Squaring both sides of this equation, we obtain 𝑚2 = 2𝑛2 , and
therefore 𝑚2 is even.
 If 𝑎 and 𝑏 are odd, then 𝑎𝑏 is odd. Since a conditional statement is logically equivalent to its contra
positive, we may conclude that for any 𝑎 and 𝑏, if 𝑎𝑏 is not odd, then either 𝑎 is not odd or 𝑏 is not
odd.
 However, an integer is not odd if and only if it is even, and so for any 𝑎 and 𝑏, if 𝑎𝑏 is even, 𝑎 or 𝑏
is even.
 If we apply this when 𝑎 = 𝑏 = 𝑚, we conclude that since 𝑚2 is even, 𝑚 must be even.
 This means that for some 𝑘, 𝑚 = 2𝑘. Therefore, (2𝑘)2 = 2𝑛2 .
 Simplifying and cancelling 2 from both sides, we obtain 2𝑘 2 = 𝑛2 . Therefore 𝑛2 is even and
therefore 𝑛 = 2𝑗 for some 𝑗.
 We have shown that 𝑚 and 𝑛 are both divisible by 2. This contradicts the previous statement that
𝑚 and 𝑛 have no common factor.
 The assumption that √2 is rational therefore leads to a contradiction, and the conclusion is that √2
is irrational.

2 Define pumping lemma and its applications. (4)


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: (Explain the application of the Pumping Lemma to show a Language is Regular or Not)

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.

3 Convert following CFG to CNF (4)


X→YYZM | YZM | YYZ | ZM | YM | M
Y→pYq | pq
Z→pZ | p
M→pMp | qMq | pp | qq
Step-1 is not required as there is no ˄ production
Step-2: Eliminate Unit Production:
Unit Production is X→M, new CFG without Unit Production is:
X→YYZM | YZM | YYZ | ZM | YM | pMp | qMq | pp | qq
Y→pYq | pq
Z→pZ | p
M→pMp | qMq | pp | qq
Step-3:Replace all mixed string with solid NT:
X→YYZM | YZM | YYZ | ZM | YM | PMP | QMQ | PP | QQ
Y→PYQ | PQ
Z→PZ | p
M→PMP | QMQ | PP | QQ
P→p
Q→q
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
4 Convert following Moore machine to Mealy machine. (4)
Old state After input a After input b Output
New state New state
→q0 q1 q2 0
q1 q3 q2 1
q2 q2 q3 0
q3 q3 q3 1

𝑞1
a/1 a/1
a/1,b/1

Start
𝑞0 b/0 𝑞3

b/0
b/1
𝑞2

a/0

Mealy machine

Q.3 Attempt any three questions.


1 Draw Finite Automata for following languages: (7)
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
1. L1∩ L2
2. L1-L2

M1

Finite Automata for 11 is not substring


M2

Finite Automata for string ending in 10

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

Finite Automata for L1-L2


L1 ∩ L2

Finite Automata for L1 ∩ L2

2 Design DPDA for the language {L=anbn, n>=0} (7)


Move State i/p Stack Symbol Move
No.
1 q0 ˄ Z0 (q2, z0)
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, z0)
a,z0/ az0
a,a/ aa
b,a/ ^

b,a/ ^ ^,z0/z0
q0 q1 q2

^,z0/ z0
3 Kleene’s Theorem Part-1 (7)
Proof:
• On the basis of statement L can be recognized by FA, NFA and NFA-^. It is sufficient to so that every
regular language can be accepted by NFA- ^.
• Set of regular language over alphabet Ʃ contains the basic languages. Ø, {^} 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 languages that can be accepted by NFA-^s, and the
induction step is to show that L1 U L2, L1L2, and L1* can also be accepted by NFA-^s.
• NFA-^ for the three basic languages is shown below.

W a W

Ø {^} {a}
FBasic Languages for NFA-^

• Now, suppose that L1 and L2 are recognized by the NFA-^s M1 and M2, respectively, where for both
i=1 and i=2,

Mi=(Qi,ε,qi,Ai,δi)

• 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
q1
f1’
^

qu
f2
^ q2

f2

Construction Of Mu

• Construction of Mu = (Qu, ε,qu,Au,δu). Let qu be a new state, not in either Q1 or Q2 and let
Qu = Q1 U Q2 U { qu }

Au = A1 U A2

• Now, we define δu so 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 M u, there is a sequence of
transition corresponding to x, starting at qu 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 q u.
therefore, since Q1 ∩ Q2 = Ø, either all the transition are between of Q1 or all are between elements
of Q2. It follow that x must be accepted by either M1 or M2.

Construction Of Mc

• Construction of Mc = (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 M2 as well as a ε-transition from each
state in A1 to q2.
• In other words, for any q not in A1, and α ∈ ε U {^}, δc(q,a) is defined to be either δ1(q,a) or δ2(q,a),
depending on whether q is in Q1 and Q2, for q ∈ A1.

δc(q,a)= δ1(q,a) for every a ∈ ε,

And δc(q,˄)= δ1(q,˄) U {q2}

f1 f2
^
qc=q1 q2
f1’ ^ f2’

Construction Of Mc

• 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 Mc, 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 from 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 Mk

• Construction of Mk = (Qk, Ʃ, qk, Ak,δk). Let qk be a new state not in Q1 and let Qk=Q1U{qk}. Once again all
the transitions of M1 will be allowed in Mk, but in addition there is a ˄-transition from qk to q1 and there
is a ˄-transition from each elements of A1 to qk. More precisely,

δk(qk,˄)={q1} and δk(qk,a)= Ø for a ∈ ε.

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 x i; 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 q k. 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 x i from q1 to an element of A1.
Therefore, x∈ L1*.
• Since we have constructed an NFA-˄ recognizing L in each of the three cases, the proof is complete.

4 Convert the following NFA-˄ to FA. (DFA)

^ b
1 4 5

b b
a
2 3
a
δ*(1,^) = {1,4}
δ*(1,a) =^( U δ(r,a))
r∈δ*( 1,^)
=^( U δ(r,a))
r∈δ(1,4)
= ^(δ(1,a)U δ(4,a))
= ^{Φ}

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


r∈δ*( 1,^)
=^( U δ(r,b))
r∈(1,4)
= ^(δ(1,b)U δ(4,b))
= ^(2,3,5)
= { 2,3,5}

δ*(2,^) = {2}
δ*(2,a) =^( U δ(r,a))
r∈δ*( 2,^)
=^( U δ(r,a))
r∈δ (2)
= ^(δ(2,a))
= ^{ 3}
= { 3}
δ*(2,b) =^( U δ(r,b))
r∈δ*( 2,^)
= ^( U δ(r,b))
r∈(2)
= ^(δ(2,b))

δ*(3,^) = {3}
δ*(3,a) =Ø
δ*(3,b) =Ø
δ*(4,^) = {4}
δ*(4,a) =^( U δ(r,a))
r∈δ*( 4,^)
=^( U δ(r,a))
r∈(4)
= ^(δ(4,a))

δ*(4,b) =^( U δ(r,b))
r∈δ*( 4,^)
=^( U δ(r,b))
r∈(4)
= ^(δ(4,b))
= ^{5}
= {5}
δ*(5,^) ={5}
δ*(5,a) =^( U δ(r,a))
r∈δ*( 5,^)
=^( U δ(r,a))
r∈(5)
= ^(δ(5,a))
=^{5}
=5
δ*(5,b) =^( U δ(r,b))
r∈δ*( 5,^)
=^( U δ(r,b))
r∈(5)
= ^(δ(5,b))
= ^{Φ}
=Φ a
b a
1 2 b 5 b 4
3
b
b b
b a
b
Construction of DFA
δ(1,a)=Φ
δ(1,b)={2,3,5}

δ((2,3,5),a)={3,4}
δ((2,3,5),b)=Φ

δ((3,4),a)=Φ
δ((3,4),b)={5}

δ(5,a)={4}
δ(5,b)=Φ

δ(4,b)={5}
δ(4,a)=Φ

DFA

-------------X----------X------------

You might also like