Tut-1 Solutions Merged
Tut-1 Solutions Merged
Tutorial-1
Proof.
By induction on |y| (i.e., the length of y ).
Base: For |y| = 0 =⇒ , y = ϵ =⇒ y = ϵ = y .
R
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
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)
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.
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
(ii) Let w ∈ LR
2 L1 =⇒ ∃x and y such that w = xy and x ∈ L2 and y ∈ L1 .
R R R
Therefore, (L1 L2 )R = LR
2 L1 .
R
(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
Now we construct the DFA for the given language as discussed in the class.
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:
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.
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 .
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 2 Let A ⊆ Σ ∗ be a language. Show that if A is regular then AR is also regular where AR =
{xR | x ∈ A}.
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.