Mathematics for Computer Science Guide
Mathematics for Computer Science Guide
Math for CS
Lessons
Akshay Tiwary • 2015
Table of Contents
1 Preliminaries 1
1.1 Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 Relations and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Cardinality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 Mathematical Induction 15
2.1 The Well Ordering Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2 Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3 Pigeonhole Principle 27
3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
i
Mathematics for Computer Science Self Study 1 PRELIMINARIES
Abstract
Starting from the bottom. 1 In this document, we’ll use the notation that N = {1, 2, 3, . . .} and N∗ = {0, 1, 2, . . .}. Also,
Nm = {1, 2, . . . , m} and Nm
∗ = {0, 1, . . . , m}.
1 Preliminaries
1.1 Proofs
The following are the usual methods of proof in practice:
Remark 1.1 (Uniqueness Proofs). Some theorems assert the existence of a unique element with a particular property. To
prove a statement of this type, we need to show an element with such a property exists, and that no other element has this
property.
That is, we first show existence and then show uniqueness. To show existence we can either prove that an element which has
such a property must exist by an indirect proof or construct an example that has the required property. To show uniqueness,
we can show that if x and y both have the desired property then x = y.
Example 1.1. Show that if a and b are real numbers and a , 0, then there is a unique real number r such that ar + b = 0.
Proof. Exercise.
Exercises
Exercise 1. What’s going on here?
√ √ √ √
1 = 1 = (−1)(−1) = −1 −1 = ( −1) 2 = −1.
p
(a) Precisely identify and explain the mistake(s) in the bogus proof.
(c) Every positive real number r has two square roots, one positive and one negative. The standard convention is that the
√
expression r refers to the positive square root of r . Prove that for all positive real numbers r and s,
√ √ √
rs = r s.
1
Mathematics for Computer Science Self Study 1 PRELIMINARIES
3>2
3 log10 (1/2) > 2 log10 (1/2)
log10 (1/8) > log10 (1/4)
1/8 > 1/4.
a =b
a 2 = ab
a 2 − b 2 = ab − b 2
(a − b)(a + b) = (a − b)b
a +b = b
a = 0.
Exercise 3. Albert announces to his class that he plans to surprise them with a quiz sometime next week.
His students first wonder if the quiz could be on Friday of the next week. They reason that it can’t: if Albert didn’t give the
quiz before Friday, then by midnight Thursday they would know the quiz had to be on Friday, and so the quiz wouldn’t be a
surprise anymore.
Next the students wonder whether Albert could give the surprize quiz on Thursday. They observe that if the quiz wasn’t
given before Thursday, it would have to be given on the Thursday. Since they already know it can’t be given on Friday.
Similarly, the students reason that the quiz can’t be given on wednesday, Tuesday or Monday. Namely, it’s impossible for
Albert to give a surprise quiz next week! All the students now relax, having concluded that Albert must be bluffing. And
since no one expects the quiz, when Albert gives it on Tuesday next week, it really is a surprise!
What, if anything, is wrong with the students’ reasoning?
Exercise 4. Show that log7 (n) is either an integer or irrational, where n is a positive integer.
√ √2
Exercise 5. If we raise an irrational number to an irrational power, can the result be rational? Consider 2 and show it by
cases.
Exercise 6. Prove or disprove that there are real numbers x and y such that x is rational, y is irrational and x y is rational.
Exercise 7. Prove or disprove that if a and b are rational numbers, then ab is rational.
Exercise 8. Prove that for any n > 0, if an is even, then a is even.
Exercise 9. Prove that if a × b = n, then either a or b must be ≤ n, where a, b, n are all non-negative reals.
Exercise 10. Let n be a non-negative integer.
(a) Explain why if n2 is even, then n is even.
(c) Give an example of two distinct positive integers m, n such that n2 is a multiple of m, but n is not a multiple of m.
2
Mathematics for Computer Science Self Study 1 PRELIMINARIES
(i) log6 4,
This proof was written for an audience of college teachers, and at this point is a little more concise than desirable. Write out
a more complete version which includes an explanation at each step.
Once you have justified the steps in this proof, think about whether you have a preference for one of these proofs over the
other. Why or why not?
Exercise 14. Here is a generalization of Exercise 11 that you might not have thought of:
a 0 + a 1x + . . . + am−1x m−1 + x m
be integers. Then any real root of the polynomial is either an integer or irrational.
√
m
(a) Explain why the proposition immediately implies that k is irrational whenever k is not the mth power of some integer.
Exercise 15. The fact that there are irrational numbers a, b such that ab is rational was proved in Exercise 5 by cases.
Unfortunately, the proof was non-constructive: it didn’t reveal a specific pair (a, b) with this property. But in fact it’s not too
hard to do this: let a = 2 and b = 2 log2 3. Show that this pair (a, b) is sufficient as per the needs of the problem.
Exercise 16. Show that if r is an irrational number then there is a unique integer n such that the distance between n and r is
less than 1/2.
Exercise 17. Prove that at least one of the real numbers a 1 , a 2 , . . . , an is greater than or equal to the average of these numbers.
What method of proof did you use, and why do you think you used it?
Exercise 18. Show that if the first 10 integers are placed around a circle in any order, there exists three consecutive locations
around the circle that have a sum greater than or equal to 17.
Exercise 19. Suppose that five ones and four zeros are arranged around a circle. Between any two equal bits you insert a
zero, and between two unequal bits you insert a one to produce nine new bits. Now you remove all the original nine bits.
Show that if you iterate this procedure, you can never get nine zeroes.
Exercise 20. For n = 40, the value of the polynomial p(n) = n2 + n + 41 is not prime. But we could have predicted this based
on general principles that no non-constant polynomial can generate only prime numbers.
In particular let q(n) be a polynomial with integer coefficients. Let c = q(0) be the constant term of q.
3
Mathematics for Computer Science Self Study 1 PRELIMINARIES
(b) Show that if q is non-constant and c > 1, then as n ranges over the non-negative integers N∗ , there are infinitely many
q(n) ∈ Z that are not primes.
(c) Conclude that for any non-constant polynomial q, there must be an n ∈ N such that q(n) is not prime.
Hint: Only one easy case remains.
Exercise 21. A two person game is a game like checkers or go, in which two players Alice and Bob alternatively take turns
making moves: first Alice takes a turn and then Bob takes a turn and then Alice and Bob and so on until the game ends and
one of the is declared the winner, or the game ends in a tie. We say that Alice has a winning strategy if he can force a win,
no matter how Alice places. Another possibility is that Alice can guarantee that she does not lose (no matter how clever
Bob is, Alice either ties or wins). Remarkably it can be proved that for any two player game, either Alice has a winning
strategy, or Bob does, or both can guarantee a tie. In this question we only consider games which never result in ties, and
we assume the number of rounds is a fixed number n.
(a) Assume the game consists of two turns. First Alice takes a turn, and then Bob, and then one of them is declared the
winner. Use quantifiers to write the statement that Alice has a winning strategy. Prove that either Alice has a winning
strategy or Bob does.
(b) Prove that if the game consists of n turns for an arbitrarily large value of n, still either Alice has a winning strategy or
Bob does.
Exercise 22. Prove that if there are n ≥ 2 people at a party, then at least 2 of them have the same number of friends at the
party.
Exercise 23. Let S = x 1y1 + x 2y2 + . . . + x nyn , where x 1 , x 2 , . . . , x n and y1 , y2 , . . . , yn are two different sequences of positive
real numbers.
(a) Show that S takes its maximum value over all orderings of the two sequences when the two sequences are sorted (so
that the elements in each sequence are in non-decreasing order).
(b) Show that S takes its minimum value over all orderings of the two sequences when one sequence is sorted in non-
decreasing order and another sequence is sorted in non-increasing order.
Exercise 24. Suppose there’s a long school walkway with n lockers along one wall, all of which are initially closed. The
lockers are numbered, starting with 1 closest to the front of the hallway and going through n closest to the back.
There are n students who start out at the stront of the hallway. One by one, each student walks down the hallway. As they
walk, the student opens and closes lockers according to the following rule: the kth student "toggles" (opens if closed and
closes if opened) every kth locker. That is the kth student switches whether every kth locker is opened or closed.
After all n passes, which lockers will be open? (Hint: When you have a complex process like this one, it often helps to try
smaller cases first.) Can you prove why this is?
Exercise 25. Let’s suppose that you have a row of 120 robots numbered 1, 2, . . . , 120. The robots are lined up so that each
robot can see every higher numbered robot but can’t see any lower numbered robots.
Once the robots line up, Sal, Yang, and Keith will go down the row of robots and put either a red or a blue hat onto their
heads. The choice of hats is random, so it is possible for all the hats to be blue, for instance. The robots can’t see their own
hats, so the nth robot can only see the hats of the robots numbered n + 1 or higher.
After placing the hats on the robots, we’ll go down the row of robots, starting with robot 1 and ask each robot to guess
which color hat they are wearing. Your goal is to devise a strategy the robots can use that will maximize the number of
robots that are guaranteed to guess their own hat color correctly. You can assume that each robot can hear the guesses of all
the robots that come before it. To recap:
4
Mathematics for Computer Science Self Study 1 PRELIMINARIES
• Each robot only knows the color of the hats of the robots that come after it.
• The robots are asked which color hat they’re wearing in order, so the first robot to make a guess can see every hat
except its own and the last robot to make a guess can’t see any hats.
• You can assume that the robots can hear all of the guesses that come before them in the line.
What is the maximum number of robots that you can ensure will guess their own hat color? [I know a way to ensure at
least 80 will survive.]
Exercise 26. Can you tile the standard chess board by dominos? What if you cut out the opposite corner squares?
Exercise 27. A straight triomino is basically a 3 × 1 rectangle. An 8 × 8 chess board with one corner square removed has 63
squares. Any tiling of such a board with straight triominos must use 63/3 = 21 triominos. However when we experiment,
we cannot find a tiling of such a board using straight triominos. Is it the case that no such tiling exists?
Hint: Try coloring the triomino in a special way.
Exercise 28. Prove or disprove the following statements.
(a) You can use dominos to tile the standard chess board with adjacent corners removed.
(b) You can use dominos to tile a rectangular chess board with an even number of squares.
(c) You can use dominos to tile a chess board with all four corners removed.
Exercise 29. Prove that if a white square and a black square are removed from an 8 × 8 chess board, you can tile the remaining
squares of the chess board using dominos.
Hint: Look at Rosen page 109.
Exercise 30. Show that by removing two white squares and two black squares from an 8 × 8 chess board, you can make it
impossible to tile the remaining squares using dominos.
Exercise 31. A right triomino is an L-shaped tile made of three squares. Is it ever possible to tile an n × n chessboard missing
two opposite squares with right trominos for n ≥ 3? If so, find an n for which it is possible. If not, prove it is impossible for
n ≥ 3.
Exercise 32. Find all squares, if they exist, on an 8 × 8 chess board such that the board obtained by removing one of these
squares can be tiled using straight triominos.
Hint: First use arguments based on coloring and rotations to eliminate as many squares as possible from consideration.
Exercise 33. Draw each of the five different tetrominoes where a tetromino is a polyomino with 4 squares. For each of the
five different tetrominoes, prove or disprove that you can tile a standard chess board using these tetrominoes.
Exercise 34. Prove or disprove that you can tile a 10 × 10 chess board using straight tetrominos.
Exercise 35. Suppose that you have a 3 × 3 × 3 cube of cheese that’s subdivided into 27 1 × 1 × 1 smaller cubes of cheese. A
mouse wants to eat the cube of cheese and does so as follows: she first picks any cube to eat first, then moves to an adjacent
cube of cheese (a cube that shared a face with the cube just eaten) to eat next. Is it possible for the mouse to eat the center
cube of cheese last? If not prove it is impossible?
Hint: Colour the cubes in such a way that the mouse can only make a move from a black cube to a white cube or a white
cube to a black cube.
Exercise 36. A latin square is an n × n grid filled with the natural numbers 1 through n so that every row and column contains
each number exactly once. A symmetric latin square is one where the square is symmetric about the main diagonal – that
is, the number at the position (i, j) equals the number at the position (j, i).
Prove that in a symmetric latin square of odd side (n is odd), every number in 1 through n occurs exactly once on the main
diagonal. What can you say about symmetric latin squares of even side?
5
Mathematics for Computer Science Self Study 1 PRELIMINARIES
Exercise 37 (Malleable Encryption). An XOR enryption works as follows. Alice and Bob want to share a secrete piece of
information M with one another. Let’s assume that M is a bitstring of length n. In advance, Alice and Bob meet in private
and share a secret, randomly-generated encryption key K with one another (K is itself a bitstring of length n). When Alice
decides to send the secret message M to Bob, she computes M ⊕ K by XORing each bit of M with the corresponding bit of K.
When Bob receives M ⊕ K, he then computes the value (M ⊕ K ) ⊕ K = M and can read the message.
The string M ⊕ K appears to be truly random, so anyone who saw the bitstring M ⊕ K and didn’t know the secret encryption
key K would have absolutely no way of learning anything about M or K. Unfortunately, while the system guarantees
secrecy (no one can read the message without the key), it doesn’t guarantee integrity. Specifically, it’s possible to tamper
with the encrypted message so that the recipient receives the wrong information.
Let’s imagine that some third person (we’ll call her Eve, as is tradition) wants to interfere with communications between
Alice and Bob. We’ll assume that Eve can grab any message that Alice sends to Bob and modify it before Bob receives it,
and can do so without Bob knowing that anything unusual has happened.
Suppose Eve knows for sure that Alice is about to send Bob exactly one of two possible messages, which we’ll call M 1 and
M 2 . Eve knows what these two possible messages are, but doesn’t know which one Alice is going to send and doesn’t know
the secret key K that Alice and Bob are using to communicate. Eve wants to interfere with the communication so that Bob
receives the opposite message that Alice intended. That is, if Alice sends M 1 to Bob, Eve wants to make it seem as though
Alice sent M 2 , and if Alice sends M 2 to Bob, Eve wants to make it seem as though Alice sent M 1 . Amazingly, even though
Eve has no way of knowing which message Alice sent to Bob and doesn’t know the encryption key K, she can still tamper
with the encrypted message to accomplish this.
(a) Describe a procedure Eve can follow that will make it seem as though Alice sent the opposite of the intended message
to Bob. Remember that Eve doesn’t know which of the two messages M 1 and M 2 Alice chose to send to Bob, doesn’t
know the encryption key K, and (since XOR encryption guarantees secrecy) has no way to learn either of these pieces
of information. She only knows that Alice definitely sent one of M 1 and M 2 .
(b) Prove that the procedure that you developed in part (a) works correctly – namely, that Bob will believe Alice sent the
opposite of the message she actually sent.
Exercise 38 (Yablo’s Paradox). A logical paradox is a statement that results in a contradiction regardless of whether it is true
or false. One of the simplest paradoxes is the Liar’s paradox.2 .
Paradoxes often arise as a result of self-reference. In the Liar’s Paradox, the paradox arises because the statement directly
refers to itself. However, it’s not the only paradox that can arise from self-reference. This problem explores a paradox called
Yablo’s paradox that gives rises to many paradoxes, each of which arises from indirect self-reference.
(i) Consider the following collection of infinitely many statements numbered S 0 , S 1 , S 2 , . . . where there is a statement Sn
for each natural number n. These statements are ordered in a list with S 0 above S 1 , which is in turn above S 2 , and so
on. Suppose that for each n, the statement Sn is "All statements in this list after this one are false." Prove that every
statement in this list is a paradox.
(ii) Now consider the following modification to the paradox. Instead of having infinitely many statements, suppose that
there are m statements T0 ,T1 , . . . ,Tm where each statement Tn is "All statements in this list after this one is false".
Interestingly, these statements are all perfectly consistent with one another and do not result in any paradoxes. For
each statement in the above list, determine whether it’s true or false and explain why your choices are consistent with
one another.
Exercise 39. Which of the following are correct? If they are not correct all of the time, when are they correct?
2
2
(a) (n+1)
2 = b n2 c + n,
2 It is the statement "This statement is false."
6
Mathematics for Computer Science Self Study 1 PRELIMINARIES
n+k n
+ k2 ,
h i h i h i
(b) 2 = 2
h√ i h√ i
(c) x = bxc ,
Based on the last two examples, attempt to prove a conjecture about bnxc.
1.2 Sets
A set is accepted as a primitive notion, without definition. Notation such as a ∈ A, b ∩ c = ϕ should not be surprising.
We can consider collections of sets. If M is a collection of sets A, B, C, . . ., then these sets are elements of M.
The notions of union and intersection can be easily extended to arbitrary families of sets. If M is such a family, we define its
union ∪M to be the set of all elements x, which belong to at least one member in the family. Intersections of families are
defined similarly.
Theorem 1.1 (De Morgan). Given a set E, and a family of sets {Ai }, where i ranges over some index set I , we always have
1. E − i ∈I Ai = i ∈I (E − Ai );
S T
2. E − i ∈I Ai = i ∈I (E − Ai ).
T S
Proof. Exercise.
Theorem 1.2 (Distributive). Given a set E, and a family of sets {Ai }, where i ranges over some index set I , we always have
1. E ∩ i ∈I Ai = i ∈I (E ∩ Ai );
S S
2. E ∪ i ∈I Ai = i ∈I (E ∪ Ai );
T T
Proof. Exercise.
Consider an ordered n-tuple (a 1 , a 2 , . . . , an ). We define an ordered pair in the exercises below, and extend the definition
to ordered n-tuples in the same way way.
Definition 1.1 (Cartesian Product). Supose we have n sets A1 , A2 , . . . , An . Then the Cartesian Product of these sets is
the set
A1 × A2 × . . . × An = {(a 1 , a 2 , . . . , an ) : ai ∈ Ai for each i ∈ Nn .
Definition 1.2 (Alphabet). An alphabet is a finite nonempty set Σ whose members are called letters and with the restrictions
that Σ does not contain letters which are themselves strings beginning with other letters of Σ.
Definition 1.3 (Word). A word is any finite string of letters from an alphabet Σ.
Definition 1.4 (Language). We denote the set of all words using letters from an alphabet Σ by Σ∗ . Any subset of Σ∗ is
called a language. A special type of a language is Σn , the set of all words over Σ of length n. It is the cartesian product of n
copies of Σ.
7
Mathematics for Computer Science Self Study 1 PRELIMINARIES
For example if Σ = {a, b, c, . . . , z}, then the English language can be defined as the subset of Σ∗ consisting of words in the
latest edition of the Oxford dictionary.
The empty word or the null word is the string with no letters. It is denoted by ϵ.
We define the length of a word w made from an alphabet Σ to be the number of letters from Σ in w. We denote it by |w |.
With this notion, we can also explain the restriction in the definition of alphabet. Consider Σ = {a, b, ab}. What is the length
of the word aab?
Exercises
Exercise 40. Show that the relations (A ∪ C) ⊆ (A ∪ B) and (A ∩ C) ⊆ (A ∩ B), when combined, imply C ⊆ B. Disprove the
converse by an example.
Exercise 41. If (x, y) denotes the set {{x }, {x, y}}, prove that, for any x, y, u, v we have (x, y) = (u, v) iff x = u and y = v.
Treat this as a definition of an ordered pair.
Exercise 42. If (x, y) is defined as in the above exercise, which of the following is true? x ∈ (x, y); {x } ∈ (x, y); y ∈ (x, y);
{y} ∈ (x, y); {x, y} ∈ (x, y); {x } = (x, x ); {{x }} = (x, x ).
Exercise 43. Find some sets A and B with the desired properties. [Try to find general solutions.]
(b) A ∈ B but A 1 B.
(c) A ∈ B and A ⊆ B.
(d) A ∈ P(A).
(e) A ⊂ P(A).
Exercise 44 (Russell Paradox). A set M is said to be abnormal iff M ∈ M. A set M is normal iff M < M. Let N be the set of all
normal sets. That is N = {X : X < X }. Is N itself normal?
There is a related puzzle called the Barber’s Paradox which asks whether a barber, who only shaves those who don’t shave
themselves, shaves himself.
Exercise 45. For each n ≥ 1, let An = {x ∈ R : x < 1 + n1 }. Show that
∞
\
An = {x ∈ R : x ≤ 1}.
n=1
Exercise 46. How many ways are there to parenthesize the union of 4 sets A ∪ B ∪ C ∪ D? Try to deive a formula or some
Sn
other way to count the number of ways to parenthesize the union 2n of n sets i=1 X i . If you come up with the correct
1
recurrence, the solution to this recurrence is Cn−1 , where Cn = n+1 n and is called the nth Catalan number. Note that C n
is the number of binary trees with n + 1 nodes.
Exercise 47. Suppose that X × Y = X × Z holds for some sets X , Y , Z . Does it necessarily follow that Y = Z ?
8
Mathematics for Computer Science Self Study 1 PRELIMINARIES
Exercise 48. Let Σ = {a, b}. List all the elements of the set
A = {w ∈ Σ∗ : |w | ≤ 3}.
Exercise 49. Let P(A) denote the set of all subsets of a set A. Show that if |A| = n, then P(A) = 2n .
Exercise 50. Find P(ϕ), P(P(ϕ)), P(P(P(ϕ))), and P(P(P(P(ϕ)))).
Exercise 51. Determine which of the following are true, and which are false.
4. Now generalize the above by removing the restriction that Ai s are pairwise disjoint. Show that
[ n Xn
A ∩ A ∩ A + . . . + (−1) n
X X X
A = − A ∩ A + A ∩ . . . ∩ A .
i |A i | i j i j k i1 in
i=1 i=1 i, j,i <j i, j,k,i <j <k i 1, ...,i n ,i 1 <...<i n
but induction does not apply here. Explain why. To illustrate this point, find an example of a collection of set B 1 , B 2 , . . .
such that ni=1 Bi , ϕ for every n ∈ N, but i=1 Bi , ϕ fails.
T T∞
4. Nevertheless, the general version of De Morgan’s Law stated above is a valid statement. Provide a proof that does not
use induction.
9
Mathematics for Computer Science Self Study 1 PRELIMINARIES
Definition 1.6 (Function). A function f : A → B is a subset of A × B such that for each a ∈ A, there is a unique b ∈ B such
that (a, b) ∈ f .
Definition 1.8 (Surjective). A function f : A → B is onto or surjective if, given any b ∈ B, it is possible to find an element
a ∈ A for which f (a) = b.
Proof. Exercise.
Definition 1.9 (Identity). Let A be a set. The identity function on A is the function i A : A → A defined as i A (x ) = x for each
x ∈ A.
Note. {0, 1}10 is used to denote set of all length 10 binary strings, and {0, 1}ω is used to denote the set of all infinite binary
strings.
Exercises
Exercise 55. Suppose that f : A → B. Suppose X ⊆ A and Y ⊆ B. For each case, either prove the statement or give a
counterexample. Also prove a weaker statement, if possible.
1. Does f (X ∩ Y ) = f (X ) ∩ f (Y )?
10
Mathematics for Computer Science Self Study 1 PRELIMINARIES
Exercise 62. A binary word is a finite sequence of 0’s and 1’s. For example 110 and 1 are words of length three and one
respectively.
The basic operation of placing one word immediately after another is called concatenation. For example, the concatenation
of 110 and 1 is 1101, and the concatenation of 110 with itself is 110110.
We can extend this basic operation on words to an operation on sets of words. To emphasize the distinction between a word
and a set of words, we refer to a set of words as a language. If R and S are languages, then R · S is the language consisting of
all the words you get by concatenating a word from R with a word from S. That is
R · S = {rs | r ∈ R and s ∈ S }.
For example,
{0, 00} · {00, 000} = {000, 0000, 00000}.
Another example is D · D abbreviated as D 2 where D = {0, 1} is just the two binary digits.
In other words, D 2 is the language consisting of all the length two words. More generally, D n will be the language of length
n words.
If S is a language, the language you get by concatenating any number of copies of words in S is called S ∗ – pronounced
"S star". By convention, the empty word, ϵ is always included in S ∗ . For example {0, 11}∗ is the language consisting of all
words you can make by stringing together 0’s and 11’s. This language can also be described as consisting of the words
whose blocks of 1’s are always of even length. Finally, the language B of all binary words is just D ∗ .
A language is called concatenation-definable (c-d) if it can be constructed with finite languages and the applying the
operations of concatenation, union and complement (relative to B) to these languages a finite number of times. Note that the
∗-operation is not allowed. For this reason, c-d languages are also called "star-free languages". Lots of interesting languages
turn out to be concatenation-definable, but some very simple languages are not. This problem ends with the conclusion that
the language {00}∗ of even length words whose bits are all 0’s is not a c-d language.
(b) Show that the language consisting of the binary words that start with 0 and end with 1 is c-d.
11
Mathematics for Computer Science Self Study 1 PRELIMINARIES
(h) Explain why all c-d languages are boring. So we have proved that the set {00}∗ of even-length all zero words is not a
c-d language.
Exercise 63. The language of sets and relations may seem remote from the practical world of programming but in fact there is
a close connection to relational databases, a very popular software application building block implemented by such software
packages as MySQL. This problem explores the connection by considering how to manipulate and analyze a large data
set using operators over sets and relations. Systems like MySQL are able to execute very similar high-level instruction
efficiently on standard computer hardware, which helps program focus on high level design.
Consider a basic Web search engine, which stores information on Web pages and processes queries to find pages satisfying
conditions provided by users. At a high level, we can formalize the key information as:
• A set P of pages that the search engine knows about.
• A binary relation L (for link) over pages, defined such that p1 Lp2 iff page p1 links to p2 .
• A set E of endorsers, people who have recorded their opinions about which pages are of high quality.
• A binary relation R (for recommends) between endorsers and pages, such that eRp iff person e has recommended page
p.
• A binary relation M (for mentions) between pages and words where pMw iff word w appears on page p.
Each part of this problem describes an intuitive, informal query over the data, and your job is to produce a single expression
using the standard set and relation operators, such that the expression can be interpreted as answering the query correctly,
for any data set. Your answers should use only the set and relation symbols given above, in addition to terms standing for
constant elements of E or W , plus the following operators: ∪, ∩, − (set difference), relational image – for example, R(A) for
some set A, R(a) for some element a, relational inverse R −1 for any relation R, and relational composition which generalizes
the composition of functions:
a(R ◦ S )c is defined as ∃b ∈ B, (aSb) and (bRc).
In other words, a is related to c if startinf at a you can follow an S arrow to the start of an R arrow and follow the R arrow
and get to c.
Here is one worked example.
• Search description: The set of pages containing the word "Mathematics".
(a) The set of pages containg the word "logic" but not the word "predicate".
(b) The set of pages containing the word "set" that have been recommended by "Meyer".
(c) The set of endorsers who have recommended pages containing the ord "algebra".
(d) The relation that relates endorser e to word w iff e has recommended a page containing w.
(e) The set of pages that have at least one outgoing or incoming link.
(f) The relation that relates word w to page p iff w appears on a page that links to page p.
(g) The relation that relates word w and endorser e iff w appears on a page that links to a page that p recommends.
(h) The relation that relates pages p1 and p2 iff p2 can be reached from p1 by following a sequence of exactly 3 links.
12
Mathematics for Computer Science Self Study 1 PRELIMINARIES
1.4 Cardinality
Definition 1.10 (Equal Cardinality). The set A has the same cardinality as B if there exists f : A → B that is bijective. In
this case, we write A ∼ B.
A set S is said to be finite if there is an m ∈ N∗ such that Nm ∼ S. We denote this by stating that |S | = m. A set S is said to
be countable N ∼ S. This is because the elements can be ordered and we can say "here is the first one", "here is the second
one" and so one. A set is said to be uncountable if it is neither finite nor countable.
Exercises
Exercise 64 (Schroder – Bernstein theorem). Assume that there exists a one-one function f : X → Y and another one-one
function д : Y → X . Use the steps below to show that there exists a bijection h : X → Y and hence X ∼ Y .
The strategy is to partition X and Y into components
X = A ∪ A0 and Y = B ∪ B 0
with A ∩ A0 = ϕ and B ∩ B 0 = ϕ in such a way that f maps A onto B and д maps B 0 onto A0.
(b) Set A1 = X \ д(Y ) (what happens if A1 = ϕ?) and inductively definte a sequence of sets by letting An+1 = д( f (An )).
Show that {An : n ∈ N} is a pairwise disjoint collection of subsets of X while { f (An ) : n ∈ N} is a similar collection in Y .
(c) Let A = ni=1 An and B = ni=1 f (An ). Show that f maps A onto B.
S S
Exercise 65. Suppose that A and B are finite sets. Suppose further that |A| = |B|.
Exercise 66. Show that a set S is infinite if and only if there is a proper subset A such that there is a bijection between S and
A.
Exercise 67. Show that there is no bijection from Nm and Nn if n , m.
Exercise 68. Suppose that A is a finite set. Suppose further that |A| = m and |A| = n. Show that m = n.
Exercise 69. Suppose A and B are sets. We say that |A| ≤ |B| precisely when there is an injective function f : A → B.
(d) Show that if |A| ≤ |B| and |B| ≤ |A| then |A| = |B|.
(e) Show that |A| ≤ P(A) . Now show that |A| , P(A) Ċonclude that |A| < P(A) .4 .
13
Mathematics for Computer Science Self Study 1 PRELIMINARIES
Exercise 72. (i) If A1 , . . . , An are at most countable sets, then A1 ∪ . . . ∪ An is at most countable.
(ii) If A1 , . . . , An are all countable sets, then A1 ∪ . . . ∪ An is countable.
(iii) If An is an at most countable set for each n ∈ N, then ∪i=1 ∞ A is countable.
n
Exercise 73. Suppose that a, b ∈ R and that a < b.
3. Although using open intervals make it more convinient to produce the required bijections, it is not necessary. Show
that [0, 1) (0, 1) in two ways. First, exhibit a bijection between the two sets. Then, show that a bijection must exist
without resorting to constructing the bijection explicitly.
Exercise 74. Consider the open interval (0, 1) and let S be the set of points on the open unit square. That is S = {(x, y) : 0 <
x, y < 1}.
(a) Find a one-one function that maps (0, 1) into but not necessarily onto S.
(b) Use the fact that every real number has a decimal expansion5 to produce a one-one function that maps S into (0, 1). Is
this function onto?
an x n + an−1x n−1 + . . . + a 1x + a 0 = 0.
Said another way, a real number is algebraic if it is the root of a polynomial with integer coefficients. Real numbers that are
not algebraic are called transcendental.
√ √3 √ √
(a) Show that 2, 2 and 3 + 2 are algebraic.
(b) Fix n ∈ N. Let An be the algebraic numbers obtained as roots of polynomials with integer coefficients that have degree
n. Using the fact that every polynomial has a finite number of roots, show that An is countable.
(c) Now argue that the set of all alebraic numbers is countable. What does this imply about the transcendental numbers?
(a) Suppose C is uncountable. Show that there exists a ∈ (0, 1) such that C ∩ [a, 1] is uncountable.
(b) Now let A be the set of all a ∈ (0, 1) such that C ∩ [a, 1] is uncountable. Set α = sup(A). Is C ∩ [α, 1] uncountable?
(c) Does the statement in (a) remain true if we replace uncountable by infinite?
14
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Exercise 79. Answer the following by establishing a 1 − 1 correspondence with a set of known cardinality.
(c) Given a set B a subset A of P(B) is called an anti-chain if no element of A is a subset of any other element of A.
For example, if S = {1, 2, 3} then an anti-chain of P(S ) is {{1, 2}, {2, 3}, {1, 3}}.
Does P(N ) contain an antichain? If so construct an anti-chain of length n for any n ∈ N. Does P(N ) have an infinite
anti-chain? Does it have an uncountable anti-chain?
Exercise 80 (Euclid 2015). Let n positive integer ≥ 1. For example N4 = {1, 2, 3, 4}.
(a) Consider A = {{1, 2}, {2, 3}, {1, 4}}. Note that A is an antichain of N4 . Determine the two antichains of N4 that contain
all the elements of A and to which no other subset of N4 can be added to form a larger antichain.
(b) Suppose that n is a positive integer and that F is an antichain of Nn . For each non-negative integer k, define ak to be
the number of elements of F that contain exactly k integers. Prove that
a0 a1 a2 an−1 an
n + n + n + . . . + n + n ≤ 1.
0 1 2 n−1 n
(c) For each positive integer n, determine, with proof, the number of elements in the largest antichain of Nn .
2 Mathematical Induction
2.1 The Well Ordering Principle
Theorem 2.1 (Well Ordering). Every non-empty set of non-negative integers has a least element.
Remark 2.1. To prove that "P (n) is true for all n ∈ N" using the Well Ordering Principle:
C = {n ∈ N | P (n) is false.
• Reach a contradiction somehow – often by showing that P (n) is actually true or by showing that there is another
member of C that is smaller than n. This is the open-ended part of the proof.
Proof. Exercise.
15
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Definition 2.1 (Well-ordered set). A set of numbers is said to be well-ordered when each of its nonempty subsets has a
minimum element.
The Well-ordering Principle says, of course, that the set of non-negative integers is well ordered, but so are lots of other
sets, such as every finite set, or the sets r N of numbers of the form rn where r ∈ R+ and n ∈ N.
Well ordering commonly comes up in computer science as a method for proiving that computations don’t run forever. The
idea is to assign a value to the successive steps of a computation so that the values get smaller at each step. If the values are
from a well ordered set, then the computation can’t run forever.
Notice that a set may have a minimum element but may not be well ordered – the set of non-negative rationals is an
example.
Proposition 2.1. For any non-negative integer n, the set of integers greater than or equal to −n is well-ordered.
Proof. Let S be any nonempty set of integers ≥ n. Now add n to each of the elements in S – call this set S + n. Now S + n is
a non-empty set of non-negative integers and so it has a least element, m. It is easy to see that m − n is the least element of
S.
Corollary 2.1. Any nonempty set of integers with a lower bound is well-ordered.
Corollary 2.2. Any nonempty set of integers bounded above has a maximal element.
n
Another example of a well ordered set of numbesr is the set F of fractions that can be expressed in the form n+1 . That is
n
F={ | n ∈ N}.
n+1
The minimal element of any nonempty subset of F is simply the one with the minimum numerator when expressed in the
n
form n+1 .
k
We can define a very different well ordered set by considering N + F = {m + k+1 | m, k ∈ N}.
Proof. Given any non-empty subset of S of N + F, look at all the nonnegative integers n such that n + f is in S for some
f ∈ F. This is a nonempty set of nonnegative integers, so by the Well-ordering-principle, there is a minimum element, ns .
By definition of ns , there is an f ∈ F such that ns + f ∈ S. Since F is well-ordered, this nonempty set contains a minimum
element, call it fs . Now it is easy to verify that ns + fs is the minimum element of S.
Exercises
Exercise 81. Show that every rational number can be written in lowest terms.
Exercise 82. Show that there is no solution over positive intgers to the equation:
4a 3 + 2b 3 = c 3 .
Exercise 83. You are given a series of envelopes, respectively containing 1, 2, 4, . . . , 2m dollars. Define Property m: For
any nonnegative integer less than 2m+1 , there is a selection of envelopes whose contents add up to exactly that number of
dollars.
Use the Well Ordering Principle to prove that Property m holds for all non-negeative integers m. (How does this relate to
the binary representation of m?)
Exercise 84 (Stamp collecter’s problem). Prove that any integer greater than or equal to 8 can be represented as a sum of
non-negative integral multiples of 3 or 5.
16
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Exercise 85. Euler’s conjecture in 1769 was that there are no positive integer solutions to the equation
a4 + b 4 + c 4 = d 4 .
Integer values for a, b, c, d that satisfy this equation were first discovered in 1986. So Euler guessed wrong, but it took more
than two centuries to demonstrate his mistake.
Now consider this equation, similar to Euler’s but with some coefficients:
8a 4 + 4b 4 + 2c 4 = d 4 .
Prove that this equation really does not have any positive integer solutions.
n
Exercise 86. Use Well ordering principle to prove that n ≤ 3 3 for every nonnegative integer n.
Exercise 87. Complete the proof that ns + fs is really the least element of S as defined in the lemma above.
Exercise 88. Which of the following are well-ordered and why?
√
(a) The integers ≥ 2.
√
(b) The rational numbers ≥ 2.
Exercise 89. Prove that every finite, nonempty set of real numbers has a least element.
Exercise 90. Prove that a set of real numbers R is well ordered iff there is no infinite decreasing sequences of real numbers in
R. In other words, there is no set of numbers r i ∈ R such that
2.2 Induction
Induction is a powerful method for showing a property is true for all nonnegative integers. Induction plays a central role
in discrete mathematics and computer sicence. In fact, its use is a definining characteristic of discrete – as opposed to
continuous – mathematics.
You know the principle of induction, so here is a template for induction proofs.
Remark 2.2. To prove that "P (n) is true for all n ∈ N" using Induction:
• State that the proof uses induction. This immediately conveys the overall structure of the proof and makes it
easier to read.
• Define an appropriate predicate P (n). The predicate is called the induction hypothesis. A clearly stated hypothesis
is often the most important part of induction proofs.
• Prove that P (0) is true. This is usually easy. This is called the base case.
• Prove that P (n) implies P (n + 1) for every nonnegative integer n. This is called the inductive step.
• Invoke induction Given these facts, the induction principle allows you to conclude that P (n) is true for all nonnega-
tive n. It is usual to not mention this fact explicitly.
17
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Example 2.2. Suppose you want to install a big courtyard that is divided into unit squares. The big square will be 2n units
on a side for some undetermined number n. Suppose that you want one of the unit squares in the center to be occupied by a
statue of a wealthy potential donor, Bill. To complicate things further, suppose your unconvetional architect Frank Gehry
wants to only use special L-shaped triomino tiles. Show that there is a tiling of such a 2n × 2n courtyard with Bill in the
center.
Proof. First we let our statement be P (n) = "there is a tiling of such a 2n × 2n courtyard with Bill in the center." The base is
straightforward. But when we try to prove the induction step, we are doomed (why?).
The remedy in such situations, when it is difficult connecting the solution for n and n + 1, is to strengthen the induction
hypothesis.
The rest of the proof is left as an exercise for the reader to flesh out the details.
• Base cases other than 1: It may happen that the result you want to prove is only true for n larger than some fixed
number k. In this case you would proceed as above, using n = k as your base case and conclude that the result is true
for all n ≥ k.
• Multiple base cases: Sometimes it may happen that finding a link between P (n) and P (n + 1) is difficult, but finding
one between P (n) and P (n + 2) is easy. In that case you can prove P (n) for all n by showing P (n) implies P (n + 2) for
your inductive step, and checking P (1) and P (2) as base cases.
• Strong induction: The principle of strong induction replaces the inductive hypothesis that P (n) is true with the stronger
assumption that P (j) is true for all j ≤ n.
• Multiple Variables: Suppose you have a statement of the form "P is true for all m, n ≥ 1". You could try proving it by
first doing induction over one of the variables, then induction over the second. Which one you choose can sometimes
(but not always) make your life easier or harder, and it’s worth thinking about which way to do it before wading in.
• Mixing forwards and backwards induction: The arithmetic mean-geometric mean inequality says that if a 1 , a 2 , . . . , an
are nonnegative numbers then
1 a 1 + a 2 + . . . + an
(a 1a 2 . . . an ) n ≤ .
n
This can be proved by forward induction over the powers of two, and then backward induction to fill in the gaps! By
backwards induction, we mean showing P (n − 1) is true if P (n) is – in this case the powers of two would be the base
cases. Try it for yourself!
Remark 2.4. When working through the problems, here are the following hints:
Try small cases. Plug in small numbers. Do examples. Look for patterns. Draw pictures. Use lots of paper. Choose effective
notation. Look for symmetry. Divide into cases. Work backwards. Argue by contradiction. Consider extreme cases. Modify
the problem. Strengthen the hypothesis! Generalize. Don’t give up after 5 minutes. Don’t be afraid of a little algebra. Look
for invariants (things that don’t change when performing a move) and monovariants (things that only increase every time
or decrease every time when performing a move).
Remark 2.5. Induction is awesome and should be used to its full potential!
You will see when you try the exercises that even after using strong induction, there will still be more work to be done. This
is almost always the case. The philosophy is to try to use your induction hypothesis to its maximum potential, getting as
much out of it as you can and then hopefully the problem wil lbe more approachable.
18
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Example 2.3. There are n lamps in a room, with certain lamps connected by wires. Initially, all lamps are off. You can
press the on/off button on any lamp A, but this also switches the state of all the lamps connected to A from on to off and
vice-versa. Prove that by pressing enough buttons, you can make all the lamp on.6
Proof. We use induction on n. The base case of n = 1 is trivial (just turn the light) on. Now assume the case of n − 1 lamps.
Look at the set of n lamps and ignore some lamp A. Then by induction, we can turn the remaining lamps on by pressing
buttons on some subset of them. Now if at the end of doing this A is also on, we are done. So we can assume that A is off.
Since A was arbitrary, we can assume that by pressing a sequence of buttons, we can flip the statese of all lamps except one
that we choose. Now taking A and B to be 2 different lamps and flipping the states of first all lamps different from A and the
all lamps different from B, we can see that we can flip the states of only A and B. So this means we can flip the states of any
even number of lamps (how?). Now we have 2 cases.
• n is even: Then we are already done, since we can flip the states of any number of even lamps.
• n is odd: In this case, there must be some lamp A connected to an even number of lamps (prove this!). First press the
button on A. Now including A, an odd number of lamps are on, so an even number of lamps must remain. Flip their
states to finish the proof!
Note that instead of using the induction hypothesis once to finish off the solution, we used it once per vertex in order to get
a huge amount of information (that we can flip the states of any even set of lamps).
Here are some other tricks to keep in mind, which can help you turn the tables.
• Often you can set up your induction in more than one way, and finding the right way makes the problem simpler.
• Sometimes trying to prove more by adding a stronger hypothesis makes it easier to carry out the induction.
Exercises
Exercise 91. Bob comes into a grocery store and wants to buy a calculator for n dollars. He has an infinite number of
two-dollar coins and an infinite number of five-dollar bills. Show that for every positive integer n ≥ 4, he will be able to pay
for the calculator without requiring any change.
Exercise 92. A sequence is defined as a 1 = 1 and for n ≥ 1, an+1 = 2an + 1. What is a 300 ?
Exercise 93. Show that the equation
x 2 + y2 = zn
has a solution in positive integers x, y, z for all n ≥ 1.
Exercise 94. Show that for all integers n ≥ 2, the number 5n ends in 25.
Exercise 95. Assume x > −1. For all positive integers n, prove that (1 + x ) n ≥ 1 + nx. When does equality hold?
Exercise 96. Let f 0 = 0 and f 1 = 1, and fn+1 = fn + fn−1 for n ≥ 1. Find a closed form formula for fn .
Exercise 97. Show that ab n + cn + d is divisibly by the positive integer m given that a + d, (b − 1)c, ab − a + c are all divisible
by m.
Exercise 98. Find a formula for the following and prove it:
1 1 1
+ +...+ .
1×3×5 3×5×7 (2n − 1)(2n + 1)(2n + 3)
19
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Exercise 100. Show that for any x > 0, and any positive integer n, the following identity holds
1 1 1
x n + x n−2 + x n−4 + . . . + + + .
x n−4 x n−2 x n
Exercise 101. Prove that n various straight lines in a plane, passing through a point, divide the plane into 2n parts.
Exercise 102. Prove that n planes, passing through a point in such a way that no three of them pass through the same line
divide space into An = n(n − 1) + 2.
Exercise 103. Prove that
2n−1 (an + b n ) < (a + b) n .
Exercise 104. Simplify the polynomial
x x (x − 1) x (x − 1) . . . (x − n + 1)
1− + − . . . + (−1) n .
1! 2! n!
Exercise 105. Show that for all positive integers n:
1 × 3 × 5 × . . . × (2n − 1) 1
≤ √ .
2 × 4 × 6 × . . . × 2n 2n + 1
Exercise 106. A sequence is defined by a 1 = 1, a 2 = 2 and for n ≥ 2, an+1 = an + 2an−1 . What is the value of a 300 ?
Exercise 107. Prove that 4n − 1 is divisible by 3 for every integer n.
Exercise 108. Prove that the number 111 . . . 111(32015 ones) is divisible by 32015 .
Exercise 109 (CWMO 2008). Let an be a sequence of reals satisfying a 0 , 0, 1, a 1 = 1 − a 0 , an+1 = 1 − an (1 − an ) for all n ≥ 1.
Prove that for any positive integer n,
1 1 1
a 0a 1 . . . a n ( + + . . . + ) = 1.
a0 a1 n
Exercise 110 (IMO Shortlist 2006). The sequence of reals an is defined recursively by a 0 = −1 and for n ≥ 1,
n
X an−k
= 0.
k +1
k=0
Exercise 112. Stacy draws n lines on a sheet of paper, so that no two of them intersect. As a result the lines split the sheet
into different regions. How many such regions are there?
Exercise 113. Each of n identical in shape jars is filled with a paint to n−1
n of its volume. No two jars contain the same kind of
the paint. It is allowed to pour any amount of paint from one jar to another. Could one get the same mixture in all jars?
Paint is not disposable and there is no other empty vessels.
Exercise 114. For the following pieces of code, answer the following questions. Does the loop terminate? Why? What is the
value of y at this point? Prove these statements.
1• x = c; y = 0;
2 while (x > 0) {
3 x --;
4 y ++;
5 }
20
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
1 y = 0;
2 for (i = 0; i <= n; i++) {
3 y += 2^i;
4 }
Exercise 115. A band of n priates divide a pile of treasures between themselves. Each wants to be sure tha he gets no less
than n1 th of the pile. Find a fair way to split the pile between them (so that anyone can blame no-one but himself). The
pirates’ opinions on the size of the piles may be different.
1 1
Exercise 116. Let x ∈ R such that x + x is an integer. Prove that for every positive integer n, x n + xn is an integer.
Exercise 117. Show that for any n ≥ 2:
1 1 1
2
+ 2 + . . . + 2 < 1.
2 3 n
n
Exercise 118. Prove that 99 always ends in 01 or 99.
Exercise 119. What is the greatest number of pieces you can get by making n straight cuts through a circular pizza?
Exercise 120. Prove that
1 1
1 + √ + . . . + √ > n.
2 n
Exercise 121. Suppose that you begin with a chocolate bar made up of n squares by k squares. At each step, you choose a
piece of chocolate that has more than two squares and snap it in two along any line, vertical or horizontal. Eventually, it
will be reduced to single squares. What is the minimum number of steps required?
Exercise 122. Consider the identity:
21
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
for m, n ≥ 1. Prove it in two ways, first by induction over n, then by induction over m.
Exercise 123 (CHNMO 2010). (edited) If 0 < x 1 ≤ x 2 ≤ . . . ≤ x s , 0 < y1 ≤ y2 ≤ . . . ≤ ys satisfy the condition that
Proof. You need to know that every positive integer solution of a 2 + b 2 = c 2 where a, b, c are relatively prime can be
expressed in the form of two relatively prime numbesr m, n where a = m2 − n2 b = 2mn and c = m2 + n2 (one of them must
be even).
So we must have that x 2 , y 2 , z is a pythagorean triple and we get x 2 = p 2 − q 2 , y 2 = 2pq and z = p 2 + q 2 . Since y 2 is a
square, one of p and q must be two times a square, and the other must be an odd square. And since x, p, q themselves form a
(relatively prime) pythagorean triple, we can see that there are r and s for which x = r 2 − s 2 , q = 2rs and p = r 2 + s 2 . This
means q is even, and so q is the one that is two times a square (q = 2u 2 ) and that p is the odd ssquare (p = v 2 ).
Now q = 2u 2 = 2rs, which means that r and s are themselves perfect squares. Yet r 2 + s 2 = p = v @ which means v 2 is
expressible as fourth powers. Yet if we look at the construction of v, we see that v 2 < z 2 , which creates our infinite descent,
which is a contradiction.
Exercise 125. What is the least possible value of the smallest of 99 consecutive positive integers whose sum is a perfect cube?
Exercise 126 (CMC 2007). For each positive integer n > 1, prove that
2n 1 1 1 25
< + +...+ < .
3n + 1 n + 1 n + 2 2n 36
Exercise 127. Given T1 = 2 and Tn+1 = Tn2 − Tn + 1 for n > 0, so the sequence Tn starts with 2, 3, 7, 43, . . .. Prove that any two
distinct terms in this sequence are coprime. That is if n > m, then Tn and Tm are coprime.
Exercise 128. For the Fibonacci numbers, show:
n−1 n−2
! !
Fn = + +...
0 1
Exercise 129. Show that every positive integer can be expressed uniquely as the sum of distinct, non-consecutive Fibonacci
numbers.
Exercise 130. Prove that the nth Fibonacci number is divisible by 3 if and only if n is divisible by 4.
Exercise 131. Suppose that an is a sequence of reals with 0 ≤ ai ≤ 1 for each i. Prove that for each n ≥ 2,
n
X 1 n
≤ √ .
i=1
1 + ai 1 + na 1a 2 . . . an
Exercise 132. What is the greatest number of parts into which n circles can dissect the plane? What about n triangles?
Exercise 133 (Putnam 1995 B5). A game starts with four heaps of beans, containing 3, 4, 5 and 6 beans. The two players move
alternatively. A move consists of taking either
(a) one bean from a heap, provided at least two beans are left in that heap, or
22
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
The player who takes the last heap wins. To want the game, do you want to move first or second? [If you’re stuck, read
[Link]
2
Exercise 134. Let Fn be the nth fibonacci number. Show that Fn+1 + Fn2 = F 2n+1 .
F 2n
Exercise 135. Let Fn be the fibonacci sequence. Prove that Un = is always an integer. Also show Un+2 = Un+1 + Un .
Fn
Exercise 136. Suppose that m boxes are arranged in a row. Prove that there are n+m−1
m−1 ways of putting n identical balls in
these boxes.
Exercise 137 (USAMO 2002). Let S be a set with 2002 elements, and let N be an integer with 0 ≤ N ≤ 22002 . Prove that it is
possible to color every subset of S either blue or red so that the following conditions hold:
Exercise 138 (CHNMO/TST 2005). Let k be a positive integers. Prove that it is always possible to partition the set
{0, 1, . . . 2k +1 − 1} into two disjoint subsets {x 1 , . . . x 2k } and {y1 , . . . , y2k } so that
2k 2k
x im yim
X X
=
i=1 i=1
23
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Exercise 148 (USAMO 1978). An integer will be called good if it can be written as a sum of positive integers (not necessarily
distinct) the sum of whose reciprocals is 1. Given that the integers 33 through 73 are good, prove that every integer greater
than 33 is good.
Exercise 149. Find all polynomials P (x ) with the following property: x is rational iff p(x ) is rational.
Exercise 150 (Putnam 1971). Given that q(x ) = 3x 2 + 5x + 7, find all polynomials p(x ) with real coefficients satisfying p(0) = 0
and p(q(x )) = q(p(x )) for all real x.
n
Exercise 151. For any prime p, and any integer n ≥ p, show that p ≡ np mod p.
Exercise 152. Given a finite collection of sets, closed under union7 . Prove or disprove: there exists an element x that belongs
to at least half the sets in the collection.
Hint: If there is any set with only one element in it, the proof is immediate.
2
Exercise 153 (AUSTRIA 2009). Prove that 3n > (n!) 4 for all positive integers n.
Exercise 154 (CHNMO/TST 2008). Let a and b be positive integers with gcd(a, b) = 1, and a, b having different parities. Let
the set S have the following properties.
• a, b ∈ S;
• If x, y, z, ∈ S, then x + y + z ∈ S.
Exercise 158. Show that every positive integer is a sum of one or more numbers of the form 2r 3s , where r and s are
non-negative integers and no summand divides another. Example: 23 = 9 + 8 + 6.
Exercise 159. Show that every integer n may be written as ±12 ± 22 + . . . ± k 2 for some k and some choice of either "+" or
"−" for each term.
Exercise 160. Suppose 2n points are drawn on a circle, and n2 + 1 pairs of points are joined by an edge. Prove that at least 1
triangle is formed.
Exercise 161. Prove that for n ≥ 6, a square can be dissected into n squares, not necessarily all of the same size.
Exercise 162. For any set T whose elements are positive integers, define f (T ) to be the square of the product of the elements
of T . For example, if T = {1, 2, 5} then f (T ) = (1 × 2 × 5) 2 = 100. For any positive integer n, consider all non-empty subsets
S of {1, 2, . . . , n} that do not contain two consecutive positive integers. Prove that if one sums f (S ) over all of these subsets,
one gets (n + 1)! − 1.
Exercise 163. We call a property wacky of the positive integers as follows: 1 and 2 are wacky by definition. For any positive
integer n that is at least 3, we say that n is wacky if there is a unique way to write n as a sum of two distinct wacky numbers
smaller than n. So 3 is wacky, 4 is wacky, 5 is not wacky, 6 is wacky etc.
Prove that there are infinitely many wacky numbers.
Exercise 164. Given a sequence a 1 = 1 and for n ≥ 1, an+1 = 2an . Prove that for any positive integer k, the sequence a 1 , a 2 , . . .
becomes constant modulo k.
For example, the sequence starts 1, 2, 4, 16, 65536 which modulo 3 is 1, 2, 1, 1, 1 and it continues begin 1 modulo 3 forever.
7 That is, if A and B belong to the collection, so does A ∪ B.
24
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Exercise 165. Every road in the country of Graphsville is one way, and each pair of cities is connected by exactly one road.
Show that there is a city which can be reached by every other city either directly, or by going through at most one other city.
Exercise 166 (Hard). Let n be a positive integer. You are given n (n+1)
2 stones, divided into piles of various sizes. Each minute,
you take one stone from each existing pile, and group them together into a new pile. Prove that after enough time, you will
have exactly one pile of size i for each integer i between 1 and n.
Exercise 167 (Quicksort). Prove the correctness of the following computer algorithm to sort a list of n numbers into ascending
order. Assume that the original list is {x 0 , x 1 , . . . , x n−1 }.
For notation, Sort(j, k ) where j ≤ k sorts the elements from x j tox k −1 . In other words, to sort the entire list we call Sort(0, n).
Here is the algorithm.
• If k − j ≤ 1, do nothing.
• If k − j > 1, rearrange the elements from x j+1 through x k so that the first slots are filled with numbers smaller thn x j ,
then put in x j , and then all the numbers larger than x j . (Note that this can be done by running a pointer from the
(k − 1)th slot down and from the (j + 1)th slot up, swapping elements that are out of order. Then put x j into the slot
between the two lists.)
After this rearrangement, suppose that x j is at slot m for j ≤ m < k. Now apply Sort(j, m) and Sort(m + 1, k ).
k k +1 n
! ! !
+ +...+ .
k k k
Exercise 173. For n > 0 and d ≥ 0, how many monomials of total degree d are there in n variables? For example, when
d = n = 3, the number is 10; using cubic variables x, y, z, we find the cubic monomials
Exercise 174 (IMO 1981). Find the integer solutions (x, y) of (x 2 + xy − y 2 ) 2 = 1 that has the largest value of x 2 + y 2 subject
to the conditions that 0 ≤ x ≤ 1981 and 0 ≤ y ≤ 1981.
Follow up: what can you say about the Diophantine equation (x 2 + 4xy − y 2 ) 2 = 1?
Exercise 175. Let Fn be the nth Fibonacci number. Show that Fn and Fn+1 are relatively prime.
Exercise 176. Show that
n
n +k 1
!
= 2n .
X
k 2k
k=0
25
Mathematics for Computer Science Self Study 2 MATHEMATICAL INDUCTION
Exercise 177. Suppose n people sit in a row of n seats. They are allowed to rearrange themselves such that each person
moves by at most one seat. Find the number of ways an that they an rearrange.
Exercise 178. You and I are playing a game with raisins. We start with two non-empty piles of raisins on the table, and take
turns making moves. A move consists of eating all the raisins in one pile and dividing the second into two non-empty (and
not necessarily equal) piles. The game continues until one of us can’t move; that player loses. Show that if one of the piles
starts out with an even number of raisins then the first player can win.
Exercise 179. Given a (2m + 1) × (2n + 1) chessboard in which all four corners are black squares, show that if one removes
any white square and any two black squares, the remaining board can be covered by dominos.
Exercise 180. Let n be a positive integer and let a 1 , . . . , ak be distinct integers in the set {1, 2, . . . , n} for k ≥ 2 such that n
divides ai (ai+1 − 1) for i = 1, 2, . . . , k − 1. Prove that n does not divide ak (a 1 − 1).
Exercise 181 (Euler’s Formula)). Let G be a connected graphic drawn in the plane with v vertices and e edges that divide the
plane into f regions or "faces" (we consider the "outside" to be a face too). Show that v − e + f = 2. Prove this by induction
on the number of vertices plus edges (you may wish to consider a top-down approach).
Extra: Use this fact to determine the maximum number of "pieces" you can cut a pizza into with n straight cuts.
Exercise 182. Suppose n disks, black on one side and white on the other, are laid out in a straight line with a random
arrangement of black sides up. You are playing a game of solitaire that consists of removing a black disk and flipping over
its immediate neighbours, if any8 , if any. A game is winnable if it possible to remove all n disks. Describe all winnable
games, and devise a strategy which will win all winnable games.
Exercise 183 (COMC 2013). Alice and Bob play the following game. Two positive integers m and n are written on the board.
On each turn, a player selects one of the number on the board, erases it, and writes in its place any (positive) divisor of this
number as long as it is different from any of the numbers previously written on the board. For example if 10 and 17 are
written on the board, a player can erase 10 and write 2 in its place (as long as 2 has not appeared on the board before).The
player who cannot make a move loses. Alice goes first.
(a) Suppose m = 240 and n = 351 . Who has the winning strategy and why?
(b) Suppose m = 240 and n = 251 . Who has the winning strategy and why?
Exercise 184. Let n ≥ 4 be a positive integer. Prove that for real numbers x 1 , x 2 , . . . x n , the following inequality holds:
x1 x2 xn
+ +...+ ≥ 2.
xn + x 2 x 1 + x 3 x n−1 + x 1
Exercise 185 (USAMO 2007). Prove that for every nonnegative integer n, the number 77 + 1 is aproduct of at least 2n + 3
n
(a) an > n − n2 ;
Exercise 187 (USAMO 2010). There are n students standing in a circle, one behind the other. The students have heights
h 1 < h 2 . . . < hn . If a student with height hk is standing directly behind a student
with height hk−2 or less, the two students
are permitted to switch places. Prove that it is not possible to make more than n3 such switches before reaching a position
in which no further switches are possible.
Exercise 188 (IMO 2010). In each of the six boxes B 1 , B 2 , B 3 , B 4 , B 5 , B 6 there is initially one coin. There are two types of
operations allowed:
8 Two disks are not considered immediate neighbour if there used to be a disk between them that is now gone.
26
Mathematics for Computer Science Self Study 3 PIGEONHOLE PRINCIPLE
Type 1: Choose a nonempty box B j with 1 ≤ j ≤ 5. Remove a coin from B j and add two coints to B j+1 .
Type 2: Choose a non-empty box Bk with 1 ≤ k ≤ 4. Remove one coin from Bk and exchange the contents of Bk +1 and Bk +2 .
Determine whether there is a finite sequence of such operations that results in boxes B 1 , B 2 , B 3 ,B 4 and B 5 being empty, and
2010
box B 6 containing exactly 20102010 coins.
3 Pigeonhole Principle
3.1 Exercises
Exercise 189. Consider the numbers 1, 2, . . . , 2n. Show that among any n + 1 of them, two numbers exist such that one
divides the other.
27