



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to problem set 0 of the cs 273: intro to theory of computation course, covering topics such as binary predicates, substrings in strings without repetition, and covering an n x n chessboard with triominos. It also includes a recursive and non-recursive definition of a set s, and proofs for each solution.
Typology: Assignments
1 / 5
This page cannot be seen from the preview
Don't miss anything!




These model solutions are somewhat more complete and detailed than I really expected anyone to give. Be reassured if your style was generally similar and your proofs had the right structure for most of the problems.
An addendum, with additional comments, may be posted when I’ve read through all the homeworks.
Solution
For example, you can let P (x, y) be x < y or x = y. Many other predicates also work. But be careful that it has to work for the natural numbers, which only contain positive integers. So, for example, x ≥ y doesn’t work because both statements are true, since there is a smallest natural number. When answering questions like this, you should always explain why your example works. The explanation can often be very brief. For example, suppose that P (x, y) is x < y. Then, if you pick any natural number x, you can always find a larger natural number y. However, there isn’t any natural number which is larger than all the natural numbers. Notice that P needs to be a test, returning a boolean value. So you can’t define it to be something like x − y.
Solution
There are m(m 2 +1) + 1 substrings in x. One of these is the empty string. The other m(m+1) 2 are the non-empty substrings. There are several ways we can go about counting the non-empty substrings.
One approach is to think of the set of positions between consecutive characters in x. Counting the positions before the first character and after the last one, x has m + 1 positions. We can generate all the substrings by picking two distinct positions to be the ends of the substring. There are m + 1 choices for the first end s and m choices for the second end e 6 = s, so m(m + 1) choices for s and e. But this generates each substring exactly twice, once with s < e and once with e < s. So we need to divide the count by two, yielding m(m 2 +1). Alternatively, we can generate substrings of length ≥ 2 by picking a character s to be one end of the substring and another character e to be the other end. There are m choices for s and m − 1 choices for e 6 = s. Since we are generating each substring twice, this means m(m 2 − 1) distinct substrings of length ≥ 2. Adding on the m substrings of length 1, we get m(m 2 − 1)+ m which, after some algebra, is m(m 2 +1). Or, we can generate all substrings exactly once by choosing a starting character s and an ending character e that doesn’t precede s. If s is the ith character in the string, we have m − i + 1 choices for e. So the total number of substrings is
∑m i=1(m^ −^ i^ + 1) which is
∑m i=1 i^ which is well known (e.g. see CS 173 textbook) to equal^
m(m+1)
Here is a recursive definition of a set S containing points in the plane: Rule 1: (3, 0) is in S. Rule 2: If (x, y) ∈ S and (p, q) ∈ S, then (x − p, y) ∈ S. Rule 3: If (x, y) ∈ S, then (y, x) ∈ S. Rule 4: S is the smallest set satisfying rules 1-3. Give a non-recursive definition of the set S. Prove that your answer is correct. That is, (a) prove that your non-recursive definition accounts for all the elements of S and also (b) prove that your non-recursive definition doesn’t allow any extra elements beyond what’s in S.
Solution
S is {(x, y)|x and y are multiples of 3}. First, let’s prove by induction on n that (3n, 0) and (− 3 n, 0) are both in S, for any n ∈ N 0. The base case is that since (3, 0) is in S, we can show that (0, 0) and (− 3 , 0) are in S by applying rule 2 twice. Then, assume that (± 3 n, 0) ∈ S for all n ≤ k. Then we show (3(k + 1), 0) is in S by applying rule 2 to (3k, 0) and (− 3 , 0). Similarly, (−3(k + 1), 0) is in S. This means that (3n, 0) is in S, for any integer n. But then rule 3 implies that (0, 3 n) is in S for any integer n. And then, by applying rule 3, we can construct (3n, 3 m) for any integers m and n.
Solution
Let’s restate the claim as: if k is an integer ≥ 8, then k = 3m + 5n for some positive integers m and n. Proof by induction on k. Base: 8 = 3 + 5. 9 = 3 + 3 + 3. 10 = 5 + 5. So the claim is true for 8, 9, and 10. Induction: Suppose that the claim is true for any amount of money in the range [8, k], where k ≥ 10. That is, any integer in this range can be represented as k = 3m + 5n for some positive integers m and n. We can write k + 1 as 3 + j. Clearly j ≤ k. Since k ≥ 10, k + 1 ≥ 11 and, therefore, j ≥ 8. So j is in the range [8, k] and by the induction hypothesis, j = 3m + 5n for some positive integers m and n. Therefore k + 1 = 3(m + 1) + 5n. So the claim is true for k + 1.
Theorem. All engineers have the same color hair. Proof. Induction on the number of engineers. Base case: One engineer. Clearly all engineers in the set have the same color hair. Indution: Assume that the claim is true for all sets of n or fewer engineers. Let S be a set of n + 1 engineers. Let x and y be any two engineers in S, x 6 = y. By the inductive hypothesis, all the engineers in S − {x} have the same color hair. Similarly all the engineers in S − {y} have the same color hair. Now pick some engineer z who is in both S − {x} and S − {y}. x and z must have the same color hair, because they are both in S − {y}. Similarly y and z must have the same color hair, because they are both in S − {x}. By transitivity, x and y must have the same color hair. Since x and y were chosen arbitrarily from S, all engineers in S must have the same color hair.
Solution
The problem occurs when S contains 2 engineers. Then there is no engineer z who is in both S − {x} and S − {y}. Since this engineer provides the key connection between the hair colors of x and y, the rest of the proof can’t be repaired.
Solution
Suppose that there are n people in the room. Since people don’t shake hands with themselves and each pair of people shakes hands at most once, each person receives at most m − 1 handshakes. There are two cases, depending on whether anyone got left out of the handshaking. Case 1: Some person never shakes hands. Then none of the other people can get more than m − 2 handshakes. Each of the m people gets between 0 and m − 2 handshakes. But there are only m − 1 integers in this range. So two people must be assigned the same number, by the pigeonhole principle. Case 2: Everyone shakes hands at least once. Each of the m people gets between 1 and m − 1 handshakes. As in case 1, there are only m − 1 integers in this range. So two people must be assigned the same number, by the pigeonhole principle.