Uploaded by Diwakar Kashyap

Solution

advertisement
Solution
Chapter – 1
Introduction to the Theory of Computation
Exercise 1.1
1. With π‘ΊπŸ = {𝟐, πŸ‘, πŸ“, πŸ•}, π‘ΊπŸ = {𝟐, πŸ’, πŸ“, πŸ–, πŸ—}, 𝒂𝒏𝒅 𝑼 = {𝟏 ∢ 𝟏𝟎}, compute π‘ΊπŸ ∩ π‘ΊπŸ =
{ 𝒙 | 𝒙 ∈ π‘ΊπŸ 𝒂𝒏𝒅 𝒙 ∈ π‘ΊπŸ } = { 𝟐, πŸ“ }
SOLUTION
The set S1 ∩ S2 contains all the elements that are common in both sets S1 and S2. In
this case, the elements 2 and 5 are in both sets 𝑆1 and 𝑆2 , so they are in the intersection
of the two sets.
𝑆1 π‘ˆ 𝑆2 = { π‘₯ | π‘₯ ∈ 𝑆1 π‘œπ‘Ÿ π‘₯ ∈ 𝑆2 } = { 2, 3, 4, 5, 7, 8, 9 }
The set 𝑆1 π‘ˆ 𝑆2 is the union of the sets 𝑆1 π‘Žπ‘›π‘‘ 𝑆2 , containing all the elements that are
in either set.
𝑆1 ∪ π‘ˆ = { π‘₯ | π‘₯ ∈ 𝑆1 π‘œπ‘Ÿ π‘₯ ∈ π‘ˆ } = { 1, 2, 3, 5, 7, 10 }
The set 𝑆1 ∪ π‘ˆ is the union of the sets 𝑆1 π‘Žπ‘›π‘‘ π‘ˆ. It contains all elements in set 𝑆1 and
all element in set π‘ˆ.
𝑆2 ∪ π‘ˆ = { π‘₯ | π‘₯ ∈ 𝑆2 π‘œπ‘Ÿ π‘₯ ∈ π‘ˆ } = { 1, 2, 4, 5, 8, 9, 10 }
The set 𝑆2 ∪ π‘ˆ is the union of the sets 𝑆2 and U. It contains all elements in set 𝑆2 and
all element in set π‘ˆ.
2. With π‘ΊπŸ = {𝟐, πŸ‘, πŸ“, πŸ•} and π‘ΊπŸ = {𝟐, πŸ’, πŸ“, πŸ–, πŸ—}, compute π‘ΊπŸ × π‘ΊπŸ and π‘ΊπŸ × π‘ΊπŸ.
Solution:
First, we need to understand what the Cartesian product of two sets is. The Cartesian
product of two sets is the set of all possible ordered pairs that consist of one element
from each set. Each ordered pair (π‘₯, 𝑦) in the Cartesian Product 𝑆1 × π‘†2 , represents an
element x from set S1 and an element y from set S2.
Given the sets 𝑆1 = {2, 3, 5, 7} and 𝑆2 = {2, 4, 5, 8, 9}. To compute the Cartesian
Product 𝑆1 × π‘†2 , we need to form all possible ordered pairs (x, y) where x is an element
of set 𝑆1 and 𝑦 is an element of set 𝑆2 .
In this case, we have 4 elements in set 𝑆1, which are 2, 3, 5, 7, π‘Žπ‘›π‘‘ 5 elements in set 𝑆2 ,
which are 2, 4, 5, 8, 9. So, there are 4 × 5 = 20 possible ordered pairs that can be
formed by combining elements of set 𝑆1 and set 𝑆2 .
The result of the Cartesian Product 𝑆1 × π‘†2 , will be a set containing all 20 of these
ordered pairs:
{ (2, 2), (2, 4), (2, 5), (2, 8), (2, 9), (3, 2), (3, 4), (3, 5), (3, 8), (3, 9), (5, 2), (5, 4),
(5, 5), (5, 8), (5, 9), (7, 2), (7, 7, 4), (7, 5), (7, 8), (7, 9) }
Similarly, To compute the Cartesian Product 𝑆2 × π‘†1 , we need to form all possible
ordered pairs (π‘₯, 𝑦) where π‘₯ is an element of set 𝑆2 and 𝑦 is an element of set 𝑆1.
The result of the Cartesian Product 𝑆2 × π‘†1 will be a set containing all 20 of these
ordered pairs:
{ (2, 2), (2, 3), (2, 5), (2, 7), (4, 2), (4, 3), (4, 5), (4, 7), (5, 2), (5, 3), (5, 5), (5, 7),
(8, 2), (8, 3), (8, 5), (8, 7), (9, 2), (9, 3), (9, 5), (9, 7) }
It's important to note that the order of the sets is important for Cartesian Product, since
the result will be different if we change the order of the sets. As you can see from the
above, 𝑆2 × π‘†1 is different from 𝑆2 × π‘†1 .
Also, we can observe that Cartesian product of two sets is commutative and the number
of ordered pairs in the Cartesian Product of two sets is the product of number of
elements in the two sets.
3. For S = {2, 5, 6, 8} and T = {2, 4, 6, 8}, compute |S ∩ T| + |S ∪ T|.
To compute the size of the intersection of two sets S and T, we use the notation |S ∩ T|.
The intersection of two sets is the set of elements that are common to both sets.
To compute the size of the union of two sets S and T, we use the notation |S ∪ T|. The
union of two sets is the set of elements that are in either S or T or both.
For the given sets S = {2, 5, 6, 8} and T = {2, 4, 6, 8}, we can compute their intersection
and union as follows:
S ∩ T = {2, 6, 8} (elements that are in both S and T)
S ∪ T = {2, 4, 5, 6, 8} (elements that are in either S or T or both)
So, |S ∩ T| = 3 (size of the intersection set)
and |S ∪ T| = 5 (size of the union set)
Now we can compute the final expression:
|S ∩ T| + |S ∪ T| = 3 + 5 = 8
So the final result is 8
4. What relation between two sets S and T must hold so that |S∪T| = |S|+|T|?
For two sets S and T, the relation between them that must hold so that |S ∪ T| = |S| +
|T| is that they must be disjoint sets. Disjoint sets are sets that have no elements in
common, meaning that the intersection of the sets is the empty set.
When two sets are disjoint, there are no elements that belong to both sets, so all elements
in the union of the sets belong to either S or T. As a result, the size of the union of the
sets is equal to the size of set S plus the size of set T, which can be represented as |S ∪
T| = |S| + |T|.
We can also prove this by using the Identity law of Set theory : |A| + |B| = |A∪B| +
|A∩B| Since the sets are disjoint, the intersection of the sets is an empty set, |A∩B| = 0
Therefore, |A| + |B| = |A∪B| + 0 = |A∪B|
So if we have two disjoint sets, their union is the sum of the size of the individual sets.
5. Show that for all sets S and T, S − T = S ∩ T.
To prove that S − T = S ∩ T for all sets S and T, we can start by examining the
definitions of the set difference and set intersection operations.
ο‚·
The set difference of S and T, denoted as S − T, is the set of elements that belong to S
but not to T. In other words, it is the set of elements that are in S but not in T.
ο‚·
The set intersection of S and T, denoted as S ∩ T, is the set of elements that belong to
both S and T. In other words, it is the set of elements that are in both S and T.
From the definitions above, we can see that the elements of S − T are the elements that
are in S but not in T. At the same time, we can see that the elements of S ∩ T are the
elements that are in both S and T.
Therefore, we can conclude that S − T = S ∩ T, since they both represent the same set
of elements, the elements that belong to S but not to T.
We can also prove this by contradiction. Assume that S − T ≠ S ∩ T, then there will be
some elements in S − T which are not in S ∩ T or vice versa. But this contradicts the
definition of set difference and set intersection as we have discussed earlier. Therefore,
S − T = S ∩ T for all sets S and T.
6. Prove DeMorgan’s laws, Equations (1.2) and (1.3), by showing that if an element x
is in the set on one side of the equality, then it must also be in the set on the other
side of the equality.
DeMorgan's laws are two important laws in set theory that relate the complements of
sets to the intersections and unions of sets. They are given by the following equations:
(1.2) ~(S ∪ T) = ~S ∩ ~T (1.3) ~(S ∩ T) = ~S ∪ ~T
To prove these laws, we can show that if an element x is in the set on one side of the
equality, then it must also be in the set on the other side of the equality.
Let's start with equation (1.2):
~(S ∪ T) = ~S ∩ ~T
If x is in ~(S ∪ T), then it means that x is not in the union of S and T. This means that
x is not in S and x is not in T. Therefore, x is in the complement of S, ~S, and x is in
the complement of T, ~T. So x is in the intersection of ~S and ~T, which is ~S ∩ ~T.
Conversely, if x is in ~S ∩ ~T, then it means that x is not in S and x is not in T. This
means that x is not in the union of S and T. Therefore, x is in the complement of the
union of S and T, ~(S ∪ T).
So we have shown that if x is in the set on one side of the equation, then it must also be
in the set on the other side of the equation.
Let's move to equation (1.3):
~(S ∩ T) = ~S ∪ ~T
If x is in ~(S ∩ T), then it means that x is not in the intersection of S and T. This means
that x is not in S or x is not in T. Therefore, x is in the complement of S or x is in the
complement of T, ~S or ~T. So x is in the union of ~S and ~T, which is ~S ∪ ~T.
Conversely, if x is in ~S ∪ ~T, then it means that x is not in S or x is not in T. This
means that x is not in the intersection of S and T. Therefore, x is in the complement of
the intersection of S and T, ~(S ∩ T).
So we have shown that if x is in the set on one side of the equation, then it must also be
in the set on the other side of the equation.
By showing that if an element x is in the set on one side of the equality, then it must
also be in the set on the other side of the equality, we have proven DeMorgan's laws,
equations (1.2) and (1.3), which relate the complements of sets to the intersections and
unions of sets.
7. Show that if S1 ⊆ S2, then S2 ⊆ S1.
It is not true that if S1 ⊆ S2, then S2 ⊆ S1.
The symbol ⊆ means subset, which means that all elements of set S1 are also present
in set S2, but set S1 may have other elements that are not in set S2.
For example, let S1 = {1, 2, 3} and S2 = {1, 2}. We can see that S1 ⊆ S2, because all
elements of S1 are in S2. But S2 is not a subset of S1 because not all elements of S2
are in S1.
Another example is let S1 = {1, 2} and S2 = {1, 2, 3}. Here we can see that S1 ⊆ S2,
but S2 is not a subset of S1 because not all elements of S2 are in S1.
So we can conclude that if S1 ⊆ S2, it does not imply that S2 ⊆ S1.
8. Show that S1 = S2 if and only if S1 ∪ S2 = S1 ∩ S2.
We can show that S1 = S2 if and only if S1 ∪ S2 = S1 ∩ S2 using the following logical
equivalences:
ο‚·
S1 = S2 if and only if S1 ⊆ S2 and S2 ⊆ S1
ο‚·
S1 ⊆ S2 if and only if S1 ∪ S2 = S2
ο‚·
S2 ⊆ S1 if and only if S1 ∩ S2 = S2
From 1, we have: S1 = S2 if and only if (S1 ⊆ S2 and S2 ⊆ S1)
From 2 and 3, we have: S1 ⊆ S2 if and only if S1 ∪ S2 = S2 and S2 ⊆ S1 if and only
if S1 ∩ S2 = S2
Combining these equivalences, we get: S1 = S2 if and only if (S1 ∪ S2 = S2) and (S1
∩ S2 = S2)
Since S2 is a subset of S1 and S1, it means S1 ∪ S2 = S2 and S1 ∩ S2 = S2, so we can
write: S1 = S2 if and only if S1 ∪ S2 = S1 ∩ S2
In other words, two sets are equal if and only if their union and intersection are equal.
Exercise 1.2
1. How many substrings 𝒂𝒂𝒃 are in π’˜π’˜π‘Ή π’˜, where π’˜ = 𝒂𝒂𝒃𝒃𝒂𝒃?
Solution: A substring is a sequence of characters that appear in a string in a consecutive
manner. In this question, we are looking for the number of substrings π‘Žπ‘Žπ‘ in the string
𝑀𝑀 𝑅 𝑀 where 𝑀 = π‘Žπ‘Žπ‘π‘π‘Žπ‘.
To find this, we first need to determine what the string 𝑀𝑀 𝑅 𝑀 is. In this case, the string
𝑀𝑀 𝑅 𝑀 is formed by concatenating the string w = π‘Žπ‘Žπ‘π‘π‘Žπ‘ twice and then reversing the
second copy. So, 𝑀𝑀 𝑅 𝑀 = "π‘Žπ‘Žπ‘π‘π‘Žπ‘π‘Žπ‘Žπ‘π‘π‘Žπ‘Žπ‘".
After that we need to look for all substring π‘Žπ‘Žπ‘ in the string 𝑀𝑀 𝑅 𝑀 Here, we can see
that there are 3 such substrings "π‘Žπ‘Žπ‘"
a
a
b
Set 1
b
a
b
a
a
b
Set 2
b
a
a
B
Set 3
π‘†π‘œ π‘‘β„Žπ‘’ π‘Žπ‘›π‘ π‘€π‘’π‘Ÿ 𝑖𝑠 3.
2. Use induction on n to show that |𝒖𝒏 | = 𝒏 |𝒖| for all strings 𝒖 and all 𝒏.
Solution:
π΅π‘Žπ‘ π‘’ πΆπ‘Žπ‘ π‘’ (𝑛 = 1)
When 𝑛 = 1, |𝑒𝑛 | = |𝑒|. This is true because 𝑒1 = 𝑒, so the length of the
concatenation of 𝑒 with itself once is the same as the length of the original string 𝑒.
Inductive Step:
Assume that |π‘’π‘˜ | = π‘˜|𝑒| is true for some π‘˜. We will now prove that
|𝑒^(π‘˜ + 1)| = (π‘˜ + 1)|𝑒|.
We know that
|𝑒(π‘˜+1) | = |π‘’π‘˜ 𝑒|.
By the induction hypothesis, we know that
|𝑒^π‘˜| = π‘˜|𝑒|.
Since we are concatenating π‘’π‘˜ with 𝑒,
|π‘’π‘˜ 𝑒| = (π‘˜|𝑒|) + |𝑒| = π‘˜|𝑒| + |𝑒| = (π‘˜ + 1)|𝑒|.
Therefore, by mathematical induction, we have shown that |𝑒𝑛 | = 𝑛|𝑒| for all strings
𝑒 and all 𝑛.
In simple words, the length of the concatenation of a string 𝑒 with itself n times is equal
to the length of the original string multiplied by 𝑛.
3. The reverse of a string, introduced informally above, can be defined more precisely
by the recursive rules
π‘Žπ‘… = π‘Ž,
(π‘€π‘Ž)𝑅 = π‘Žπ‘€π‘…,
π‘“π‘œπ‘Ÿ π‘Žπ‘™π‘™ π‘Ž ∈ 𝛴, 𝑀 ∈ 𝛴 ∗. π‘ˆπ‘ π‘’ π‘‘β„Žπ‘–π‘  π‘‘π‘œ π‘π‘Ÿπ‘œπ‘£π‘’ π‘‘β„Žπ‘Žπ‘‘
(𝑒𝑣)𝑅 = 𝑣𝑅 𝑒𝑅 ,
π‘“π‘œπ‘Ÿ π‘Žπ‘™π‘™ 𝑒, 𝑣 ∈ 𝛴 +.
Solution:
The question is asking to prove that for any two strings u and v in the set of non-empty
strings Σ+, the reverse of the concatenation of those strings (uv) is the concatenation of
the reverse of those strings (vR uR). We can use the recursive definition of string
reversal to prove this statement.
First, we'll define some notation for the problem. Let Σ be the set of all characters, and
let Σ* be the set of all strings, including the empty string. Then, let Σ+ be the set of all
non-empty strings. With this notation, we can state the problem as:
4. Prove that for all u, v ∈ Σ+, (uv)R = vR uR
To prove this statement, we'll use the recursive definition of string reversal, which is
defined by the following two rules:
ο‚·
aR = a for all a ∈ Σ (the reverse of a single character is itself)
ο‚·
(wa)R = awR for all a ∈ Σ and w ∈ Σ* (the reverse of a string w followed by a
character a is the reverse of a followed by the reverse of w)
Using these rules, we can prove the statement by induction on the length of the string
u.
Base case: If the length of u is 1 (u ∈ Σ), then (uv)R = (u(vR))R. Using the second rule,
we can reverse the string u(vR) by reversing the string vR and then reversing the string
u. So, (uv)R = (vR) (uR) = vR uR.
Inductive step:
Assume that the statement is true for all strings u with a length of n, where n > 1. Now,
let u be a string with a length of n+1. Then, we can write u as u'a for some string u' and
some character a. By the definition of concatenation, we can write (uv) as (u'av). Then,
we can reverse this string by reversing the string v and then reversing the string u'a.
Using the second rule, we can reverse the string u'a by reversing the character a and
then reversing the string u'. And, by the induction hypothesis, we know that (u'R) aR =
u'Ra. Now, we can reverse the string vR and then reverse the string u'Ra, to get (uv)R
= (vR) (u'Ra) = (vR) (u'R) aR = vR (u'R) aR = vR u'RaR = vR u'R aR = vR u'R a = vR
(u'Ra) = vR uR.
So, by induction, we've proven that the statement holds for all u, v ∈ Σ+.
Finally, we have used the recursive definition of string reversal to prove that for any
two strings u and v in the set of non-empty strings Σ+, the reverse of the concatenation
of those strings (uv) is the concatenation of the reverse of those strings (vR uR)
5. To prove that (WR)R = w for all w ∈ Σ*, we can use the recursive definition of string
reversal, which is defined by the following two rules:
ο‚·
aR = a for all a ∈ Σ (the reverse of a single character is itself)
ο‚·
(wa)R = awR for all a ∈ Σ and w ∈ Σ* (the reverse of a string w followed by a
character a is the reverse of a followed by the reverse of w)
We can prove this statement by induction on the length of the string w.
Base case:
If the length of w is 0 (w is the empty string), then (WR)R = (RR) = R = w.
Inductive step:
Assume that the statement is true for all strings w with a length of n, where n > 0. Now,
let w be a string with a length of n+1. Then, we can write w as wa for some string w'
and some character a.
Then, we can reverse the string (wa)R by reversing the string a and then reversing the
string w', using the second rule.
Then, we can reverse the reversed string (wa)R by reversing the string w' and then
reversing the character a.
So, (wR)R = (w'aR)R = (aw'R)R = waR = w.
So, by induction, we've proven that the statement holds for all w ∈ Σ*.
Overall, we have used the recursive definition of string reversal to prove that for any
string w in Σ*, (WR)R = w.
6. Given the language L = {ab, aa, baa}, the following strings are in L*:
𝒂𝒃𝒂𝒂𝒃𝒂𝒂𝒂𝒃𝒂𝒂: This string can be formed by concatenating the string "ab" with itself
3 times.
ο‚·
𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂: This string can be formed by concatenating the string "aa" with
itself 3 times and concatenating it with "ab"
ο‚·
𝒃𝒂𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃: This string can be formed by concatenating the string "baaa"
with itself and concatenating it with "ab"
ο‚·
𝒃𝒂𝒂𝒂𝒂𝒂𝒃𝒂𝒂: This string can be formed by concatenating the string "baaa"
with itself and concatenating it with "aa"
A language L^n (L to the power of n) is the set of all possible strings that can be formed
by taking n concatenations of the strings in the original language L.
Given the language L = {ab, aa, baa}, the following strings are in L^4:
𝒂𝒃𝒂𝒃𝒂𝒃𝒂𝒃: This string can be formed by concatenating the string "ab" with itself 4
times.
𝒂𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂: This string can be formed by concatenating the string
"aa" with itself 4 times and concatenating it with "abab"
𝒃𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒃𝒂𝒂𝒂:
This
string
can
be
formed
by
concatenating the string "baaa" with itself 3 times and concatenating it with "abaa"
𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂𝒂𝒃𝒂𝒂𝒂:
This
string
can
be
formed
by
concatenating the string "baaa" with itself 4 times.
Note that the set of strings in L^n can be infinite, and this are just some examples of the
possible strings in L^4.
Related documents
Download