0% found this document useful (0 votes)
165 views70 pages

Emre Sermutlu CENG 124 Discrete Structures

This document contains lecture notes on discrete structures from CENG 124. It covers topics in counting principles including the union rule, product rule, permutations, combinations, binomial theorem, and counting objects in boxes. It includes examples and exercises applying these principles to problems involving selecting people or objects with certain constraints.

Uploaded by

Ay Yasemin Beril
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views70 pages

Emre Sermutlu CENG 124 Discrete Structures

This document contains lecture notes on discrete structures from CENG 124. It covers topics in counting principles including the union rule, product rule, permutations, combinations, binomial theorem, and counting objects in boxes. It includes examples and exercises applying these principles to problems involving selecting people or objects with certain constraints.

Uploaded by

Ay Yasemin Beril
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Lecture Notes On

CENG 124

Discrete Structures

Prepared by: Dr. Emre Sermutlu

Based on the book: Discrete and Combinatorial Mathematics,


Ralph P. Grimaldi, 5th ed.

Last Update: February 26, 2016


2
Week 1– Counting - I

Union Rule: |S ∪ T | = |S| + |T | − |S ∩ T |.

Exercise 1-1: How many integers in A = {1, 2, . . . , 300} are divisible by 3 but not
divisible by 7?

Product Rule: For finite sets S1 , S2 , . . . , Sk we have


|S1 × S2 × · · · × Sk | = |S1 | · |S2 | · · · |Sk |.

Exercise 1-2: Let Σ = {a, b, c, d, e, f, g} How many words of 5 letters can we make
a) With repetition?
b) Without repetitions?

Exercise 1-3: Let |S| = n, |T | = m. How many functions are there from S to T ? How
many are 1 − 1?

Permutation: A permutation of a finite set is an ordered list of its elements, with each
element occurring once.
n!
P (n, r) =
(n − r)!

Combination: A combination of n objects taken r at a time is choosing an r element


subset.  
n n!
C(n, r) = =
r (n − r)!r!

Exercise 1-4: There are 15 girls and 18 boys in a class of 33. In how many different
ways can we choose:
a) 5 students?
b) 2 boys and 3 girls?

Exercise 1-5: In how many ways can we order a group of 7 people such that
a) A and B are next to each other?
b) A and B are not next to each other?
c) A and B are next to each other but A and C are not?

Exercise 1-6: For 5 digit integers from 10000 to 99999, how many are palindromes and
what is their sum?
 
Answer: 900, 49 500 000

3
Exercise 1-7: How many 11-letter words can be made from the letters of the word
ABRACADABRA?
 
Answer: 83160

Exercise 1-8: How many n−bit binary sequences contain exactly k zeros?

Exercise 1-9: How many paths are there from one end of the chessboard to the other,
if we can only move right and up?
Binomial Theorem: For x, y ∈ R and n ∈ N, we have:
n  
X
n n r n−r
(x + y) = xy
r=0
r
     
n+1 n n
We can prove this using induction and = + , but we can also prove
r r−1 r
it by counting.
n  
X n
Exercise 1-10: Prove that = 2n . (Three different ways)
i=0
i

Exercise 1-11: We will select 4 distinct numbers from the list {−5, −4, −3, −2, −1, 1, 2, 3, 4}.
In how many ways can we do this if their product is positive?
        
4 4 5 5
Answer: + + = 66
4 2 2 4

Exercise 1-12: In how many different ways can we express 72 as a sum of 2’s and 3’s if
a) Order is not important?
b) Order is important?
Solution:
a) Possible values for number of 2’s: {0, 3, 6, 9, . . . , 36}. Possible values for number of 3’s:
{24, 22, 20, . . . , 0}. So there are clearly 13 possibilities.
b) If we use n 2’s and m 3’s, and order is important, it means we are permuting n + m
objects. But n of these and m of these can be permuted among themselves, so there are
(n + m)!
n! m!
different permutations (for this case). Therefore the answer is:
35! 34! 33! 25!
1+ + + + ··· + +1
2! 33! 4! 30! 6! 27! 22! 3!
12
X (36 − k)!
=
k=0
(2k)! (36 − 3k)!

Exercise 1-13: 6 students will sit at a round table. Anıl, Sümeyye and Tahsin are in
section 1 and Bora, İpek and Efnan are in section 2. They will sit such that nobody is
next to someone in his/her own section. In how many different ways can they do that?
Solution: 2! · 3! = 12

4
Week 2– Counting - II

Objects in Boxes: If we want to place n identical objects into k distinct boxes, there
are  
n+k−1
n
different ways. We can prove this by considering permutations of n objects and k − 1
dividers.

Exercise 2-1: How many numbers between 1 and 1000 have the property that their
digits sum to 5?
  
7
Answer: Place 5 marbles into 3 boxes,
5

Exercise 2-2: We will select 8 pizzas from 4 available types. In how many ways can we
make this choice?

Exercise 2-3: Twelve $100 bills will be distributed to 4 people.


a) In how many ways can we do this?
b) How does the answer change if each person must receive at least $200?
 
Answer: 455, 35

Exercise 2-4: a) How many ways are there to put 14 objects in 3 boxes with at least 8
objects in one box?
b) How many ways are there to put 14 objects in 3 boxes with no more than 7 objects in
one box?
c) How many numbers between 0 and 999 have the sum of their digits equal to 20?
 
Answer: 84, 36, 36

Exercise 2-5: You can buy a pizza with 5 toppings. There are 8 possibilities for toppings:
Pepperoni, ham, chicken, tuna, mushroom, shrimp, onion, olives.
a) How many different orders are possible if you buy a single pizza?
b) How many different orders are possible if you buy 3 pizzas?
 
8
Solution: a) = 56
5
   
56 + 3 − 1 58
b) Distribute 3 orders to 56 pizza types: = = 30856
3 3
563
Note: The answer = 29269.33 is close, but obviously wrong. It is not even an integer!
3!
The error is that, if two among the three pizzas are the same, we are not counting this
choice 6 times. We count it only 3 times.

5
Exercise 2-6: Find the number of solutions to x1 + x2 + · · · + x13 6 10 where
each xi is integer and xi > 0
   
10 + 14 − 1 23!
Answer: =
10 10! 13!

Exercise 2-7: Find the number of solutions to x1 + x2 + · · · + x13 = 10 where


each xi is integer and xi > 0
   
10 + 13 − 1 22!
Answer: =
10 10! 12!

Exercise 2-8: How many numbers in the set {10000, 10001, 10002, . . . , 99999} have sum
of digits equal to 20?
Solution: Distribute 20 balls to 5 containers randomly. Then subtract the cases where
one gets 10 or more. Then add cases where two gets 10.
      
24 5 14 5
− +
20 1 10 2

But this number includes the cases where the first digit is zero. So we have to find all
such distributions for 4 containers and subtract:
             
24 5 14 5 23 4 13 4
− + − − + = 4998
20 1 10 2 20 1 10 2

An easier alternative would be to put one ball to the first container, then distribute
remaining 19 randomly. This method results in:
        
23 4 13 14 4
− − + = 4998
19 1 9 10 1

Exercise 2-9: Find the number of different integers n such that 1000 6 n 6 9999 and
the sum of digits of n is 9.
(For example 3033, 6012, 1223 etc.)
       
11 12 11
Answer: = − = 165
8 9 9

Exercise 2-10: There are 7 departments in a faculty. We will choose 40 students from
the faculty, such that there will be at least 3 and at most 20 students from any department.
In how many different ways can we do this?
Solution: Give 3 to each. Distribute remaining 19 to 7 randomly, using 19 balls and 6
lines:
25!
= 177 100
19! 6!
Now subtract those cases where one gets 19 (total 22) or 18 (total 21):

177 100 − 7 − 7 · 6 = 177 051

6
Exercise 2-11: Consider all 4 digit numbers made from digits {1, 2, 3, 4, 5, 6, 7}.
How many have nondecreasing digits?
(1234, 1222, 4444, 5667 are possible, 1231, 7512, 3776, 5553 are NOT)
Solution: We can choose
  and order:
7
4 distinct numbers in = 35 different ways. (Example: 1246)
4
 
7
3 distinct numbers in 3 = 105 different ways. (Example: 1244,1224,1124)
3
 
7
2 distinct numbers in 3 = 63 different ways. (Example: 1112, 1122,1222)
2

1 number in 7 different ways. (Example: 1111)

So the answer is: 35 + 105 + 63 + 7 = 210


Second Method:
Suppose a b c d is a solution. Consider a b − a c − b d − c . All these num-
bers are positive or zero, their sum is at most 7. So this is a problem of distributing 7
balls to 5 children (one takes extra balls) such that the first gets at least 1.

(6 + 5 − 1)!
= 210
6! 4!

Exercise 2-12: We have 5 Red, 5 White and 5 Blue chips. We will arrange them in a line,
but we want all reds to be on the left of all blues. For example, RRWWRWRRWBBBWBB
is acceptable, RRWBWRWRRWBBWBB is not.
How many arrangements are there?
Solution: Place 5 Reds and 5 Blue’s. Then, fill the 11 spaces with Whites randomly.
This is like distributing 5 identical objects to 11 distinct boxes.
 
11 + 5 − 1 15!
= = 3003
5 5! 10!

Exercise 2-13: We will distribute 40 identical balls to 10 different children such that
each child gets at least 2 and at most 20 balls. In how many different ways can we do
this?
Solution: First, give 2 balls to each of the 10 children. Distribute the remaining 20 balls
to 10 children randomly. This can be done in
   
20 + 10 − 1 29
=
20 20
different ways.
Among these distributions, there are 10 cases where one child gets all 20 (total number
of 22) balls and 10 · 9 = 90 cases where one child gets 19 (total number of 21) balls. So
we have to subtract these.
 
29
− 10 − 90 = 10 014 905
20

7
Exercise 2-14: Find the number of integer solutions of the system of inequalities

x1 + x2 + x3 + x4 + x5 + x6 + x7 6 25

15 6 x1 + x2 + x3 + x4 + x5 + x6 + x7

0 6 xi

Solution: Distributing 25 or fewer items to 7 boxes is equivalent to distributing exactly


25 items to 8 boxes:
   
25 + 8 − 1 32
=
25 25
We want to distribute 15 or more, so we have to subtract the number of distributions
where the total is 14 or fewer.
Distributing 14 or fewer items to 7 boxes is equivalent to distributing exactly 14 items
to 8 boxes:
   
14 + 8 − 1 21
=
14 14
   
32 21
⇒ − = 3 249 576
25 14

8
Ordered Partitions: If a set has n elements and if n1 + n2 + · · · + nk = n, then there
are
n!
n1 !n2 ! · · · nk !
ordered partitions, where the ith partition has ni elements.

Exercise 2-15: There are 30 students in a classroom. The instructor will form 4 groups
of sizes 4, 7, 9 and 10, and give them homeworks from logic, sets, divisibility and counting.
In how many ways can this be done?

n!
Multinomial Theorem: The expression is called a multinomial coefficient
  n1 !n2 ! · · · nk !
n
and written as .
n1 n2 · · · nk
For x1 , x2 , . . . , xk ∈ R and n ∈ N we have
 
X n
(x1 + x2 + · · · + xk ) = n
xn1 1 xn2 2 · · · xnk k
x +···+x =n
n1 n2 · · · nk
1 k

Exercise 2-16: Find the coefficient of x8 in the expansion of (1 + x2 + x4 )10 .


 
10! 10! 10!
Answer: + + = 615
4! 6! 2! 8! 2! 1! 7!

Exercise 2-17: Find the coefficient of x2 y 6 z 8 in the expansion of (x − 5y + z 4 )10 .


10! (−5)6
 
Answer:
2! 6! 2!

9
10
Week 3– Logic

Proposition: A proposition is any sentence that is either true or false.


Negation: If P is a statement, the negation of P (¬P ) is the statement ”P is false.”
Let P and Q be propositions. P ∧ Q means both P and Q are true, P ∨ Q means P is
true or Q is true. (or both).
Truth Tables: We can summarize the possible values of a compound statement using
a truth table. Here, 1 means ”True” and 0 means ”False”.

P Q P ∧Q P Q P ∨Q
P ¬P 1 1 1 1 1 1
1 0 1 0 0 1 0 1
0 1 0 1 0 0 1 1
0 0 0 0 0 0

Logically Equivalent Statements: If two statements are both true or both false, we
say they are logically equivalent. For example, ¬(P ∧Q) is logically equivalent to ¬P ∨¬Q
and ¬(P ∨ Q) is logically equivalent to ¬P ∧ ¬Q.

Exercise 3-1: Show that p ∧ (q ∨ r) is logically equivalent to (p ∧ q) ∨ (p ∧ r).

Tautologies and Contradictions: A statement that is always true is called a tautology,


a statement that is always false is called a contradiction. For example, P ∨ ¬P is a
tautology, P ∧ ¬P is a contradiction.
Implication and Biconditional: The statement P → Q (P implies Q) is the statement
”If P is correct, then Q is correct”. The statement P ⇐⇒ Q (P if and only if Q) means
P and Q are logically equivalent, that is, they are either both true or both false.

P Q P →Q P Q P ⇐⇒ Q
1 1 1 1 1 1
1 0 0 1 0 0
0 1 1 0 1 0
0 0 1 0 0 1

Exercise 3-2: Construct a truth table for the following:


a) (p ∧ q) → p
b) (p → q) → (q → p)

Exercise 3-3: Show that p → q is logically equivalent to ¬p ∨ q.

11
The Laws of Logic

• ¬¬p ⇐⇒ p

• ¬(p ∨ q) ⇐⇒ ¬p ∧ ¬q
¬(p ∧ q) ⇐⇒ ¬p ∨ ¬q

• p ∨ q ⇐⇒ q ∨ p, p ∧ q ⇐⇒ q ∧ p,

• p ∨ (q ∨ r) ⇐⇒ (p ∨ q) ∨ r, p ∧ (q ∧ r) ⇐⇒ (p ∧ q) ∧ r

• p ∨ (q ∧ r) ⇐⇒ (p ∨ q) ∧ (p ∨ r), p ∧ (q ∨ r) ⇐⇒ (p ∧ q) ∨ (p ∧ r)

• p ∨ p ⇐⇒ p, p ∧ p ⇐⇒ p

• p ∨ ¬p ⇐⇒ Tautology, p ∧ ¬p ⇐⇒ Contradiction

Exercise 3-4: Simplify (p ∨ q) ∧ ¬(¬p ∧ q)

Converse: Q → P is the converse of P → Q.

Contrapositive: ¬Q → ¬P is the contrapositive of P → Q. If an implication is correct,


can we say its converse and contrapositive are also correct?

Exercise 3-5: Show that P ⇐⇒ Q is logically equivalent to (P → Q) ∧ (Q → P )

Exercise 3-6: What is the negation of P → Q?

Universal and Existential Quantifiers: ∀xP (x) means the statement P (x) is correct
for all x. ∃xP (x) means there exists at least one x for which the statement P (x) is correct.

¬(∀x P (x)) ⇐⇒ ∃x ¬P (x)

¬(∃x P (x)) ⇐⇒ ∀x ¬P (x)

Exercise 3-7: Find the negation of the following:


a) All odd numbers are prime.
b) Some 4th year students are taking this course.

Exercise 3-8: Show that P ∨ (Q ∧ R) is equivalent to (P ∨ Q) ∧ (P ∨ R)

Exercise 3-9: Prove or disprove the following:


a) ∀x ∈ R, (x + 1)2 > x2
b) ∃n ∈ Z, 5|n2 − 2
c) ∀n ∈ Z, 6|n4 − n2

12
Exercise 3-10: Let P be the statement n is a multiple of 4 and Q be n2 is a multiple
of 4. Which of the following are true?
a) P → Q
b) Q → P
c) P ⇐⇒ Q
d) ¬P → ¬Q
e) ¬Q → ¬P
 
Answer: a), e) are true, the others are false .

Exercise 3-11: Give converse and contrapositive of following statements:


a) p ⇒ (q ∧ r)
b) If x + y < 10 then x2 + y 2 < 100
Solution:
a) Converse: (q ∧ r) ⇒ p
Contrapositive: ¬q ∨ ¬r ⇒ ¬p
b) Converse: If x2 + y 2 < 100then x + y < 10
Contrapositive: If x2 + y 2 > 100 then x + y > 10

Exercise 3-12: Convert into logical notation: If he listens Shakira, he feels good. If
Fenerbahçe wins, he feels good. He feels good now, therefore either he is listening to
Shakira, or Fenerbahçe won today.
Is this correct?
 
Answer: [(p ⇒ r) ∧ (q ⇒ r)] ⇒ [r ⇒ (p ∨ q)], No

Exercise 3-13: Show that p → (q ∨ r) is logically equivalent to (p ∧ ¬q) → r


a) Using a truth table,
b) Without using a truth table.
Solution:
p q r q ∨ r p → (q ∨ r) p ∧ ¬q (p ∧ ¬q) → r
1 1 1 1 1 0 1
1 1 0 1 1 0 1
1 0 1 1 1 1 1
1 0 0 0 0 1 0
0 1 1 1 1 0 1
0 1 0 1 1 0 1
0 0 1 1 1 0 1
0 0 0 0 1 0 1

13
Fifth and seventh columns are identical.
Alternatively, we can show equivalence as:

p → (q ∨ r) ⇐⇒ ¬p ∨ (q ∨ r)
⇐⇒ (¬p ∨ q) ∨ r
⇐⇒ ¬(p ∧ ¬q) ∨ r
⇐⇒ (p ∧ ¬q) → r

Exercise 3-14: Show that (p ∨ q) → (q → q) is a tautology


a) Using a truth table,
b) Without using a truth table.
Solution:
p q p ∨ q q → q (p ∨ q) → (q → q)
1 1 1 1 1
1 0 1 1 1
0 1 1 1 1
0 0 0 1 1
Alternatively, we can show tautology as:

(p ∨ q) → (q → q) ⇐⇒ (p ∨ q) → (¬q ∨ q)
⇐⇒ (p ∨ q) → 1
⇐⇒ ¬(p ∨ q) ∨ 1
⇐⇒ 1

Exercise 3-15: For the following statements the universe is real numbers. Are they
correct? Explain.

a) ∀x∃y(x2 + y 2 = 1)

b) ∃x∀y(x2 + y 2 = 1)

c) ∃x∃y(x2 + y 2 = 1)
Solution:
a) NO.
If x = 2 there is no y ∈ R such that x2 + y 2 = 1.

b) NO.
There is no x ∈ R such that x2 + 52 = 1.

c) YES
x = 0, y = 1 is one of the possible choices satisfying x2 + y 2 = 1.

14
Exercise 3-16: Express the following in logical notation. Is the reasoning correct?

• If there is a homework on Friday, I do not go to the movies on weekend.

• If I go to the movies on weekend, I have no money left on Monday.

• I have no money left on Monday. So there was no homework on Friday.

Solution: f : There is a homework on Friday


w: I go to the movies on Weekend
m: I have some money left on Monday
The given statements are:
f −→ ¬w
w −→ ¬m
¬m −→ ¬f
The reasoning is wrong. It is possible that f is TRUE, w is FALSE and m is FALSE.
This makes the first two assumption TRUE but the conclusion FALSE.

Exercise 3-17: A student says If I miss the bus and there is an exam in the morning,
then I am in trouble. Express this in logical notation. Find the contrapositive of this
statement.
Solution:
P : I miss the bus
Q : There is an exam in the morning
R : I am in trouble
The statement is equivalent to:
(P ∧ Q) → R
Its contrapositive is:
¬R → (¬P ∨ ¬Q)
In other words, If I am not in trouble, then either I didn’t miss the bus or I did not have
an exam in the morning.

Exercise 3-18: Let m, n be positive integers. Are the following statements true or false?
(No explanation necessary)
a) ∀n ∃m [n = m2 ]
b) ∀n ∃m [m = n2 ]
c) ∃n ∃m [n = m2 ]
d) ∃n ∀m [m = n2 ]

15
Exercise 3-19: Show that [(p ∧ ¬q) ∧ r] → [(p ∧ r) ∨ q] is a tautology or provide a
counterexample.
Solution:
p q r p ∧ ¬q ∧ r (p ∧ r) ∨ q S
1 1 1 0 1 1
1 1 0 0 1 1
1 0 1 1 1 1
1 0 0 0 1 1
0 1 1 0 0 1
0 1 0 0 1 1
0 0 1 0 0 1
0 0 0 0 0 1

The statement is correct for all possible truth values of p, q, r. Therefore it is a tautology.

 
Exercise 3-20: Show that (p ∧ ¬q) ∧ [p → (q → r)] → ¬r is a tautology or provide a
counterexample.
Solution: We can solve this question with a truth table. Or, alternatively, we can do
this: If the implication is wrong, first part must be true, so p = 1, q = 0. The second part
must be false, so r = 1. This is the counterexample we want: (1, 0, 1).
The statement is NOT a tautology.

Exercise 3-21: Let A = {1, 3, 5, . . .} denote the set of all positive odd integers and
B = {2, 4, 6, . . .} the set of all positive even integers.
Are the following statements true or false? Explain!

• For all m ∈ A there exists n ∈ B such that m < n.

• There exists m ∈ A such that m < n for all n ∈ B.

• There exists n ∈ B such that m < n for all m ∈ A .

• For all m ∈ A there exists n ∈ B such that n = 4m.

Solution:

• TRUE. (Given any odd number, we can find a larger even number)

• TRUE. (1 is smaller than any positive even number)

• FALSE. (There is no even number larger than all odd numbers)

• TRUE. (Four times an odd number is an even number)

16
Exercise 3-22: Suppose that everyone who is young and healthy is happy. Are the
following claims about three different people correct? Explain.
a) A is not happy. Therefore A is not young and A is not healthy.
b) B is happy. Therefore B is young.
c) C is not happy and C is young. Therefore C is not healthy.
Solution:
a) FALSE. A is not young OR A is not healthy.
b) FALSE. B may be old.
c) TRUE. We can see this by taking the contrapositive of the given statement.
Not happy ⇒ not young OR not healthy.

Exercise 3-23: Elements in a set A may or may not have the properties P, Q, R, S. (For
example, A may be a set of integers and P denote divisible by 4 etc.) Are the following
logical inferences correct? In other words, does the conclusion follow from assumptions?
Explain your reasons.
a) If an element has property P , then it has properties Q and R. The element x has
property Q. Therefore x also has property R.
b) If an element has properties P and Q, then it has property S. The element y has
property S. Therefore y also has properties P and Q.
c) If an element has properties P, Q and R, then it has property S. The element z has
properties P, Q and S. Therefore z also has property R.
d) If an element has properties P and R, then it has properties Q and S. The element
w has property Q but it does not have the property S. Therefore w does not have the
property P or w does not have the property R.
Solution:

a. FALSE. We have no information on R.


Example: A: Positive integers, P : multiple of 6, Q: multiple of 2, R: multiple of 3.
Obviously, if an integer is multiple of 6, it is multiple of 2 and multiple of 3. But if
an integer is multiple of 2, it is not necessarily multiple of 3.

b. FALSE. Converse of a true statement is not necessarily true.


Example: A: Positive integers, P : multiple of 9, Q: multiple of 4, S: multiple of 6.
Obviously, if an integer is multiple of 9 AND 4 then it is a multiple of 6. But if an
integer is multiple of 6, it is not necessarily multiple of 9.

c. FALSE. We have no information on R.


Example: A: Positive integers, P : multiple of 5, Q: multiple of 3, R: multiple of
4, S: multiple of 30. Obviously, if an integer is multiple of 5, 3 AND 4 then it is
a multiple of 30. But if an integer is multiple of 5, 3 and 30, it is not necessarily
multiple of 4.

d. TRUE. ¬(P ∧ R) ≡ ¬P ∨ ¬R

17
Exercise 3-24: Are the following pairs of compound statements logically equivalent or
not? Explain.
a) ∀x (P (x) ∧ Q(x)) and (∀x P (x)) ∧ (∀x Q(x))
b) ∃x (P (x) ∧ Q(x)) and (∃x P (x)) ∧ (∃x Q(x))
Solution:
a) YES they are logically equivalent.
The first statement says that both P (x) and Q(x) are correct for all elements in the set.
The second statement says exactly the same thing.
b) NO they are not logically equivalent. The first statement says there is an element x for
which both P (x) and Q(x) are true. The second statement says there are two elements,
x1 , x2 such that P (x1 ) is true and Q(x2 ) is true. We do not know if x1 and x2 are the
same or not.

For example, suppose three students are sitting at a table.

a. At least one of them has passed both PHYS and MATH courses.

b. At least one of them has passed PHYS course and at least one of them has passed
MATH course.

It is clear that these two statements are not equivalent. 1) may be FALSE while 2) is
TRUE.

Exercise 3-25: Are the following pairs of compound statements logically equivalent or
not? Explain.
a) ∀x (P (x) ∨ Q(x)) and (∀x P (x)) ∨ (∀x Q(x))
b) ∃x (P (x) ∨ Q(x)) and (∃x P (x)) ∨ (∃x Q(x))
Solution:
a) NO they are not logically equivalent. The first statement says P (x) or Q(x) is true for
all elements in the set. The second statement says P (x) is true for all elements or Q(x)
is true for all elements.

For example, suppose three students are sitting at a table.

a. All of them have passed at least one of the two courses: PHYS or MATH.

b. All of them have passed PHYS course or all of them have passed MATH course.

It is clear that these two statements are not equivalent. 1) may be TRUE while 2) is
FALSE.
b) YES they are logically equivalent.
The first statement says that P (x) or Q(x) is correct for some element in the set. The
second statement says exactly the same thing.

18
Week 4– Induction

Well-Ordering Principle: Every nonempty subset of Z+ contains a smallest element.

First Principle of Mathematical Induction: Let P (n) be a proposition about the


positive integer n. If
(I) P (1) is true,

(II) P (k + 1) is true whenever P (k) is true, (for k > 1)


then the propositions P (n) are true for all positive integers.
Second Principle of Mathematical Induction: Let P (n) be a proposition about the
positive integer n. If
(I) P (1) is true,

(II) P (k + 1) is true whenever P (i) is true for every positive integer i 6 k


then the propositions P (n) are true for all positive integers.
We can modify these principles such that the induction will start from n0 rather than 1.

n
X n(n + 1)
Exercise 4-1: Show that i=
i=1
2

n
X n(n + 1)(2n + 1)
Exercise 4-2: Show that i2 =
i=1
6

Exercise 4-3: Show that a set with n elements has 2n subsets using induction.

Exercise 4-4: Show that n3 + (n + 1)3 + (n + 2)3 is divisible by 9 for all n ∈ Z+ .

n  
X n n−i i
n
Exercise 4-5: Show that (x + y) = x y
i=1
i

Exercise 4-6: Fibonacci sequence is defined as: F1 = 1, F2 = 1, Fn = Fn−1 + Fn−2 . The


first few terms are 1, 1, 2, 3, 5, 8, 13, 21, . . .. Show that the formula
" √ !n √ !n #
1 1+ 5 1− 5
Fn = √ −
5 2 2

is correct for all n.

19
Exercise 4-7: Show that the sum of the interior angles of a polygon of n sides is π(n−2).
(Hint: Start with the triangle and use induction)

Exercise 4-8: Show that 16|5n − 4n − 1

Exercise 4-9: Can we divide a class of n students into groups of 4 or 5?

Exercise 4-10: Show that 1 + 2 + 22 + 23 + · · · + 2n = 2n+1 − 1

Exercise 4-11: Prove that 5n+1 + 2 · 3n + 1 is divisible by 8 for all n ∈ N.

Exercise 4-12: Prove that 11n − 4n is divisible by 7 for all n ∈ Z+ .

Exercise 4-13: Prove that n! > 2n for n > 4.

Exercise 4-14: Show that 8n+2 + 92n+1 is divisible by 73 for n ∈ N.


Solution: n = 0 ⇒ 73 | 64 + 9
Assume it is correct for n = k, in other words 73 | 8k+2 + 92k+1 . Then

8k+2 + 92k+1 = 73p, where p is an integer

Now check the case n = k + 1:

8k+3 + 92k+3 = 8 · 8k+2 + 81 · 92k+1

= 8 · 8k+2 + 8 · 92k+1 + 73 · 92k+1

= 8 · 73p + 73 · 92k+1

Therefore 8k+3 + 92k+3 = 73q for some integer q and the claim is correct by mathematical
induction.

Exercise 4-15: Show that 4 + 10 + 16 + · · · + (6n + 4) = (n + 1)(3n + 4) for all n ∈ N.


Solution: n = 0 ⇒ 4 = 4
Assume it is correct for n = k:

4 + 10 + 16 + · · · + (6k + 4) = (k + 1)(3k + 4)

Now check n = k + 1. Add 6(k + 1) + 4 to both sides and rearrange to obtain

4 + 10 + 16 + · · · + (6k + 4) + (6k + 10) = (k + 2)(3k + 7)

Therefore the formula is correct by mathematical induction.


Exercise 4-16: Show that 23 9 · 23n−1 + 102n−1 for all positive integers n.

20

Solution: For n = 1, 9 · 22 + 101 = 46, 23 46.

Assume the claim is correct for n = k. Then 9 · 23k−1 + 102k−1 = 23p for some integer p.
For n = k + 1:

9 · 23(k+1)−1 + 102(k+1)−1 =
9 · 8 · 23k−1 + 100 · 102k−1
8 · (9 · 23k−1 + 102k−1 ) + 92 · 102k−1
=
8 · 23p + 4 · 23 · 102k−1
=
=
23q

for some integer q. Therefore by mathematical induction, 23 9 · 23k−1 + 102k−1

Exercise 4-17: Show that 10 | n5 − n for all n ∈ Z+ .


Solution: Let n = 1. We know that 10 | 0 so the statement is correct for n = 1.
Suppose it is correct for n = k, in other words, assume 10 | k 5 − k, or k 5 − k = 10p
where p is an integer.

(k + 1)5 − (k + 1) = k 5 + 5k 4 + 10k 3 + 10k 2 + 5k + 1 − k − 1


= (k 5 − k) + 5k(k 3 + 1) + 10(k 3 + k 2 )
= 10p + 5k(k 3 + 1) + 10(k 3 + k 2 )
= 10q + 5k(k 3 + 1)

Where q is an integer. Either k is even, or k 3 + 1 is even, in both cases 5k(k 3 + 1) is a


multiple of 10. Therefore
(k + 1)5 − (k + 1) = 10r
For some integer r. In other words

10 | (k + 1)5 − (k + 1) by mathematical induction.

Exercise 4-18: Show that (1 + x)n > 1 + nx where n = 1, 2, 3, . . . and x ∈ R+ .


Solution: For n = 1 we have (1 + x) > 1 + x so the statement is correct for n = 1.

Assume that it is correct for n = k, in other words:

(1 + x)k > 1 + kx

Multiply both sides by (1 + x):

(1 + x)k+1 > (1 + kx)(1 + x)

(1 + x)k+1 > 1 + kx + x + kx2


If we eliminate kx2 , the inequality will not change sides.

(1 + x)k+1 > 1 + (k + 1)x

By mathematical induction, the formula is correct for all n ∈ Z+ .

21
Exercise 4-19: Show that
1
1 · 2 + 2 · 3 + · · · + n · (n + 1) = n(n + 1)(n + 2)
3
for all n ∈ Z+ .
1
Solution: For n = 1 we have 1 · 2 = 2 = 3
· 1 · 2 · 3 or 2 = 2 so the statement is correct
for n = 1.

Assume that it is correct for n = k, in other words:


1
1 · 2 + 2 · 3 + · · · + k · (k + 1) = k(k + 1)(k + 2)
3
Add (k + 1)(k + 2) to both sides:
1
1 · 2 + 2 · 3 + · · · + k · (k + 1) + (k + 1) · (k + 2) = k(k + 1)(k + 2) + (k + 1) · (k + 2)
3  
1
= (k + 1)(k + 2) k + 1
3
1
= (k + 1)(k + 2)(k + 3)
3

By mathematical induction, the formula is correct for all n ∈ Z+ .


Exercise 4-20: Prove that 4 17n − 13n for all n > 1.

Solution: Let’s use mathematical induction. The statement is correct for n = 1. Suppose
it is correct for n = k, in other words

4 17k − 13k

Now consider n = k + 1

17k+1 − 13k+1 = 17 · 17k − 13 · 13k

= 4 · 17k + 13 · 17k − 13 · 13k



4 4 · 17k and 4 13 · (17k − 13k )

Therefore
4 4 · 17k + 13 · 17k − 13 · 13k

In other words
4 17k+1 − 13k+1

22
Week 5– Prime Numbers, Integers

Definition: If n ∈ Z+ , n > 1 and n has exactly two divisors, 1 and n, it is called a prime
number.
Theorem: (Euclid) There are infinitely many primes.

Exercise 5-1: Write an algorithm that makes a list of prime numbers up to a given
number.
The Division Algorithm: Let n ∈ Z and m ∈ Z+ . There are unique integers q and r
such that
n = mq + r 06r<m

Definition: Let a, b be integers, not both zero. A positive integer c is called a greatest
common divisor of a and b if
1) c | a and c | b
2) If d is another common divisor of a and b, then d | c.

Exercise 5-2: Prove that gcd(n, n + 2) = 1 or 2.


Theorem: If m and n are integers with n > 0 then the common divisors of m and n are
the same as common divisors of n and m mod n. Therefore gcd(m, n) = gcd(n, r) where
r = m (mod n)
Proof: Let m = nq + r. If d | m, d | n, then d | r and conversely if d | n, d | r, then
d | m. This means that, common divisors of (m, n) and common divisors of (n, r) are
identical sets.
Euclidean Algorithm
Euclidean algorithm is a very fast way of finding gcd.

Input: m, n ∈ N, not both zero


Output: gcd(m, n)
a = m, b = n
while b 6= 0 do
TEMP = a
a=b
b = TEMP mod b
return a
Theorem: Let a, b ∈ Z+ . Then, there exists a unique c ∈ Z+ that is the greatest common
divisor of a and b. Furthermore, there exist x, y ∈ Z such that c = ax + by.
Proof: Let S = {as + bt | s, t ∈ Z, as + bt > 0}. Let c be the least element of S. Let’s
divide a by c.
a = qc + r
Then r = a − qc = (1 − qx)a + (−qy)b. If r > 0, r ∈ S But also r < c which contradicts
the choice of c. Therefore r = 0 in other words c | a. Similarly, we can prove c | b.
If gcd(a, b) = 1 we say a and b are relatively prime.

23
Example: m = 49, n = 19
49 − 2 · 19 = 11
19 − 1 · 11 = 8
11 − 1 · 8 = 3
8−2·3 = 2
3−1·2 = 1
We can see that gcd(49, 19) = 1 which means they are relatively prime. Now reversing
this process we obtain:
1 = 3−1·2
= 3 − 1 · (8 − 2 · 3)
= −1 · 8 + 3 · 3
= −1 · 8 + 3 · (11 − 1 · 8)
= 3 · 11 − 4 · 8
= 3 · 11 − 4 · (19 − 1 · 11)
= −4 · 19 + 7 · 11
= −4 · 19 + 7 · (49 − 2 · 19)
= 7 · 49 − 18 · 19
Thus we have found two numbers (x, y) = (7, −18) such that 49x + 19y = 1.

Exercise 5-3: Find c = gcd(111, 81). Then find x, y ∈ Z such that 111x + 81y = c.
 
Answer: − 8 · 111 + 11 · 81 = 3

Exercise 5-4: Find two integers m, n such that


234m + 677n = 1
 
Answer: m = 298, n = −103

Exercise 5-5: a) Find the greatest common divisor of 612 and 221.
b) Find two integers x, y such that 612x + 221y = c, where c = gcd(612, 221).
Solution:
a)
612 − 2 · 221 = 170

221 − 1 · 170 = 51

170 − 3 · 51 = 17

51 − 3 · 17 = 0

gcd(612, 221) = 17

24
b)
17 = 170 − 3 · 51
= 170 − 3 · (221 − 170)
= −3 · 221 + 4 · 170
= −3 · 221 + 4 · (612 − 2 · 221)

17 = 4 · 612 − 11 · 221

Theorem: Every integer n > 1 can be written as a product of primes uniquely, up to


the order of primes.

Exercise 5-6: How many positive divisors does 240 have?

Exercise 5-7: How many positive divisors does 148500 have?


 
Answer: 96

Exercise 5-8: There are 100 prisoners in a prison, each in a separate cell. Each pressing
of a button outside opens the door if it is locked and locks the door if it is open. On
the day of a festival, the first guard presses each button to free the prisoners. Then,
the second one presses {2, 4, 6, . . .}, the third one {3, 6, 9, . . .} etc. until the 100th guard
presses number 100. Which prisoners are free?

Exercise 5-9: Find smallest integer n such that 1260n is a cube.

Exercise 5-10: Find smallest integer m such that 2m is a square and 3m is a cube.
 
Answer: 72

Exercise 5-11: (3, 5, 7) is a prime triple. Find another one if there is. Prove that there’s
no other if there is not.
 
Answer: mod 3

Exercise 5-12: You have two containers, one is a 3 liter and the other is a 5 liter
container. You have unlimited amount of water, and can transfer between the containers.
Can you obtain amounts of 1,2,4 liters? What if we begin with 3 and 6?

Exercise 5-13: Find c = gcd(128, 38). Then find x, y ∈ Z such that 128x + 38y = c.
 
Answer: − 8 · 128 + 27 · 38 = 2

Exercise 5-14: Determine the smallest square number that is divisible by 8!.
Solution: 8! = 27 · 32 · 5 · 7 ⇒ n = 2 · 5 · 7 · 8! = (24 · 3 · 5 · 7)2 = 16802

25
Exercise 5-15: Find the number of divisors of 51975.
Solution: 51975 = 33 · 52 · 7 · 11
It has 4 · 3 · 2 · 2 = 48 divisors.

Exercise 5-16: Are the following statements true or false? Here, x, y, z are integers.
Explain.
a) ∀x ∃y ∃z (x = 3y + 8z)
b) ∀x ∃y ∃z (x = 2y + 8z)
Solution: a) We can express the number 1 in terms of 3 and 8:

1=3·3−1·8

Therefore we can express any integer x in terms of 3 and 8.

x = 3 · 3x − 1 · 8x ⇒ TRUE

b) We can not express an odd integer in terms of 2 and 8. For example, if x = 5, there
is no y, z, such that 5 = 2y + 8z ⇒ FALSE.

Exercise 5-17: How many zeroes are there at the end of 128! ? Explain.
Solution: For a zero, we need 10 = 5 · 2 as a factor. There are more 2’s than 5’s, in any
factorial, so we have to count 5’s. Don’t forget that 25 and multiples contain two, 125
contain three 5’s.
     
128 128 128
+ + = 31
5 25 125

Exercise 5-18: Find two integers p, q such that 64p + 59q = 1.


Solution: Using Euclid’s algorithm

64 − 1 · 59 = 5
59 − 11 · 5 = 4
5−1·4 = 1
4−4·1 = 0

Therefore gcd(64, 59) = 1. Reverse this process to obtain:

1 = 5−1·4
= −1 · 59 + 12 · 5
= 12 · 64 − 13 · 59

So p = 12 and q = −13.

26
Week 6– Relations, Functions

Given sets S and T , a binary relation from S to T is a subset of S × T .

R = {(s, t) | s ∈ S, t ∈ T and . . .}

If s is related to t we say sRt or (s, t) ∈ R.


Let R be a relation on S, that is , R ⊆ S × S. We say R is:
Reflexive if (x, x) ∈ R for all x ∈ S

Symmetric if (x, y) ∈ R implies (y, x) ∈ R

Antisymmetric if (x, y) ∈ R and (y, x) ∈ R implies x = y

Transitive if (x, y) ∈ R and (y, z) ∈ R implies (x, z) ∈ R

Exercise 6-1: Let S = {1, 2, 3, 4, 5}. Find a relation R on S that is symmetric, transitive,
not reflexive and not anti-symmetric.
 
Answer: {(1, 2), (2, 1), (1, 1), (2, 2)}

Exercise 6-2: Let S = {1, 2, 3, 4, 5}. Find a relation R on S that is anti-symmetric,


reflexive, not transitive and not symmetric.
 
Answer: {(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (1, 2), (2, 3)}

Equivalence Relations: A relation R on a set A is called an equivalence relation if it is


reflexive, symmetric and transitive.
If R is an equivalence relation, we write a ∼ b (a is equivalent to b) instead of aRb.
Let ∼ be an equivalence relation on a set S. For each s ∈ S we define the equivalence
class of s as:

[s] = {t ∈ S | t ∼ s}

Theorem: The following are logically equivalent:


I) s ∼ t
II) [s] = [t]
III) [s] ∩ [t] 6= ∅

Theorem: An equivalence relation determines a partition, and a partition determines


an equivalence relation.

27
Exercise 6-3: For the following questions, determine whether the given relation is re-
flexive, symmetric, transitive, anti-symmetric:
a) The relation R is defined on the set of lines on the plane as L1 RL2 if L1 ⊥L2 .
 
Answer: Symmetric

b) The relation R is defined on the set of lines on the plane as L1 RL2 if L1 k L2 .


 
Answer: Reflexive, symmetric, transitive.

c) The relation R is defined on the set of people as p1 Rp2 if p1 and p2 have a common
parent.
 
Answer: Reflexive and symmetric.

d) R ⊆ Z × Z, mRn if m = −n.
 
Answer: Symmetric.

e) R ⊆ R × R, xRy if |x − y| < 1.
 
Answer: Reflexive and symmetric.

f ) R is a relation on P(S) for some set S, (A, B) ∈ R if A ⊆ B.


 
Answer: Reflexive, antisymmetric, transitive.

g) R is a relation on N, (m, n) ∈ R if m | n.
 
Answer: Reflexive, antisymmetric, transitive.

Exercise 6-4: A relation R is defined on the Cartesian plane as (x, y)R(z, w) if xw = yz.
Is this an equivalence relation?
 
Answer: Yes

Exercise 6-5: Let n = abcd denote a four digit number.


a) Show that 9|n if and only if
9|a + b + c + d
b) Show that 11|n if and only if
11|a − b + c − d
 
Answer: Consider n in mod 9 and mod 11.

28
Exercise 6-6: Consider the set S = {1, 2, 3, . . . , 20} on the number line. Define a re-
lation R on S as follows: two numbers x, y are related if |x − y| 6 2. For example,
(2, 3) ∈ R, (2, 4) ∈ R but (2, 5) ∈
/ R. Is this relation reflexive? Is it symmetric? Is it
antisymmetric? Is it transitive?

Solution: The relation R is:


Reflexive, because |x − x| = 0 6 2
Symmetric, because if |x − y| 6 2 then |y − x| 6 2
NOT Antisymmetric, because (2, 3) ∈ R and (3, 2) ∈ R.
NOT Transitive because (2, 4) ∈ R and (4, 6) ∈ R, but (2, 6) ∈
/ R.

Exercise 6-7: Let S be the set of real numbers [−1, 1]. Consider the relation R on S
defined by:

(x, y) ∈ R if x2 + y 2 = 1

a) Is this relation Reflexive?


b) Is this relation Symmetric?
c) Is this relation Antisymmetric?
d) Is this relation Transitive?

Explain your answers.


Solution:
a) 12 + 12 6= 1 ⇒ this relation is NOT Reflexive.
b) If x2 + y 2 = 1 then y 2 + x2 = 1 ⇒ this relation is Symmetric.
c) (1, 0) ∈ R and (0, 1) ∈ R ⇒ this relation is NOT Antisymmetric.
d) (1, 0) ∈ R and (0, −1) ∈ R but (1, −1) ∈
/R ⇒ this relation is NOT Transitive.

Exercise 6-8: Let S be the set of integers {2, 3, 4, 6, 8, 12, 16, 24, 48, 72, 96}. Consider
the relation R on S defined by:

(m, n) ∈ R if m | n

a) Is this relation Reflexive?


b) Is this relation Symmetric?
c) Is this relation Antisymmetric?
d) Is this relation Transitive?

Explain your answers.


Solution:
a) m | m ⇒ this relation is Reflexive.

29
b) 2 | 4 but 4 - 2 ⇒ this relation is NOT Symmetric.
c) If m | n and n | m at the same time, then m = n ⇒ this relation is Antisymmetric.
d) If k | m and m | n then obviously k | n ⇒ this relation is Transitive.

Exercise 6-9: Consider the students in our University. Define a relation between them
as follows: If their birthdays (just the day and month) is 5 days or less apart, they are
related.
For example, suppose you were born on December 3. Then you will be related to
people born between November 28 and December 8 (inclusive). You will NOT be related
to someone born on January 10, or December 9.
a) Is this relation Reflexive?
b) Is this relation Symmetric?
c) Is this relation Anti - Symmetric?
d) Is this relation Transitive?
e) Is this relation an Equivalence relation?
Solution: a) YES, everybody is born on the same date with himself/herself.
b) YES, if x is related to y, obviously, y is related to x.
c) NO (for the same reason)
d) NO, if x is related to y and y is related to z, x is not necessarily related to z. For
example, their birthdays may be on 5th, 8th and 11th of the month.
e) NO, not transitive.

FUNCTIONS
A function f : A −→ B gives one and only one output from B for each input from A.
The set A is called domain of f .
Composition: Function composition is defined as (f ◦ g)(x) = f (g(x)).
In general f ◦ g 6= g ◦ f but (f ◦ g) ◦ h = f ◦ (g ◦ h). (Function composition is associative
but it is not commutative)
One–to–one Functions: If f (x1 ) = f (x2 ) ⇒ x1 = x2 then f is one-to one.

Onto Functions: If there exists an x ∈ A for all y ∈ B such that f (x) = y then f is
onto.

Exercise 6-10: Find functions f : N → N that are:


a) One-to-one and onto.
b) One-to-one but not onto.
c) Onto but not one-to-one.
d) Not one-to-one and not onto.

Bijections: If a function is one–to–one and onto, we call it a one–to–one correspondence


or a bijection.

30
Exercise 6-11: Let f : B → C, g : A → B, f ◦ g : A → C. Either show that the
following propositions are true, or give counterexamples:
a) If f ◦ g is one-to-one, then, f is one-to-one.
b) If f ◦ g is one-to-one, then, g is one-to-one.
c) If f ◦ g is onto, then, f is onto.
d) If f ◦ g is onto, then, g is onto.

Theorem: Let f : A → B and g : B → C.


a) If f and g are one-to-one, then g ◦ f is one-to-one.
b) f f and g are onto, then g ◦ f is onto.

Theorem: A function f : A → B is invertible if and only if it is one-to-one and onto.

Theorem: If f : A → B and g : B → C are invertible, then g ◦ f : A → C is invertible


and
(g ◦ f )−1 = f −1 ◦ g −1

Theorem: Let f : A → B where A, B are finite sets with |A| = |B|. Then, the following
are equivalent:
a) f is one-to-one.
b) f is onto.
c) f is invertible.

Exercise 6-12: Let f : [0, 2] → [−4, 0], f (x) = x2 − 4x. Find the inverse of f .

 
−1
Answer: f (x) = 2 − 4 + x

Exercise 6-13: For the following questions, describe a bijection (one–to–one correspon-
dence) between the two given sets:
a) 40–bit sequences containing exactly 23 zeros and possible paths from (0, 0) to (17, 23)
consisting of right and up steps of length 1.
b) n–bit sequences and all subsets of a set containing n elements.
c) 20–bit sequences containing exactly 4 one’s and different ways of distributing 16 mar-
bles to 5 different kids.
d) 110–bit sequences with exactly 10 ones and solutions over N to the equation x1 + x2 +
· · · + x10 6 100

Exercise 6-14: Let A = {1, 2, 3} and B = {a, b}.


a) How many functions are there from A to B?
b) How many one-to-one functions are there from A to B?
c) How many onto functions are there from A to B?
d) How many one-to-one onto functions are there from A to B?

Exercise 6-15: Same question, this time for |A| = m and |B| = n (Number of elements).

31
Exercise 6-16: Let A = {1, 2, 3, . . . , 10} and B = {1, 2, 3, . . . , 12}. How many one-to-
one functions are there from A to B such that f (1) = 1?
 
11!
Answer: 1 · 11 · 10 · 9 · · · 3 =
2!

Exercise 6-17: Let A = {1, 2, 3, . . . , 10} and B = {1, 2, 3, . . . , 12}. How many functions
are there from A to B such that f (1) is even?
 
9
Answer: 6 · 12

Exercise 6-18: The function f : N → N is given by f (n) = 2n . Is this function one-to-


one? Is it onto? Explain.
Solution: This function is one-to-one. Clearly, if n1 6= n2 then 2n1 6= 2n2
In other words f (n1 ) 6= f (n2 ).
This function is NOT onto. There is no n ∈ N such that 2n = 3 or 2n = 5, 6, 7, 9 etc.

Exercise 6-19: Let A = {3, 6, 9, . . . , 99} and B = {2, 4, 6, . . . , 100}.


a) How many functions are there from A to B?
b) How many one-to-one functions are there from A to B?
c) How many functions are there from A to B that take multiples of 10 to multiples of
10? (For example, f (30) = 20, f (60) = 60 etc.)
Solution: a) 5033

50!
b) = 50 · 49 · · · 18
(50 − 33)!

c) 103 5030

Exercise 6-20: a) Find a function f : Z → Z such that f is one-to-one but not onto.
b) Find a function g : Z → Z such that g is onto but not one-to-one.
Solution: Many different solutions are possible. An example is:
a) f (n) = 2n
(
n/2 if n is even
b) g(n) =
(n + 1)/2 if n is odd

32
Week 7– Pigeonhole Principle

If a finite set S is partitioned into k sets, then at least one of them has

d|S|/ke

or more elements.
Example: A sack contains 50 marbles of 4 different colors. There must be at least 13
marbles of the same color.

Exercise 7-1: How many times must we roll a single die to get the same score n times?
 
Answer: 6(n − 1) + 1 = 6n − 5

Exercise 7-2: Let A be a 10–element subset of {1, 2, 3, . . . , 50}. Show that A has two
different 4–element subsets the sums of whose elements are equal.
  
10
Answer: Consider
4

Exercise 7-3: Show that in any set of 301 integers there must be a pair (m, n) such that
300|m − n.
 
Answer: Use pigeonhole principle

Exercise 7-4: We select 5 points from (the interior of) an equilateral triangle with side
length 1. Show that there are at least two whose distance is less than 1/2.

Exercise 7-5: Show that if any 14 integers are selected from the set S = {1, 2, 3, . . . 25}
there are at least two whose sum is 26.

Exercise 7-6: Assume a country has a population of 74 million. There are 100 cities
and 20 football teams in this country. Everyone lives in a city and supports one team.
We can certainly find 2 or 3 people who have the same birthday, live in the same city and
support the same team.
What is the maximum number of such people that we can always find?
Solution: There are 74 million people and 366 × 100 × 20 = 736 000 categories. If we
distribute all people there will be
74 000 000
= 101.09
736 000
people per category on average.
d101.09e = 102
By pigeonhole principle, at least one category will certainly contain 102 people.

Exercise 7-7: There are 4000 students in a university. Can we say with certainty that
there are 12 students with the same birthday? Explain.

33
Solution: NO.
366 × 11 = 4026 > 4000. Therefore it is possible to distribute 4000 people to 366 groups
such that each group contains 11 or fewer people.

Exercise 7-8: There are n > 2 students in a classroom. Prove that there will always be
two students who have the same number of friends in the class.
Note: The relation is a friend of is symmetric. In other words, if x is a friend of y
then y is a friend of x.

Exercise 7-9: A very large number of students take an examination. Their grades are
integers in the range [0, 100]. We randomly select 2015 groups of students. Each group
consists of 5 students. Show that we can always find 5 groups with exactly the same
average grade.
Solution: Note that the object of interest is the group, not the student. The possible
values for group average are:

{0, 0.2, 0.4, 0.6, . . . , 99.6, 99.8, 100.0}

There are 501 different possibilities. It is easier to see this if we look at the sum of group’s
grades, where the possibilities are:

{0, 1, 2, . . . , 499, 500}

This makes 501 holes and 2015 pigeons. Therefore there are
 
2015
= d4.02e = 5
501

groups with the same average by pigeonhole principle.

Exercise 7-10: We choose n different 3-digit numbers randomly. We claim with certainty
that there are at least two among them such that their difference is a 3 digit number with
identical digits. (Such as 111,222, etc)
What can you say about n?
Solution: Consider all these n numbers modulo 111. Clearly, there are 111 categories:
{0, 1, 2, . . . , 110}. Therefore if
n > 112
there are at least two numbers in the same category.
These two numbers are different, so their difference cannot be 0. Therefore it must be
a positive multiple of 111.

Exercise 7-11: We randomly place 13 squares of side length 1 inside a circle of radius
2. Show that at least two of the squares intersect.
Solution: A circle of radius 2 has area 4π = 12.56 < 13. These thirteen unit squares
have a total area of 13. Therefore at least two squares must intersect.

34
Week 8– Inclusion and Exclusion

The Principle of Inclusion and Exclusion: Consider a set S with |S| = N and con-
ditions c1 , c2 , . . . , cm on the elements of S. The number of elements of S that satisfy none
of the conditions ci is given by:

N (c1 c2 . . . cm ) = N
−[N (c1 ) + · · · + N (cm )]
+[N (c1 c2 ) + · · · + N (cm−1 cm )]
−[N (c1 c2 c3 ) + · · · ]
..
.
m
(−1) N (c1 c2 . . . cm )

Proof: Consider an element that satisfies r of these conditions. Then, we are adding it

     
r r r r
 r
1−r+ − + · · · (−1) = 1 + (−1)
2 3 r

times. That is, 0 times.

Exercise 8-1: Determine the number of positive integers n where 1 6 n 6 100 and n is
not divisible by 2, 3 or 5.

 
Answer: 100 − 50 − 33 − 20 + 16 + 10 + 6 − 3 = 26

Number of Elements in Set Intersections


How can we find the number of elements in A1 ∪ A2 ∪ · · · ∪ An ?
Add all the sets, then subtract intersections of two sets, then add intersections of three
sets etc.

Exercise 8-2: Find the number of integers in {1, 2, . . . , 1000} that are divisible by 6,7
or 9.
|D6 ∪ D7 ∪ D9 | = |D6 | + |D7 | + |D9 | − |D6 ∩ D7 | − |D6 ∩ D9 | − |D7 ∩ D9 | + |D6 ∩ D7 ∩ D9 |
= |D6 | + |D7 | + |D9 | − |D42 | − |D18 | − |D63 | + |D126 |

Exercise 8-3: In how many ways can we divide 12 students into 3 sets with one set
having 2 and others having 5 students?
 
Answer: 8316

35
Exercise 8-4: In how many different ways can we factorize 156009, where each factor is
greater than 1 and order is not important?(Hint: 156009 = 3 · 7 · 17 · 19 · 23)
 
Answer: 51 = 15 + 25 + 10 + 1

Exercise 8-5: In how many ways can three x’s, three y’s and three z’s be arranged so
that no consecutive triplet of the same letter appears?
 
9! 7! 5!
Answer: −3 + 3 − 3! = 1314
3! 3! 3! 3! 3! 3!

Exercise 8-6: How many numbers from the set S = {1000, 1001, . . . , 9999} have at least
one digit 0, at least one 8 and at least one 9?
 
4 3 3 4 4 3 4
Answer: 9000 − 9 − 8 · 9 − 8 · 9 + 8 + 8 + 7 · 8 − 7 = 150

Exercise 8-7: In how many different ways can we distribute 15 identical marbles to 5
different children such that each child has at least one and at most 4 marbles?
         
14 5 10 5 6
Answer: − + = 101
10 1 6 2 2

Exercise 8-8: On a graph, we will connect 5 distinct vertices with 4 edges such that no
vertex will be isolated. In how many different ways can we do this?
           
10 5 6 5 3 5 1 5 0 5 0
Answer: 2 − 2 + 2 − 2 + 2 − 2 = 768
1 2 3 4 5

Exercise 8-9: Six married couples will be seated at a circular table. In how many ways
can we do this such that no wife sits next to her husband?
 
Answer: 12 771 840

Derangements
In a derangement, nothing is in its natural place.

Exercise 8-10: Find the number of permutations of n such that no number is in its
correct place for n = 2, 3, 4, 5.
 
Answer: 1, 2, 9, 44

The general formula for the number of derangements of n objects is:


n
X (−1)k
n!
k=0
k!

36
Exercise 8-11: A secretary mails 10 letters without checking the envelopes for correct
address. What is the probability that all letters are sent to wrong locations?

         
10 10 10 1
Answer: 10! − 9! + 8! + · · · + 0! /10! ≈
1 2 10 e

Exercise 8-12: If we distribute 9 exam papers to 9 students randomly, what is the


probability that none of them receives his/her own paper?

       
9 9 9 9
9! − 9 · 8! + · 7! − · 6! + · · · + · 1! − · 0!
2 3 8 9
If we divide this by the total number of distributions 9!, we obtain
1 1 1 1 1
1−1+ − + ··· + − ≈
2! 3! 8! 9! e
1
The case where at least one gets correct paper has probability ≈ 1 − e

Exercise 8-13: How many numbers from the set S = {1, 2, . . . , 1000} are divisible by at
least one of the numbers 3, 5 or 11?
 
Answer: 333 + 200 + 90 − 66 − 30 − 18 + 6 = 515

Exercise 8-14: Consider all strings of 4 letters made of letters {v, w, x, y, z}. Some
examples are xyvw, xxyy, zyvz. How many of them contain at least one x, at least one y
and at least one z?
 
4 4 4 4
Answer: 5 − 3 · 4 + 3 · 3 − 2 = 84

Exercise 8-15: Turkish alphabet has 29 letters, {A, B, C, . . . , Z}. Clearly, there are 29!
permutations of this set. How many of these permutations do not contain any of the
words AYŞE, MERT, NUR or CANSU?
Solution: The number of permutations is:

29! (All permutations)


−26! (Contains AYŞE)
−26! (Contains MERT)
−27! (Contains NUR)
−25! (Contains CANSU)
+24! (Contains both AYŞE and NUR)
+22! (Contains both MERT and CANSU)

37
Exercise 8-16: 8 students, Nilay, Özgür, Arda, Cansu, Kübra, Merve, Mert and Gizem
will sit around a circular table.

• Arda and Mert want to sit next to each other.

• Merve and Nilay do NOT want to sit next to each other.

• Cansu and Kübra do NOT want to sit next to each other.

• Merve and Cansu do NOT want to sit next to each other.

In how many different ways can they be seated?


Solution: Consider Arda and Mert as a single person. Thus, there are 7 persons, but
this is a circular table, so there are a total of 6! arrangements.
Now we have to subtract cases where M-N, C-K or M-C are together, add the cases
both M-N and C-K, or both M-N and M-C or both C-K and M-C are together, (be careful
at this point, M-N+C-K is two couples, M-N+M-C is a triple) and then subtract cases
where all three are together.
Then, we have to multiply by 2 because Arda and Mert can exchange places. So the
answer is:
 
2 · 6! − 2 · 5! − 2 · 5! − 2 · 5! + 4 · 4! + 2 · 4! + 2 · 4! − 2 · 3! = 360

38
Week 9– Stirling Numbers

The number of different ways to distribute m distinct objects to n identical containers,


with no container left empty is S(m, n)

Exercise 9-1: We will form 3 teams from a set of 5 students. In how many different
ways can we do this? (Students are distinct, teams are not)

m\n 1 2 3 4 5 6
1 1
2 1 1
3 1 3 1
4 1 7 6 1
5 1 15 25 10 1
6 1 31 90 65 15 1
If we construct this table’s a few rows carefully, we will notice that

S(m, n) = S(m − 1, n − 1) + nS(m − 1, n)

This can be solved to give:


n  
1 X k n
S(m, n) = (−1) (n − k)m
n! k=0 n−k

Exercise 9-2: How many onto functions are there from A to B?


For |A| = m, |B| = n, there are n!S(m, n) onto functions from A to B. (If m > n).

Another way to express the same formula is:


n  
X
k n
(−1) (n − k)m
k=0
n−k

Exercise 9-3: In how many ways can we distribute 7 distinct problems to 4 distinct
students?
         
4 7 4 7 4 7 4 7
Answer: 4 − 3 + 2 − 1 = 8400
4 3 2 1

39
Exercise 9-4: There are 9 students in a class, Ayça, Batuhan, Çag̃atay, Damla, Elif,
Turaç, Ug̃ur, Volkan, Zehra. We will form 4 project groups from these students. Each
group may contain at least 1 and at most 6 students. In how many different ways can we
do this if
a) Projects are identical?
b) Projects are distinct?
Solution: We can think of this problem as the number of onto functions from a 9 element
set to a 4 element set.
Extend the Stirling table up to 9th level using the formula
S(m, n) = S(m − 1, n − 1) + nS(m − 1, n):

m\n 1 2 3 4 5 6
1 1
2 1 1
3 1 3 1
4 1 7 6 1
5 1 15 25 10 1
6 1 31 90 65 15 1
7 1 63 301 350 140 21 1
8 1 127 966 1701 1050 · · ·
9 1 255 3025 7770 · · ·
So:
a) 7770
b) 4! 7770 = 186 480
Second Method:
We can distribute students to subsets as follows:
  
8 6
1+2+3+3: 9 /2 = 2520 ways
2 3
   
9 7 5
2+2+2+3: /3! = 1260 ways
2 2 2
  
9 5
1+1+3+4: = 1260 ways
4 3
   
9 5 3
1+2+2+4: /2 = 1890 ways
4 2 2
  
9 4
1+1+2+5: = 756 ways
5 2
 
9
1+1+1+6: = 84 ways
6

Total is: 2520 + 1260 + 1260 + 1890 + 756 + 84 = 7770 different ways.

40
Exercise 9-5: 6 students, A, B, C, D, E, F go to a cafe where there are 3 empty tables.
They take seats such that no table is left empty. In how many different ways can they do
this? (Tables are identical)
Solution:    
6 3 6 3 6
3 − 2 + 1
1 2
= 90
3!

Second Method: We can distribute 6 elements into 3 sets as 1 − 1 − 4, 1 − 2 − 3, or


2−2−2   
6 4
    
6 6 3 2 2
+ + = 90
4 3 2 3!

Exercise 9-6: 5 students, A, B, C, D, E go to a cafe where there are 3 empty tables. One
is near the cashier, the second is in the middle and the third is near the window. They
take seats such that no table is left empty. In how many different ways can they do this?
Solution:
35 − 3 · 25 + 3 · 15 = 150

Second Method: We can distribute 5 elements into 3 sets as 1 − 1 − 3 or 1 − 2 − 2

  
5 3
 
5 2 2
+ = 25
3 2!

Now we have to multiply this by 3! because tables are distinct.

25 · 3! = 150

Exercise 9-7: How many positive integers n less than 900 satisfy gcd(n, 900) = 1?
Solution:
900 900 900 900 900 900 900
900 − − − + + + −
2 3 5 2·3 2·5 3·5 2·3·5
= 240

41
Exercise 9-8: How many words of seven letters composed of the set {a, b, c, d, e} contain
all five symbols?
Solution:        
7 5 7 5 7 5 7 5 7
5 − 4 + 3 − 2 + 1
1 2 3 4

= 16800

OR

 
5 7!
{a, b, c, d, e} + two identical letters, for example a, a : = 4200
1 3!

 
5 7!
{a, b, c, d, e} + two distinct letters, for example a, b : = 12600
2 2!2!

4200 + 12600 = 16800

Exercise 9-9: Determine the number of onto functions from A = {1, 2, 3, 4, 5, 6} to


B = {a, b, c, d}.
     
6 4 6 4 6 4
Solution: 4 − ·3 + ·2 − · 16 = 1560
1 2 3

Exercise 9-10: We will form 3 teams from 10 distinct workers. In how many different
ways can we do this? (Each team contains at least one worker)
Solution: Using Stirling numbers on the table:

S(10, 3) = S(9, 2) + 3S(9, 3) = 255 + 3 · 3025 = 9330

OR, we may obtain the same result by inclusion-exclusion:

310 − 3 · 210 + 3 · 110


= 9330
3!

42
Exercise 9-11: 6 people on an air plane have identical suitcases. On exit, they take
one randomly. Aslı and Kardelen make a bet on how many of them will get their own
suitcases.

• Aslı thinks that, nobody will get his/her own suitcase.

• Kardelen thinks that, exactly one person will get his/her own suitcase.

Who is more likely to win?


Solution: The number of different cases where Aslı wins is the derangements of 6:
           
6 6 6 6 6 6
6! − · 5! + · 4! − · 3! + · 2! − · 1! + · 0! = 265
1 2 3 4 5 6

The number of different cases where Kardelen wins is 6 times the derangements of 5:
"           #
5 5 5 5 5
6 · 5! − · 4! + · 3! − · 2! + · 1! − · 0! = 6 · 44 = 264
1 2 3 4 5

So Aslı is more likely to win. (By a very small margin)

265 264
Probabilities are: = 0.3681 for Aslı and = 0.3667 for Kardelen.
6! 6!

Note that both numbers are approximately equal to e−1 = 0.3679

Exercise 9-12: There are 8 chairs in a classroom. 6 students attend a lecture. After the
break, the same 6 students come to the same class and choose chairs randomly.
How many arrangements are there where exactly 2 students sit on their previous chairs?
 
6
Solution: Choose two students in = 15 different ways. The rest is an inclusion-
2
exclusion problem. We have 4 items and 6 containers. Each container can contain at
most 1 item. Item 1 can NOT be placed in container 1 etc.
       
4 4 4 4
6·5·4·3− 5·4·3+ 4·3− 3+ = 181
1 2 3 4

So the answer is:


15 · 181 = 2715

Exercise 9-13: An online dating service will match the women A,B,C with the men
U,V,W,X,Y,Z.
Women’s constraints are:

• A does not want X.

• B does not want Y.

• C does not want Z.

43
Men have no constraints. How many matchings are possible?
Solution: We will use inclusion-exclusion to count the distributions as follows:

All matched randomly


− One woman is matched to someone she does not want, the others are matched randomly
+ Two women are matched to someone they do not want, the other is matched randomly
− Three women are matched to someone they do not want.

6 · 5 · 4 − 3 · 5 · 4 + 3 · 4 − 1 = 71

Exercise 9-14: An online dating service will match the women A,B,C with the men
U,V,W,X,Y,Z.
Women’s constraints are:

• A does not want X.

• B does not want X and Y.

• C does not want X,Y and Z.

Men have no constraints. How many matchings are possible?

Solution: First Solution: We will use inclusion-exclusion to count the distributions as


follows:
All matched randomly
− One woman is matched to someone she does not want, the others are matched randomly
+ Two women are matched to someone they do not want, the other is matched randomly
− Three women are matched to someone they do not want.

6 · 5 · 4 − 5 · 4 − 2 · 5 · 4 − 3 · 5 · 4 + 4 + 2 · 4 + 4 · 4 − 1 = 27

Second Solution: A better idea is to eliminate X in the beginning:

5 · 4 · 3 − 4 · 3 − 2 · 4 · 3 + 3 = 27

Third Solution: An even better idea is this:

• First match C. She has 3 choices. (U,V,W)

• Then match B. She has 3 choices. (4-1)

• Then match A. She has 3 choices. (5-2)

Therefore there are 3 · 3 · 3 = 27 different matchings.

44
Week 10– Generating Functions

Formal Power Series:


N
X 1 − xN +1
xn = 1 + x + x2 + x3 + · · · + xN =
n=0
1−x

X 1
xn = 1 + x + x2 + x3 + · · · =
n=0
1−x

X x
xn = x + x2 + x3 + · · · =
n=1
1−x


X 1
(−1)n xn = 1 − x + x2 − x3 + · · · =
n=0
1+x

X 1
x2n = 1 + x2 + x4 + x6 + · · · =
n=0
1 − x2

X 1
(n + 1)xn = 1 + 2x + 3x2 + · · · =
n=0
(1 − x)2

1 X 1
(n + 2)(n + 1)xn = 1 + 3x + 6x2 + · · · =
2 n=0
(1 − x)3

If we generalize this by evaluating derivatives m − 1 times, we obtain


∞  
1 X m+n−1 n
= x
(1 − x)m n=0
n

m(m + 1) 2 m(m + 1)(m + 2) 3 m(m + 1)(m + 2)(m + 3) 4


= 1 + mx + x + x + x + ···
2 3! 4!
We are not interested in convergence here, but the above series converge for |x| < 1.

Exercise 10-1: What is the coefficient of x10 in the expansion of


(x + x2 )(x3 + x4 + · · · )(1 + x2 + x4 + · · · )?
 
Answer: 7

Exercise 10-2: In how many ways can we distribute 10 identical balls to three different
children A, B, C such that A gets 1 or 2, B gets 3 or more, C gets an even number of
balls?
 
Answer: 7, The problems are equivalent

45
Exercise 10-3: In how many ways can we distribute 12 oranges to A, B, C such that A
gets at least 4, B gets at least 2 and C gets between 2 and 5?
 
Answer: 14

Exercise 10-4: Determine the coefficient of x15 in (x2 + x3 + · · · )4 .


 
Answer: 120

x
Exercise 10-5: Determine the coefficient of x10 in the expansion of
(1 + x2 )(1 − x)

Exercise 10-6: In how many ways can we fill a bag with n fruits subject to the following
constraints?

• The number of apples must be even.

• The number of bananas must be a multiple of 5.

• There can be at most four oranges.

• There can be at most one pear.

For example, there are 8 ways to form a bag with 7 fruits:

Apples 6 6 4 4 2 2 0 0
Bananas 0 0 0 0 0 5 5 5
Oranges 0 1 3 2 4 0 2 1
Pears 1 0 0 1 1 0 0 1
1 1 − x5
 
1 1
Answer: 2 5
(1 + x) = 2
= 1 + 2x + 3x2 + · · ·
1−x 1−x 1−x (1 − x)
So the answer is simply n + 1.

Exercise 10-7: In how many different ways can we distribute n apples to A, B, C such
that A gets 0 or 1, B gets 0 or 2, C gets a multiple of 4?
 
Answer: 1. The result is independent of n

46
Exercise 10-8: In how many different ways can we distribute 75 pieces of chocolate to
5 different children such that each child gets at least 6 and at most 24?
Solution: The generating function is:

(x6 + x7 + · · · + x24 )5 = x30 (1 + x + x2 + · · · + x18 )5

(1 − x19 )5
= x30
(1 − x)5

∞  
30 19 38 57 76 95
X n+4
= x (1 − 5x + 10x − 10x + 5x − x ) xn
n=0
n
     
49 30 11
Coefficient of x75 is: −5 + 10 = 78151
45 26 7
Second Method: Give 6 to each, distribute remaining 45 balls randomly. Subtract cases
where one child gets 19 or more. Add cases where two children gets 19 or more, to obtain:
     
49 30 11
−5 + 10 = 78151
45 26 7

Exercise 10-9: We are distributing 33 pieces of identical bonibons to Nilay, Ahmet Can,
Mehmet, Cihan and Büşra with the following constraints:

• Nilay gets a multiple of 6. {0, 6, 12, . . .}

• Ahmet Can gets at most 5. {0, 1, . . . , 5}

• Mehmet gets a multiple of 4. {0, 4, 8, . . .}

• Cihan gets none or 2. {0, 2}

• Büşra gets 7 or 8. {7, 8}

In how many different ways can we do this distribution?

Solution: The generating function is:

(1 + x6 + x12 + · · · )(1 + x + · · · + x5 )(1 + x4 + x8 + · · · )(1 + x2 )(x7 + x8 )

1 1 − x6 1
= (1 + x2 )x7 (1 + x)
1 − x 6 1 − x 1 − x4
x7 (1 + x)(1 + x2 )
=
(1 − x)(1 + x2 )(1 − x)(1 + x)
x7
=
(1 − x)2
= x7 (1 + 2x + 3x2 + 4x3 + · · · )
Coefficient of x33 is 33 − 6 = 27. Therefore there are 27 different ways.

47
Exercise 10-10: We will buy a total of 100 identical laptop computers from 5 distinct
stores A, B, C, D, E such that

• We will buy an odd number from A,

• We will buy 0 or 1 from B,

• We will buy 10 or less from C,

• We will buy 7 or more from D.

In how many different ways can we do that?

Solution: The generating function is:

(x + x3 + x5 + · · · )(1 + x)(1 + x + · · · + x10 )(x7 + x8 + · · · )(1 + x + x2 + · · · )

x 1 − x11 x7 1
= 2
(1 + x)
1−x 1−x 1−x 1−x
x8 − x19
=
(1 − x)4
∞  
8
X
19n+3 n
= (x − x ) x
n=0
n

Coefficient of x100 is:


   
95 84
− = 43 131
92 81

Exercise 10-11: Find the number of different solutions of the equation n + m + k = 10


where n, m, k are nonnegative integers and n is odd, m is 0 or 1, k is at most 8.
Solution:
(x + x3 + x5 + · · · ) (1 + x) (1 + x + x2 + · · · + x8 )
x 1 − x9
= (1 + x)
1 − x2 1−x
x(1 − x9 )
=
(1 − x)2
∞  
10
X n+1
= (x − x ) xn
n=0
n

Coefficient of x10 :    
10 1
− =9
9 0

48
Exercise 10-12: We will order 6 pizzas. There are 3 types available: Vegetarian, pep-
peroni and margarita. We want at most 3 vegetarian, at most 4 margarita and at least 2
pepperoni. In how many different ways can we order?
Solution:
(1 + x + x2 + x3 ) (1 + x + x2 + x3 + x4 ) (x2 + x3 + · · · )
1 − x4 1 − x5 x2
=
1−x 1−x 1−x
x2 − x6 − x7 + x11
=
(1 − x)3
∞  
2 6 7 11
X n+2
= (x − x − x + x ) xn
n=0
n

Coefficient of x6 :    
6 2
− = 14
4 0

Exercise 10-13: A group of 7 people find a buried treasure consisting of 40 identi-


cal pieces of gold. They will share the gold among themselves according to following
constraints:

• Berke gets even number.

• Ece gets a multiple of 3.

• Gizem gets a multiple of 4.

• Merve gets 0,1 or 2.

• Sergen gets 0 or 2.

• Utku gets 0 or 1.

• Yılmaz gets 0 or 1.

In how many different ways can they do this?


Solution: The series representing these constraints are:

1 1 1 1 − x3
· · · · (1 + x2 ) · (1 + x) · (1 + x)
1 − x2 1 − x3 1 − x4 1 − x
After cancellations, we obtain:
∞  
1 X n+2 n
= x
(1 − x)3 n=0
n

The coefficient of x40 is:  


42
= 861
40

49
Exercise 10-14: How many integer solution are there for the equation

x1 + x2 + x3 + x4 = 21

satisfying the following conditions?

• 0 6 x1

• 3 6 x2 6 8

• 0 6 x3 6 4

• 7 6 x4

Solution: The series product representing possible solutions is:

(1 + x + x2 + · · · )(x3 + x4 + · · · + x8 )(1 + x + x2 + x3 + x4 )(x7 + x8 + · · · )

1 x3 (1 − x6 ) (1 − x5 ) x7
=
1−x 1−x 1−x 1−x
x10 (1 − x5 − x6 + x11 )
=
(1 − x)4
∞  

10 15 16 21
X n+3 n
= x −x −x +x x
n=0
n

Coefficient of the term x21 in this series expansion is:


       
14 9 8 3
− − + = 225
11 6 5 0

50
Week 11– Exponential Generating Functions

For a sequence of real numbers a0 , a1 , a2 , . . . the exponential generating function is


defined as:
x2 x3
f (x) = a0 + a1 x + a2 + a3 + ···
2! 3!
The generating function for the sequence 1, 1, 1, . . . is ex .
ex + e−x ex − e−x
For even powers, we can use and for odd powers, .
2 2

Exercise 11-1: In how many ways can four of the letters of the word ENGINE be
arranged? (Here, order is important)
 
Answer: 102
We can obtain the same result by finding the coefficient of x4 /4! in the expansion of:
2
x2

1+x+ (1 + x)2
2!

Exercise 11-2: A ship carries flags of the colors red, white, blue, black. Twelve of these
are placed on a vertical pole.
a) How many such signals use an even number of blue flags and an odd number of black
flags?
 
11
Answer: 4

b) How many of the signals have at least three white flags or no white flags at all?
 
12 11 10
Answer: 4 − 12 · 3 − 66 · 3

Exercise 11-3: Consider all 50 letter sequences made of letters a, b, c.


a) How many of them contain an even number of a’s?
350 + 1
 
Answer:
2
b) How many of them contain odd number of b’s?
350 − 1
 
Answer:
2

Exercise 11-4: A set has 10 elements. We will partition it into 4 subsets such that each
subset will have an odd number of elements. In how many different ways can we do this?
4 
1 ex − e−x
 
Answer: 5440, Use generating function:
4! 2

51
Exercise 11-5: There are 32 houses on a street. We will paint each house with one of
the six colors: White, blue, red, yellow, green or orange. For each color, the number of
houses painted must be even.
In how many different ways can we do that?
Solution: The exponential generating function is:
6 6
x2 x4 ex + e−x
 
1+ + + ··· =
2! 4! 2

e6x + 6e4x + 15e2x + 20 + 15e−2x + 6e−4x + e−6x


=
64

x32 1  32 
Coefficient of is: 6 + 6 · 432 + 15 · 232
32! 32

Exercise 11-6: Consider all words of length 10 made of the letters in the set {a, b, c, d, e, f, g}.
How many contain at least one a, at least one b and at least two c?
Solution: Define conditions as:

• P : The word contains no a,

• Q: The word contains no b,

• R: The word contains no c or 1 c.

Then, the answer is:

= N − N (P ) − N (Q) − N (R)
+N (P Q) + N (P R) + N (QR)
−N (P QR)

= 710 − 610 − 610 − (610 + 10 · 69 )


+510 + (510 + 10 · 59 ) + (510 + 10 · 59 )
−(410 + 10 · 49 )

Second Method: The exponential generating function is:

2  2 4
x2 x3 x3 x2 x3
 
x
x+ + + ··· + + ··· 1+x+ + + ···
2! 3! 2! 3! 2! 3!

= (ex − 1)2 (ex − 1 − x)e4x

= e7x − (3 + x)e6x + (3 + 2x)e5x − (1 + x)e4x

x10
The coefficient of is:
10!

710 − 3 · 610 − 10 · 69 + 3 · 510 + 20 · 59 − 410 − 10 · 49

52
Exercise 11-7: We will form a 7-letter sequence using the letters A, B, C. Each letter
must appear an odd number of times or zero times. How many possible sequences are
there?
Solution: Order is important ⇒ we have to use exponential generating functions.
3
ex − e−x

(1 + x + x3 + x5 · · · )3 = 1+
2

−4 + 9ex − 9e−x + 6e2x + 6e−2x + e3x − e−3x


=
8

x7
In the Taylor series expansion of this function, the coefficient of the term is:
7!
1  9 + 37
9 + 9 + 6 · 27 − 6 · 27 + 37 + 37 =
8 4

Exercise 11-8: We will form 16 letter sequences using the letters {x, y, z} with the
following conditions:

• There will be at least 4 x’s,

• Number of y’s will be even.

How many sequences are possible?


Solution: We have to use exponential series to represent possible solutions, because order
is important:
 4
x5 x2 x4 x2 x3
  
x
+ + ··· 1+ + + ··· 1+x+ + + ···
4! 5! 2! 4! 2! 3!
x2 x3 e + e−x x
    x 
x
= e − 1+x+ + e
2! 3! 2
e3x ex x2 x3
   2x 
e 1
= + − 1+x+ + +
2 2 2! 3! 2 2

x16
Coefficient of the term in the series expansion is:
16!
 
1 16 16 16 · 15 14 16 · 15 · 14 13
15
3 + 1 − 2 − 16 · 2 − ·2 − ·2 = 17 951 649
2 2! 3!

53
Exercise 11-9: We will form 16 letter sequences using the letters {x, y, z} with the
following conditions:

• There will be at least 2 x’s,

• Number of y’s will be odd.

How many sequences are possible?


Solution: We have to use exponential series to represent possible solutions, because order
is important:
 2
x3 x3 x5 x2 x3
  
x
+ + ··· x+ + + ··· 1+x+ + + ···
2! 3! 3! 5! 2! 3!
e − e−x x
 x 
x
= (e − 1 − x) e
2
e3x ex 1 + x 2x 
= − − e −1
2 2 2

x16
Coefficient of the term in the series expansion is:
16!
1 16
3 − 1 − 216 − 16 · 215 = 21 228 448

2

54
Week 12– Computational Complexity

Growth of Functions: Given two increasing functions, how can we tell which one is
increasing faster?
Big-Oh: Let f (n), g(n) be two functions. We say f (n) = O(g(n)) (f is Big-Oh of g) if

0 6 f (n) 6 cg(n)

for all n > n0 . In other words, f (n) = O(g(n)) if g(n) times a constant is greater than
f (n) for sufficiently large n values.

Exercise 12-1: Show that nk = O(en ) for all k ∈ Z+ .

Exercise 12-2: Show that log n = O(nk ) k > 0.

Exercise 12-3: Show that 2n = O(n!)


Big-Theta: We say that f (n) = Θ(g(n)) (f is Big-theta of g) if

0 6 c1 g(n) 6 f (n) 6 c2 g(n)

for all n > n0 . In other words, if f (n) = O(g(n)) and g(n) = O(f (n)) then we say
f (n) = Θ(g(n)).

Exercise 12-4: Show that (n + 1)2 = Θ(n2 )

Exercise 12-5: Show that ln n = Θ(log n)

Exercise 12-6: Determine the Θ class of the following:


a) f (n) = n2 − 2n − ln n
b) f (n) = 3(n − 1)3
c) f (n) = n! − en
 
Answer: a) Θ(2n )

b) Θ(n3 )
c) Θ(n!)

55
Exercise 12-7: Rank the following functions according to their growth rates:
√ √
n, n!, 2n , n2 , n3 , log n, n log n, n, n n, 3n , nn , 1

Exercise 12-8: Rank the following functions according to their growth rates:

 n
2
√ 2 3/2 3
f (n) = n + 2n n, g(n) = n log n − n log n, h(n) = 1 + 2n +
2

Solution: f = O(g), g = O(h). In other words for sufficiently large n we have f < g < h.

Exercise 12-9: Rank the following functions according to their growth rates:

n + n2 , n! + en , n n, 4n , (n + 1)n

Solution: √
n n < n + n2 < 4n < n! < (n + 1)n

Exercise 12-10: Rank the following functions according to their growth rates:

e(n+2) , nn + n!, log(n2 ), n log n, (2n)!

Solution:
log(n2 ) < n log n < e(n+2) < nn < (2n)!

56
For the following questions, write an algorithm in pseudo-code. Then,
find the asymptotic complexity of the algorithm:

Exercise 12-11: Given an unsorted vector a, find if the element X occurs in a.


Solution:
INPUT vector a
n = size(a)
For i = 1 to n
If a(i) == X
Return True;
EndIf
EndFor
Return False;
 
Answer: O(n)

Exercise 12-12: Given a sorted vector a, find the location of element X


Solution:
INPUT vector a, element X
low = 0
high = size(a)
While low 6 high
mid = (low + high)/2
If a(mid) < X
low = mid + 1
elseif a(mid) > X
high = mid − 1
else
Return mid;
EndIf
EndWhile
Return NOT FOUND;
 
Answer: O(ln(n))

Exercise 12-13: Sort N numbers by finding the smallest in the list and placing it as the
first:
Solution:
For i = 1 to N
index = i
For j = i + 1 to N
If A(j) < A(index)
index = j
EndIf
EndFor
Swap(A(i), A(index))
EndFor

57
Exercise 12-14: Given an array of n elements, check whether all elements are distinct.
Return False if any two are the same.
Solution:
INPUT: Vector A
n = size(A)
For i = 1 to n − 1
For j = i + 1 to n
If A(i) == A(j)
Return False
EndIf
EndFor
EndFor
Return True

Exercise 12-15: Find the time the following algorithm takes based on input size n. In
other words, find Θ class. You may assume n is a power of 2 for simplicity.
Solution:
INPUT n
S = 0; k = 1
While k 6 n
For j = 1 to n
S =S+1
EndFor
k =2∗k
EndWhile
 
Answer: Θ(n log2 n)

Exercise 12-16: Find the time the following algorithm takes based on input size n. In
other words, find Θ class. You may assume n is a power of 2 for simplicity.
Solution:
INPUT n
S = 0; k = 1
While k 6 n
For j = 1 to k
S =S+1
EndFor
k =2∗k
EndWhile
 
Answer: Θ(n)

58
Exercise 12-17: The following program checks if all elements of the given vector are
distinct. It returns False if any two are the same. What is the asymptotic growth rate?
(Consider worst case)
Solution:
INPUT: Vector A
n = size(A)
For i = 1 to n − 1
For j = i + 1 to n
If A(i) == A(j)
Return False
EndIf
EndFor
EndFor
Return True
(n − 1)n
Solution: (n − 1) + (n − 2) + (n − 3) + · · · + 2 + 1 = = Θ(n2 )
2

Exercise 12-18: Find the time the following algorithm takes based on input size n. In
other words, find its Θ class.
Solution:
INPUT n
Sum = 0
For i = 1 to n
For j = 1 to i2
Sum = Sum + j
EndFor
EndFor
n(n + 1)(2n + 1) 2n3 + 3n2 + n
Solution: 12 + 22 + 32 + · · · + n2 = =
6 6

⇒ Complexity of Algorithm is: Θ(n3 )

Exercise 12-19: Find a function g(n) such that f (n) = O(g(n)) and g(n) = O(h(n))
but f (n) 6= Θ(g(n)) and g(n) 6= Θ(h(n)).
In other words, g(n) should increase faster that f (n) but slower than h(n). For
example: f (n) = n2 , h(n) = n4 ⇒ g(n) = n3
a) f (n) = ln n, h(n) = n
b) f (n) = 2n , h(n) = nn
c) f (n) = n2 + n, h(n) = n2 + en
Solution: Many answers are possible, some examples are:

a) n
b) n! or 3n or n2n
c) n3 or n4 or 2n

59
Exercise 12-20: We know that Fonk1(n) is an algorithm of complexity Θ(n) and
Fonk2(n) is an algorithm of complexity Θ(n2 ). Find the complexity of the following
algorithm:

INPUT n
For i = 1 to 3n
Fonk1(i)
Fonk2(i)
EndFor
For j = 1 to n
Fonk1(n)
EndFor
Solution:
     
2 2 2
1 + 2 + · · · + 3n + 1 + 2 + · · · + (3n) + n + · · · + n = Θ(n2 ) + Θ(n3 ) + Θ(n2 )

= Θ(n3 )

Exercise 12-21: Find the asymptotic complexity of the following algorithm:


INPUT: Integer n
//A is an n × n matrix
For i = 1 to n
For j = 1 to n
A(i, j) = 1/(i + j)
EndFor
EndFor
For i = 1 to n
If i is even
A(i, i) = 1
Else
A(i, i) = −1
EndIf
EndFor
Return A
Solution: Θ(n2 ) + Θ(n) = Θ(n2 )

60
Week 13– Homogeneous Recurrence Relations

We say that a sequence is defined recursively if some finite set of values, usually the
first few are specified, and the remaining values are defined in terms of the previous ones.
For example, the factorial function defined as: Factorial(0) = 1,
Factorial(n) = Factorial(n − 1) is recursive.
Fibonacci sequence is another example.

Exercise 13-1: Solve the first order recurrence relation an+1 = 2an , a0 = 7.
 
n
Answer: 7 · 2

Exercise 13-2: Solve an − 3an−1 = 0, a4 = 81


 
n
Answer: 3

Exercise 13-3: Find an explicit formula for an where a1 = 1, a2 = 5 and


an+1 = 5an − 6an−1 for n > 2.
 
n n
Answer: an = 3 − 2
Assume the result is xn like the first order equations. We obtain x2 − 5x + 6 = 0. The
solution is 2 or 3, and both 2n and 3n satisfy the equation. Also, 2n + 3n or any linear
combination of these two satisfy the equation.
The following theorem summarizes these results:
Theorem: Let an + pan−1 + qan−2 = 0 be a recurrence relation and x2 + px + q = 0 its
characteristic equation, where p, q are nonzero.
a) If the characteristic equation has two distinct roots r1 , r2 then an = c1 r1n + c2 r2n .
b) If the characteristic equation has a double root r then an = c1 rn + c2 nrn .

Exercise 13-4: Solve the recurrence relation a0 = 1, a1 = −3 and an = −2an−1 + 3an−2


for n > 2.
 
n
Answer: an = (−3)

Exercise 13-5: How can we obtain the general formula for Fibonacci sequence, given
that Fn = Fn−1 + Fn−2 ?
 " √ !n √ !n # 
1 1+ 5 1− 5
Answer: √ −
5 2 2
n n n−1
Assume Fn = x . In that case,
√ x =x + xn−2 and x2 − x − 1 = 0. The solution of
1± 5
this equation gives x1,2 = , therefore the general solution is Fn = c1 xn1 + c2 xn2 . We
2
can determine c1 and c2 from the initial conditions F1 = 1, F2 = 1.

Exercise 13-6: Solve an + an−1 − 6an−2 = 0, n > 2, a0 = −1, a1 = 8


 
n n
Answer: an = 2 − 2(−3) .

61
Exercise 13-7: Solve an+2 = an+1 + an , a0 = 0, a1 = 4.

Exercise 13-8: (Repeated Root) Solve the recurrence relation an+2 = 4an+1 −4an , where
a0 = 1, a1 = 3
 
n n−1
Answer: an = 2 + n2

Exercise 13-9: (Repeated Root) Solve the recurrence relation 9an+2 = 42an+1 − 49an ,
where a1 = 21, a2 = 98
  n 
7
Answer: an = 9n
3

Exercise 13-10: Solve 2an+3 = an+2 + 2an+1 − an , a0 = 0, a1 = 1, a2 = 2


  n 
5 1 n 8 1
Answer: an = + (−1) −
2 6 3 2

Complex Roots
For the following questions, remember the formulas:
p y
x + iy = reiθ , where r = x2 + y 2 , and θ = arctan
x

eiθ = cos θ + i sin θ

eiθ + e−iθ eiθ − e−iθ


⇒ cos θ = , sin θ =
2 2i

Exercise 13-11: Solve the recurrence relation an+2 = 2an+1 − 2an , where a0 = 1, a1 = 2
√ n
 
nπ nπ 
Answer: an = ( 2) cos + sin
4 4

Exercise 13-12: Solve the recurrence relation an+2 = 3an+1 − 3an , where a0 = 2, a1 = 3
√ n
 

Answer: an = 2( 3) cos
6

Exercise 13-13: Solve the recursion relation

2an+2 = −7an+1 + 4an , a0 = 9, a1 = −9

  n 
n 1
Answer: an = 3(−4) + 6
2

Exercise 13-14: Solve the recurrence relation an+2 −2an+1 +an = 18, a0 = 7, a1 = 8
for n > 0.
Solution: x2 − 2x + 1 = 0 ⇒ x = 1 (Double Root)

62
ahn = c1 1n + c2 n1n = c1 + c2 n

apn = A n2 1n = A n2

A(n + 2)2 − 2A(n + 1)2 + An2 = 18 ⇒ A=9

an = c1 + c2 n + 9n2

n=0 ⇒ c1 = 7,

n=1 ⇒ c2 = −8

an = 7 − 8n + 9n2

Exercise 13-15: Solve the following recursion relations:


a) an+2 = 6an+1 − 9an , a1 = 15, a2 = 126
b) an+2 + an+1 + an = 0, a0 = 4, a1 = −5
Solution:
a) an = krn ⇒ r2 − 6r + 9 = 0 ⇒ r=3
an = k1 3n + k2 n3n ⇒ 3k1 + 3k2 = 15, 9k1 + 18k2 = 126 ⇒ k1 = −4, k2 = 9
an = (−4)3n + 9n3n

= 3n (9n − 4)


n 2 1 3
b) an = kr ⇒ r +r+1=0 ⇒ r=− ± i
2 2
√ !n √ !n
1 3 1 3
an = k1 − + i + k2 − − i
2 2 2 2
√ √ √
k1 + k2 = 4, k1 − k2 = 2 3i ⇒ k1 = 2 + 3i, k2 = 2 − 3i
√ 2πni √ −2πni
an = (2 + 3i) e 3 + (2 − 3i) e 3


   
2πn 2πn
= 4 cos − 2 3 sin
3 3

Exercise 13-16: Solve the recursion relation an = 10an−1 − 18an−2 with the initial
conditions
a0 = 4, a1 = 20.
Solution: x2 − 10x + 18 = 0

63

x=5± 7
√ √
an = c1 (5 + 7)n + c2 (5 − 7)n

n = 0 ⇒ 4 = c1 + c2
√ √
n = 1 ⇒ 20 = c1 (5 + 7) + c2 (5 − 7)

⇒ c1 = c2 = 2
h √ √ i
an = 2 (5 + 7)n + (5 − 7)n

Exercise 13-17: Solve the recursion relation 2an+2 − 8an+1 + 7an = 0 with the initial
conditions
a0 = 16, a1 = 32.
Solution: 2x2 − 8x + 7 = 0

2
x=2±
2
√ !n √ !n
2 2
an = c 1 2+ + c2 2−
2 2

n = 0 ⇒ 16 = c1 + c2
√ ! √ !
2 2
n = 1 ⇒ 32 = c1 2+ + c2 2 −
2 2

⇒ c1 = c2 = 8
" √ !n √ !n #
2 2
an = 8 2+ + 2−
2 2

64
Week 14– Recurrence Relations and Algorithms

Exercise 14-1: Let Σ = {0, 1, 2}. Let an denote the number of n-bit strings that contain
an even number of zeros. Clearly, a0 = 1, a1 = 2, a2 = 5. What is an in general?
We can obtain an n-bit sequence with an even number of zeros as follows: Take an
(n − 1)–bit sequence with an even number of zeros, add 1 or 2. Or, take an (n − 1)–bit
sequence with an odd number of zeros and add 0. This means:
3n + 1
an = 2an−1 + (3n−1 − an−1 ) ⇒ an =
2

Exercise 14-2: Let Σ = {a, b}. How many words of length n are there that do not
contain aa?
Let’s call this number sn . Clearly, s0 = 1, s1 = 2, s2 = 3. The last two letters of our
word must be ab or bb or ba. To obtain an n letter word that does not contain aa, we can
add b to an n − 1 letter word, or we can add ba to an n − 2 letter word. So

sn = sn−1 + sn−2
√ √ !n √ √ !n
5+3 5 1+ 5 5−3 5 1− 5
sn = +
10 2 10 2

Exercise 14-3: In how many different ways can we express n as a sum of 1’s and 2’s,
where order is important?
 √ √ !n √ √ !n 
5+ 5 1+ 5 5− 5 1− 5
Answer: an = an−1 + an−2 , an = +
10 2 10 2

Exercise 14-4: Count the number of arithmetic expressions of n symbols made of


0, 1, . . . , 9, +, ∗, /.
√ n √ n
  
5
Answer: an = 10an−1 + 29an−2 , an = √ (5 + 3 6) − (5 − 3 6)
3 6

Exercise 14-5: For n > 1 let an be the number of ternary strings (containing 0,1,2) of
length n that do not contain 11 or 22. Find and solve a recurrence relation for an . (Hint:
Consider those ending in 00 separately)
√ n+1 √ n+1
  
1
Answer: an = 2an−1 + an−2 , an = (1 + 2) + (1 − 2)
2

Exercise 14-6: There are n houses around a circular street. We will color them using 5
distinct colors such that any two adjacent houses will have different colors. In how many
different ways can we do this? (The recurrence relation is correct for n > 2)
 
n n
Answer: an+2 = 3an+1 + 4an , an = 4 + 4(−1)

Exercise 14-7: Let A = {0, 01, 011, 111}. For n > 1, find the number of binary strings
of length n made from elements of A.

65
 √ 
4 n 3 2nπ 3 2nπ
Answer: an = an−1 + an−2 + 2an−2 , an = 2 + cos + sin
7 7 3 21 3

Exercise 14-8: Let an be the number of regions in the plane obtained by drawing n
lines. For example, a1 = 2, a2 = 4, a3 = 7.
(Lines are not parallel, three lines do not intersect at a point)
a) Find a recurrence relation for an .
b) Find an .
Solution:
a) an = an−1 + n

b) x − 1 = 0 ⇒ ahn = c

apn = An2 + Bn

An2 + Bn − A(n − 1)2 − B(n − 1) = n

1 1
⇒ A= , B=
2 2

n2 + n n2 + n
apn = ⇒ an = +c
2 2

a1 = 2 ⇒ c=1

n2 + n + 2
an =
2

Exercise 14-9: In how many different ways can we express 100 as a sum of 5’s and 10’s
if order is important?
Solution: an = an−5 + an−10

x10 − x5 − 1 = 0

1 ± 5
x5 =
2
√ √ !n/5 √ √ !n/5
5+ 5 1+ 5 5− 5 1− 5
a5 = 1, a10 = 2 ⇒ an = +
10 2 10 2

a100 = 10946

66
Or, alternatively, divide by 5 and transform the problem to obtaining 20 using 1’s and
2’s.

Exercise 14-10: The number of laptops manufactured in a factory was 10000 in the first
year, 16000 in the second year, and the average of previous two years after that. How
many laptops were produced on the nth year?
an−1 + an−2
Solution: an =
2

2x2 − x − 1 = 0

1
x = 1 or x = −
2
 n
n 1
an = c1 (1) + c2 −
2

c2
10000 = c1 −
2
c2
16000 = c1 +
4
 n
1
an = 14000 + 8000 −
2

Exercise 14-11: An algorithm makes T (n) operations to solve a problem of input size
n. Find an explicit formula for T (n) if
a) T (n) = T (n/2)
b) T (n) = 2T (n/2)
c) T (n) = aT (n/b)
(Hint consider the transformation n = 2m )
Nonhomogeneous Recurrence Relations
Consider the second order nonhomogeneous relation

an + pan−1 + qan−2 = krn

• Solve the homogeneous version of the equation an + pan−1 + qan−2 = 0. Call the
solution ahn .

• Let apn be any particular solution for the nonhomogeneous equation.

a. If r is not a root of the homogeneous equation, apn = Crn .


b. If r is a single root of the homogeneous equation, apn = Cnrn .
c. If r is a double root of the homogeneous equation, apn = Cn2 rn .

• The general solution is: an = ahn + apn .

67
Exercise 14-12: Solve the recurrence relation an+2 − an+1 − 6an = 14 · 5n , a0 = 5, a1 =
10 for n > 0.
 
7 n 13 n n
Answer: an = (−2) + 3 +5
5 5

Exercise 14-13: Solve the recurrence relation an+2 −5an+1 +4an = 6·4n , a0 = 2, a1 = 6
for n > 0.
 
2 n 4 1 n
Answer: an = 4 + + n4
3 3 2

Exercise 14-14: Solve the recurrence relation an+2 − 16an+1 + 64an = 2 · 8n+2 ,
a0 = 1, a1 = 12 for n > 0.
   
1
Answer: an = 1 − n + n 8n 2
2

Exercise 14-15: Solve a0 = 1, a1 = 2 and an = 2an−1 − an−2 + 2 for n > 2.


 
2
Answer: an = n + 1

Exercise 14-16: Solve the recurrence relation an+2 − 4an+1 + 3an = −200, a0 =
3000, a1 = 3300 for n > 0.
 
n
Answer: an = 100 · 3 + 2900 + 100n

Generalization of the Method


We can solve recursion relations with the right hand side given below using the same
method:

f (n) apn candidate


1 a
n an + b
2
n an2 + bn + c
nk ak nk + · · · + a0
rn arn
nk rn rn (ak nk + · · · + a0 )
If we have a characteristic root at apn , we have to multiply it by n for a single root,
and n2 for a double root.

68
Exercise 14-17: Solve the recurrence relation

2an+2 − 9an+1 + 9an = 10 · 4n , a0 = 3, a1 = 14


for n > 0.
Solution:
3
2x2 − 9x + 9 = 0 ⇒ x = 3,
2
 n
3
ahn n
= c1 3 + c2 apn = A 4n
2

2A4n+2 − 9A4n+1 + 9A4n = 10 · 4n ⇒ A=2

3
c1 + c2 + 2 = 3, 3c1 + c2 + 8 = 14 ⇒ c1 = 3, c2 = −2
2
 n
n 3
an = 3 · 3 − 2 + 2 · 4n
2

Exercise 14-18: Solve the recurrence relation


16 n
an+2 − 4an = 2 , a0 = 3, a1 = −2
3
for n > 0.
Solution:
x2 − 4 = 0 ⇒ x = 2, −2

ahn = c1 2n + c2 (−2)n apn = A n 2n

16 n 2
A(n + 2)2n+2 − 4An2n = ·2 ⇒ A=
3 3

4 2 7
c1 + c2 = 3, 2c1 − 2c2 + = −2 ⇒ c1 = , c2 =
3 3 3

7 2
an = (−2)n + (n + 1) 2n
3 3

69
Exercise 14-19: Solve the recurrence relation

an+2 − 3an+1 + 2an = −5, a0 = 4, a1 = 12


for n > 0.
Solution:
x2 − 3x + 2 = 0 ⇒ x = 2, 1

ahn = c1 + c2 2n apn = A n

A(n + 2) − 3A(n + 1) + 2An = −5 ⇒ A=5

c1 + c2 = 4, c1 + 2c2 = 7 ⇒ c1 = 1, c2 = 3

an = 1 + 5n + 3 · 2n

Exercise 14-20: Solve the recurrence relation

an+2 − 14an+1 + 49an = −6 · 7n+1 , a0 = 1, a1 = 11


for n > 0.
Solution:
x2 − 14x + 49 = 0 ⇒ x = 7 (Double Root)

ahn = c1 7n + c2 n7n apn = A n2 7n

3
A(n + 2)2 7n+2 − 14A(n + 1)2 7n+1 + 49An2 7n = −42 · 7n ⇒ A=−
7

c1 = 1, −3 + 7 + 7c2 = 11 ⇒ c2 = 1

 
3 2 n
an = 1 + n − n 7
7

Exercise 14-21: Solve the recursion relation

3an+2 = −17an+1 + 6an , a0 = 13, a1 = −21

  n 
n 1
Answer: an = 4(−6) + 9
3

70

You might also like