0% found this document useful (0 votes)
74 views12 pages

Tut-1 Solutions Merged

The document discusses problems related to theory of computation. Problem 1 proves that for any two strings x and y over the same alphabet, (xy)R = yRx R. Problem 2 proves that two definitions of palindrome are equivalent. Problem 3 proves that two definitions of balanced parentheses are equivalent. Problem 4 proves that any equivalence relation on a set partitions the set into disjoint equivalence classes.

Uploaded by

Chirag ahjdas
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)
74 views12 pages

Tut-1 Solutions Merged

The document discusses problems related to theory of computation. Problem 1 proves that for any two strings x and y over the same alphabet, (xy)R = yRx R. Problem 2 proves that two definitions of palindrome are equivalent. Problem 3 proves that two definitions of balanced parentheses are equivalent. Problem 4 proves that any equivalence relation on a set partitions the set into disjoint equivalence classes.

Uploaded by

Chirag ahjdas
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/ 12

CS F351 Theory of Computation

Tutorial-1

Problem 1 (In tutorial) Given a string over an alphabet Σ, xR is the string


x
obtained by reversing the string x. Example: Let Σ = {0, 1} and x = 1010 then
xR = 0101. Prove the following: for any two strings x and y over the same alphabet
Σ, (xy)R = y R xR .
The formal denition of xR is as follows: ϵR = ϵ and (xa)R = axR where a ∈ Σ.
Hint: use mathematical induction.

Proof.
By induction on |y| (i.e., the length of y ).
Base: For |y| = 0 =⇒ , y = ϵ =⇒ y = ϵ = y .
R

(xy)R = (xϵ)R = xR = ϵxR = y R xR .

Inductive hypothesis: Assume that the statement is true for all strings y , over Σ,
of length k. i.e., for all y ∈ Σk , (xy)R = y R xR .
Induction step: We now show that the statement holds for all strings y of length
k + 1.
Let y ∈ Σk+1 be a string, of length k + 1, such that y = va, where v ∈ Σk and a ∈ Σ.
(xy)R = (x(va))R = ((xv)a)R (Associativity of concatenation)
= a(xv)R (Def inition)
= a(v R xR ) (Inductive hypothesis =⇒ (xv)R = v R xR )
= (av R )xR (Associativity of concatenation)
= (aR v R )xR (Since aR = a)
= (va)R xR (Inductive hypothesis =⇒ aR v R = (va)R )
= y R xR

∴ By the principle of the mathematical induction it holds.

Problem 2 (In tutorial) Consider the following denitions of palindrome.

Denition 2.1 A palindrome is a string that reads the same from forward and back-
ward.

Denition 2.2
1
1. ϵ is a palindrome
2. If a is any symbol then the string a is a palindrome.
3. If a is any symbol and x is a palindrome then the string axa is a palindrome.
4. Nothing is palindrome unless it follows from (a) to (c)

Prove by induction that the two denitions are equivalent.

Proof.

For ϵ, it is part of def2 (clause 1) while it trivially satises def1. Similar argument
holds for strings of unit length (clause 2 in def2). For length 2 palindromes, they
satisfy def2 being of the type aa with x = ϵ (clause 3). Strings of type aa also satisfy
def1 being the same symbol repeated twice. Now let us assume both denitions to
be equivalent upto strings of length n > 2 in Σ∗ .
Consider a string σ with |σ| = n + 1 which is palindrome as per def1. That implies
σ = σ R (applying def1). Hence it must be the case that σ starts and ends with same
symbol. Hence ∃σ ′ ∈ Σ∗ , a ∈ Σ such that σ = aσ ′ a. Also, σ = σ R =⇒ aσ ′ a =
(aσ ′ a)R =⇒ aσ ′ a = aσ ′ R a =⇒ σ ′ = σ ′ R . Thus σ ′ is palindrome as per def1.
Since |σ ′ | = n − 1 and def2, def1 are equivalent for string length upto n, we have σ ′
as palindrome also for def2. Now, applying clause 3 of def2, we have σ = aσ ′ a as
palindrome (as per def2).
Consider a string σ with |σ| = n + 1 which is palindrome as per def2. Since n > 2,
we must have a palindrome x such that |x| = n − 1 and axa = σ for some symbol a.
x should satisfy def1 and hence x = xR . So, σ R = (axa)R = axR a = axa = σ . This
σ is also palindrome as per def1.

Problem 3 Prove that the following denitions for the string of balanced parentheses
are equivalent.

Denition 3.1 A string w over alphabet {(, )} is balanced i


1. w has an equal number of ('s as )'s.
2. any prex of w has at least as many ('s as )'s.

Denition 3.2 A string w over alphabet {(, )} is balanced i


1. ϵ is balanced.
2. If w is balanced string then (w) is balanced.
3. If w and x are balanced strings the wx is balanced.
4. Nothing else is balanced string
2
Problem 4 (In tutorial) Prove that any equivalence relation R on a set S parti-
tions S into disjoint equivalence classes.

Proof. Let R be an equivalence relation on S , and suppose a and b are elements of


S . Let Ca and Cb be the equivalence classes containing a and b respectively; that
is, Ca = {c | aRc} and Cb = {c | bRc}. We shall show that either Ca = Cb or
Ca ∩ Cb = ∅. Suppose Ca ∩ Cb ̸= ∅; let d be in Ca ∩ Cb . Now let e be an arbitrary
member of Ca . Thus aRe. As d is in Ca ∩ Cb we have aRd and bRd. By symmetry
dRa, By transitivity (twice), bRa and bRe. Thus e is in Cb and hence Ca ⊆ Cb . A
similar proof shows that Cb ⊆ Ca , so Ca = Cb . Thus distinct equivalence classes
are disjoint. To show that the classes form a partition, we have only to observe that
3
by reexivity, each a is in the equivalence class Ca , so the union of the equivalence
classes is S .

Problem 5 Show that the following are equivalent relation and give their classes.

1. R1 on integers → iR1 j i i = j
2. R2 on people → pR2 q if p and q were born on the same hour of same day of
some year

4
CS F351 Theory of Computation
Tutorial-2

Problem 1 Let L1 and L2 be two languages. Prove that (L1 L2 )R = LR


2 L1 .
R

Solution: (i) Let w ∈ (L1 L2 )R =⇒ wR ∈ L1 L2


=⇒ ∃x and y such that wR = xy ∈ L1 L2 and x ∈ L1 and y ∈ L2 .
Then (xy)R = y R xR ∈ LR
2 L1 . Thus, (L1 L2 ) ⊆ L2 L1 .
R R R R

(ii) Let w ∈ LR
2 L1 =⇒ ∃x and y such that w = xy and x ∈ L2 and y ∈ L1 .
R R R

Then (xy) = y x ∈ L1 L2 . Hence w = xy ∈ (L1 L2 ) . Thus, L2 L1 ⊆ (L1 L2 )R .


R R R R R R

Therefore, (L1 L2 )R = LR
2 L1 .
R

Problem 2 Give DFA's on Σ = {0, 1} accepting the following strings.

(a) The set of all strings such that each string has neither 00 nor 11 as a substring.

(b) The set of all strings such that each string has an even number of 0's and even number of 1's.

1
(c) (∗) The set of all strings such that each string has an odd number of 0's and even number of 1's.

(d) (∗) The set of all binary strings whose decimal equivalent is divisible by 5.

(e) The set of all strings containing at least three occurrences of three consecutive 1's, overlapping is
permitted e.g., the string 11111 should be accepted.

2
(f) (∗) The set of all strings such that every block of ve consecutive symbols contains at least two 0's.
Solution:

Problem 3 Design a DFA for the following set: the set of strings, over an alphabet Σ = {0}, whose
length is divisible by 2 or 7.

3
CS F351 Theory of Computation
Tutorial-3

Note: ∗ marked problems can be left to the students to try after the tutorial.

Problem 1 Design a DFA for the language, over Σ = {a, b}, such that all strings in the language contain

even number of a's and each a b.


is followed by at least one

Solution: Consider two sets of the given language:


A = {x ∈ Σ∗ | x contains even number of a's} and
B = {x ∈ Σ∗ | each a in x is followed by at least one b}
Note that the given language is the same as A ∩ B . The DFA's for A and B are given below:

Now we construct the DFA for the given language as discussed in the class.

Problem 2 Construct NFA for the following languages:

1. L1 = {x ∈ {0, 1}∗ | x contains the equal number of occurrences of 01 and 10}.


(∗) Also, construct a DFA for the same language.
Solution:

1
Figure 1: Solution to Problem 2.1.

2. (∗) L2 = {x ∈ {0, 1}∗ | x contains two 0s separated by a substring whose length is a multiple of 3}.

Solution:

Figure 2: Solution to Problem 2.2.

2
Problem 3 (∗) Say that string x is a prex of y if a string z such that y = xz and that x is a proper
prex of y if x ̸= y. Let A be a regular language.

Show that N OP REF IX(A) = {w ∈ A | no proper prex of w is a member of A} is also a regular


language.
Solution:
Let M = (Q, Σ, δ, q0 , F ) be an DFA such that L(M ) = A. We now construct M ′ = (Q′ , Σ, δ ′ , q0′ , F ′ ) such
that L(M ′ ) = N OP REF IX(A) where

1. Q′ = Q.
δ(r, a) if r ∈

/F
2. For r ∈ Q′ and a ∈ Σ dene δ ′ (r, a) =
∅ if r ∈ F
3. q0′ = q0 .
4. F ′ = F .

Problem 4 Construct an equivalent DFA for the following NFA's.

1. ({q0 , q1 , q2 , q3 }, {0, 1}, δ, q0 , {q3 }) where δ is Solution: The equivalent DFA is given be-
given in the below table. low. The states marked with ∗ are the nal
states.
δ 0 1 δ 0 1
→ q0 {q0 , q1 } {q0 } → {q0 } {q0 , q1 } {q0 }
q1 {q2 } {q2 } {q0 , q1 } {q0 , q1 , q2 } {q0 , q2 }
q2 {q3 } ∅ {q0 , q1 , q2 } {q0 , q1 , q2 , q3 } {q0 , q2 }
q3 {q3 } {q3 } {q0 , q2 } {q0 , q1 , q3 } {q0 }
∗{q0 , q1 , q2 , q3 } {q0 , q1 , q2 , q3 } {q0 , q2 , q3 }
∗{q0 , q1 , q3 } {q0 , q1 , q2 , q3 } {q0 , q2 , q3 }
∗{q0 , q2 , q3 } {q0 , q1 , q3 } {q0 , q3 }
∗{q0 , q3 } {q0 , q1 , q3 } {q0 , q3 }

2. (∗) ({q0 , q1 , q2 , q3 }, {0, 1}, δ, q0 , {q1 , q3 }) where Solution: The equivalent DFA is given be-
δ is given in the below table. low. The states marked with ∗ are the nal
states.
δ 0 1
δ 0 1
→ q0 {q1 , q3 } {q1 }
→ {q0 } {q1 , q3 } {q1 }
q1 {q2 } {q1 , q2 }
∗{q1 , q3 } {q2 } {q0 , q1 , q2 }
q2 {q3 } {q0 } ∗{q1 } {q2 } {q1 , q2 }
q3 ∅ {q0 } {q2 } {q3 } {q0 }
∗{q0 , q1 , q2 } {q1 , q2 , q3 } {q0 , q1 , q2 }
∗{q1 , q2 } {q2 , q3 } {q0 , q1 , q2 }
∗{q3 } ∅ {q0 }
∗{q1 , q2 , q3 } {q2 , q3 } {q0 , q1 , q2 }
∗{q2 , q3 } {q3 } {q0 }
∅ ∅ ∅

3
CS F351 Theory of Computation
Tutorial-4

Note: ∗ marked problems can be left to the students to try after the tutorial.

Problem 1 Construct NFA for the following languages:


L3 = {ω ∈ {a0 , a1 , a2 }∗ | ω is a string in which at least one ai occurs even number of times (not necessarily
consecutive), where 0 ≤ i ≤ 2} .
Solution:

Figure 1: Solution to Problem 2.1.

Problem 2 Let A ⊆ Σ ∗ be a language. Show that if A is regular then AR is also regular where AR =
{xR | x ∈ A}.

Solution Idea: Let M = (Q = {q0 , q1 , . . . , qk }, Σ, δ, q0 , F ) be an NFA such that L(M ) = A.


To construct an NFA M ′ for AR , in M reverse the direction of the edges, make q0 as the nal state. If F
has a unique state, then make it as the starting state for M ′ , otherwise create a new start state s and put
an ϵ-transition from s to each state in F (now a unique start state is dened for M ′ ).

Problem 3 (∗) For languages A and B, let the perfect shue of A and B be a language
{w | w = a1 b1 a2 b2 . . . ak bk , where a1 a2 . . . ak ∈ A and b1 b2 . . . bk ∈ B, each ai , bi ∈ Σ}.
Show that if A and B are regular then perfect shue of A and B is also regular.
Solution:
Please see a solution on page 2, problem 5
1
Problem 4 Use the procedure discusses in the class to convert the following DFA to regular expression.

Solution:
Please see solution on Problem 2.

Problem 5 Use the procedure discusses in the class to convert the regular expression
(((00)∗ (11)) + 01)∗ into an NFA (with ϵ-transitions).

Solution:
Please see solution on Problem 1.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy