ENGG 2440A / ESTR 2004: Discrete Mathematics for

ENGG 2440A / ESTR 2004: Discrete Mathematics for Engineers
The Chinese University of Hong Kong, Fall 2016
Homework 5 Solutions
1. Find exact closed form expressions for the following sums. Explain how you discovered the
expression and prove that it is correct.
(a) 1 · 2 + 2 · 3 + · · · + n · (n + 1).
(b) 12 + 32 + 52 + · · · + n2 , where n is odd.
(c) 1 · 2−1 + 2 · 2−2 + · · · + n · 2−n . (Hint: Calculate 2S − S, where S is the sum of interest.)
Solution:
(a) Let S(n) = 0 · 1 + 1 · 2 + · · · + (n − 1) · n. This is an expression that involves pairwise
products, so we guess a solution of the form S(n) = an3 + bn2 + cn + d for some numbers
a, b, c, d. If our guess is correct, the evaluations S(0) = 0, S(1) = 2, S(2) = 8, S(3) = 20
give rise to the following system of linear equations:
d=0
a+b+c+d=2
8a + 4b + 2c + d = 8
27a + 9b + 3c + d = 20.
This system has the unique solution a = 1/3, b = 1, c = 2/3, d = 0.
We now prove that, in fact, S(n) = 13 n3 + n2 + 23 n = 13 n(n + 1)(n + 2) by induction
on n. When n = 0, S(n) = 0 and 31 n(n + 1)(n + 2) = 0 as desired. Now we assume
S(n) = 13 n(n + 1)(n + 2) for some n. Then
S(n+1) = S(n)+(n+1)(n+2) = 13 n(n+1)(n+2)+(n+1)(n+2) = 31 (n+1)(n+2)(n+3)
as desired.
Alternative solution: We can write S(n) as (12 + · · · + n2 ) + (1 + · · · + n). Using
formulas from class, we can rewrite this as ( 31 n3 + 21 n2 + 16 n) + 12 n(n + 1) and simplify
to 31 n3 + n2 + 32 n.
(b) Let S(n) = 12 + 32 + 52 + · · · + n2 for positive odd number n. This is an expression that
involves pairwise products, so we guess a solution of the form S(n) = an3 + bn2 + cn + d
for some numbers a, b, c, d. If our guess is correct, the evaluations S(1) = 1, S(3) = 10,
S(5) = 35, S(7) = 84 give rise to the following system of linear equations:
a+b+c+d=1
27a + 9b + 3c + d = 10
125a + 25b + 5c + d = 35
343a + 49b + 7c + d = 84.
This system has the unique solution a = 1/6, b = 1/2, c = 1/3, d = 0.
We now prove that, in fact, S(n) = 16 n3 + 21 n2 + 13 n = 16 n(n + 1)(n + 2) by induction
on n. When n = 1, S(1) = 1 and 16 n(n + 1)(n + 2) = 1 as desired. Now we assume
S(n) = 16 n(n + 1)(n + 2) for some n. Then
S(n + 2) = S(n) + (n + 2)2
= 16 n(n + 1)(n + 2) + (n + 2)2
= 16 (n + 2)[n(n + 1) + 6n + 12]
= 16 (n + 2)(n + 3)(n + 4)
as desired.
Alternative solution: We can write
S(n) = (12 + 22 + · · · + n2 ) − (22 + 42 + · · · + (n − 1)2 )
= (12 + 22 + · · · + n2 ) − 22 (12 + 22 + · · · + ((n − 1)/2)2 ).
By the formula from class the first term equals 31 n3 + 21 n2 + 16 n and the second one
equals 4( 31 ((n − 1)/2)3 + 21 ((n − 1)/2)2 + 61 (n − 1)/2). After simplifying we obtain that
S(n) = 61 n3 + 12 n2 + 31 n.
(c) Let S(n) = 1 · 2−1 + 2 · 2−2 + · · · + n · 2−n . Then
2S(n) = 1 + 2 · 2−1 + 3 · 2−2 + · · · +
S(n) =
n ·2−(n−1)
1 · 2−1 + 2 · 2−2 + · · · + (n − 1)·2−(n−1) + n · 2−n
Subtracting the second formula from the first we obtain that
S(n) = 2S(n) − S(n) = 1 + (2−1 + 2−2 + · · · + 2−n−1 ) − n · 2−n .
Using the formula for a geometric sum, we can simplify the expression to
S(n) =
1 − 2−n
− n · 2−n = 2 − (n + 2) · 2−n .
1 − 1/2
We now prove that, in fact, S(n) = 2 − (n + 2)2−n by induction on n. When n = 1,
S(1) = 1/2 and 2 − (n + 2)2−n = 1/2 as desired. Now we assume S(n) = 1 − n · 2−n for
some n. Then
S(n + 1) = S(n) + (n + 1) · 2−(n+1) = 2 − (n + 2)2−n + (n + 1) · 2−(n+1)
= 2 − (2(n + 2) − (n + 1)) · 2−(n+1) = 2 − (n + 3) · 2−(n+1)
as desired.
2. Show the following inequalities by using the integral method for approximating sums.
√
√
√
√
√
(a) 2 n + 1 − 2 ≤ 1/ 1 + 1/ 2 + · · · + 1/ n ≤ 2 n + 1 − 1.
(b)
(c)
1 2
1 2
1
2 n ln n − 4 n + 4 − n ln n ≤ 1 ln 1 + 2 ln 2 + · · · + (n − 1) ln(n − 1)
2
2
2
1 · e−1 + 2 · e−2 + · · · + n · e−n ≤ 3/(2e).
≤ 12 n2 ln n − 14 n2 + 41 .
Solution:
√
(a) We approximate
by the integral of the function f (x) = 1/ x. The value of the
√ the sum
√
sum from 1/ 1 to 1/ n equals the area under the first n bars in the following diagram.
√
1/ x
1
2
3
4
5
6
x
√
The area is at least the integral of the function f (x) = 1/ x from 1 to n + 1. So, we
have
Z n+1
√
√ n+1
1
1
1
1
√ + √ + ··· + √ ≥
√ dx = 2 x1 = 2 n + 1 − 2.
n
x
1
2
1
If we subtract the area of the light-shaded rectangles from the sum then the √
integral
becomes an upper bound. The total area of the light-shaded rectangles is 1 − 1/ n + 1.
Therefore
Z n+1
1
1
1
1
1
√ + √ + ··· + √ − 1 − √
√ dx
≤
n
x
n+1
1
2
1
from where we obtain the upper bound
√
√
1
1
1
1
√ + √ + ··· + √ ≤ 2 n − 1 − 1 − √
≤ 2 n − 1 − 1.
n
n+1
1
2
(b) We approximate the sum by the integral of the function x ln x. The value of the sum
from 1 ln 1 + · · · + (n − 1) ln(n − 1) equals the area under the first n + 1 dark-shaded bars
in the following diagram.
x ln x
1
2
3
4
5
6
x
This area is upper-bounded by the integral of the function x ln x from 1 to n. The
antiderivative of x ln x is 12 x2 ln x − 41 x. This gives the inequality
Z n
1
1
1
1 ln 1 + 2 ln 2 + · · · + n ln n ≤
x ln x dx = n2 ln n − n +
2
4
4
1
On the other hand, the integral is less than the sum plus the area of the lightly shaded
rectangles. This area is exactly n ln n, and therefore
Z n
1 ln 1 + 2 ln 2 + · · · + (n − 1) ln(n − 1) + n ln n ≥
x ln x dx.
1
Evaluating the integral we obtain that
1
1
1
1 ln 1 + 2 ln 2 + · · · + (n − 1) ln(n − 1) ≥ n2 ln n − n + − n ln n
2
4
4
2
(c) We approximate the sum by the integral of the function x · e−x . The sum equals the
area under the first n bars in the following diagram. Apart from the first two bars, the
others are so short that they are not visible.
xe−x
2
x
0
1
2
3
4
5
6
√
2
The function
xe−x is increasing from x = 0 up to x = 1/ 2 and then decreasing when
√
x > 1/ 2. The sum from the second up to the n-th bar can therefore be upper bounded
by the integral of the function from 1 up to n, giving the inequality
Z n
2
2
2
2
2
1 · e−1 + 2 · e−2 + · · · + n · e−n ≤ 1 · e−1 +
xe−x dx.
1
2
2
The antiderivative of the function xe−x is − 21 e−x , so the integral is at most
Z n
Z ∞
2 ∞
2
2
xe−x ≤
xe−x = 12 xe−x 1 = 1/2e
1
1
and so the sum is at most 1/e + 1/2e = 3/2e.
3. Find exact closed-form solutions to the following recurrences.
(a) g(n) = g(n − 1) + 4g(n − 2), g(0) = 0, g(1) = 1.
(b) T (n) = 2T (n − 1) + n2 , T (0) = 0.
(c) F (n) = 3F (n/3) + n/3, F (1) = 1, where n is a power of 3.
Solution:
(a) This is a homogeneous linear recurrence, so we guess a solution of the form g(n) = xn
for some nonzero x. If our guess is correct, xn must equal xn−1 + 4xn−2 for all n, from
where x2 = x + 4. This quadratic equation has the two solutions
√
√
1 − 17
1 + 17
x1 =
and
x2 =
.
2
2
Any linear combination of xn1 and xn2 also satisfies the recurrence. We look for a a linear
combination g(n) = sxn1 + txn2 that satisfies the additional requirements g(0) = 0 and
g(1) = 1:
0 = g(0) = s + t
1 = g(1) = sx1 + tx2 = s ·
1+
√
2
17
+t·
1−
√
2
17
.
√
√
The unique solution to this system is s = 1/ 17, t = −1/ 17. Therefore
√
√
1 1 + 17 n
1 1 − 17 n
g(n) = √ ·
−√ ·
2
2
17
17
is the solution to our recurrence.
(b) We try to guess a solution by unwinding the formula for T (n):
T (n) = 2T (n − 1) + n2
= 2(2T (n − 2) + (n − 1)2 ) + n2
= 22 T (n − 2) + 2(n − 1)2 + n2
= 22 (2T (n − 3) + (n − 2)2 ) + 2(n − 1)2 + n2
= 23 T (n − 3) + 22 (n − 2)2 + 2(n − 1)2 + n2 .
Continuing in this manner suggests the guess
T (n) = 2n T (0) + 2n−1 (1)2 + 2n−2 (2)2 + 2n−3 (3)2 + · · · + 20 (n)2 .
Since T (0) = 0, we can write
T (n) = 2n−1 · 12 + 2n−2 · 22 + 2n−3 · 32 + · · · + 20 · n2
2
22 32
n2
n 1
=2
+
+
+ ··· + n .
21 22 23
2
This sum is similar to the one in question 1(c) so we can try to evaluate it by the same
method. Let
12 22 32
n2
S = 1 + 2 + 3 + ··· + n.
2
2
2
2
Then
22 32
n2
2S = 12 + 1 + 2 + · · · + n−1
2
2
2
and we can group by denominator to write
2
n2 − (n − 1)2
n2
2 − 12 32 − 22
2
+
+ ··· +
− n.
S = 2S − S = 1 +
1
2
n−1
2
2
2
2
The terms in the middle sum are of the form (k + 1)2 − k 2 , which equals 2k + 1, so we
can rewrite S as
2·1+1 2·2+1 2·3+1
2 · (n − 1) + 1
n2
S =1+
+
+
+
·
·
·
+
−
21
22
23
2n−1
2n
1
2
n−1
1
1
1
n2
=1+2·
+ 2 + · · · + n−1 +
+ 2 + · · · + n−1 + n .
1
1
2
2
2
2
2
2
2
In question 1(c) we found that the first parenthesized sum equals 2 − (n + 1)2−(n−1) .
The second parenthesized sum is a geometric sum and equals 1 − 2−n−1 . The expression
simplifies to S = 6 − n2 · 2−n − 4n · 2−n − 6 · 2−n , which gives the guess
T (n) = 2n S = 6 · 2n − n2 − 4n − 6
We prove this is correct by induction on n. When n = 0, both T (n) and 2n S =
6 · 2n − n2 − 4n − 6 are zero. Now assume T (n) = 2n S = 6 · 2n − n2 − 4n − 6 for some
n. Then
T (n + 1) = 2T (n) + n2 = 6 · 2n − 2n2 − 8n − 12 + (n + 1)2
= 6 · 2n+1 − n2 − 6n − 11 = 6 · 2n+1 − (n + 1)2 − 4(n + 1) − 6
as it should be.
Alternative solution: We can try to relate the recurrence for T (n) with the homogeneous recurrence T 0 (n) = 2T 0 (n − 1). Since the non-homogeneous term is quadratic, it
is sensible to venture a guess of the form T 0 (n) = T (n) + an2 + bn + c for some a, b, c to
be determined. To obtain T 0 (n) = 2T 0 (n − 1), it must be that
T (n) + an2 + bn + c = 2(T (n − 1) + a(n − 1)2 + b(n − 1) + c).
As T (n) = 2T (n − 1) + n2 , this implies
n2 + (an2 + bn + c) = 2(a(n − 1)2 + b(n − 1) + c)
for all n. This equation simplifies to
(a − 1)n2 + (−4a + b)n + c = 0
which is satisfied for all n if a − 1 = 0, −4a + b = 0, and 2a − 2b + c = 0. This solves
to a = 1, b = 4, c = 6. The function T 0 (n) = T (n) + n2 + 4n + 6 indeed satisfies the
recurrence T 0 (n) = 2T 0 (n − 1). The initial condition for T 0 (n) is T 0 (0) = T (0) + 6 = 6.
The solution to this recurrence is T 0 (n) = 6 · 2n , so T (n) = 6 · 2n − n2 − 4n − 6 for all n.
(c) We try to guess a solution by unwinding the formula for F (n):
n
n
F (n) = 3F ( ) +
3
3
n
n
n
= 3(3F ( 2 ) + 2 ) +
3
3
3
n
n n
2
= 3 F( 2) + +
3
3
3
n
n
n n
2
= 3 (3F ( 3 ) + 3 ) + +
3
3
3
3
n n n
3
3
= 3 F (n/3 ) + + + .
3
3
3
Continuing in this manner suggests the guess
F (n) = 3log3 n F (1) + log3 (n) ·
n
.
3
Since F (1) = 1, we can write
1
F (n) = n + n log3 n.
3
We prove this is correct by induction on n. When n = 1, both F (n) and n + 13 n log3 n
are zero. Now assume F (n) = n + 13 n log3 n for some n. Then
F (3n) = 3F (n) + n = 3n + n log3 n + n = 3n + n log3 n + n log3 (3) = 3n + n log3 (3n)
as it should be.
4. Sort the following functions in increasing order of asymptotic growth. (For example, if you
are given the functions n2 , n, and 2n , the sorted list would be n, n2 , 2n .) Show that for every
pair of consecutive functions f, g in your list, f is o(g).
n
2
(a) en , nn , (log n)2 , 22 , n log n, n, 2n .
(b) The tower function T (n) is given by the recursive formula T (1) = 2 and T (n + 1) = 2T (n)
for n ≥ 1. Where do the functions T (n) and T (log n) (assuming n is a power of two) fit
into the list in part (a)?
Solution:
(a) The sorted list is
2
n
(log n)2 , n, n log n, en , nn , 2n , 22 .
We now argue the correctness of this ordering:
(log n)2 is o(n): this follows from Theorem 5 of the Lecture 7 notes.
n is o(n log n): The ratio n/n log n is equal to 1/ log n, which becomes eventually smaller
than any number so n is o(n log n).
n log n is o(en ): To compare n log n and en , we can first say n log n is at most n2 and
then apply Corollary 6 from Lecture 7 to obtain that n2 is o(en ). Therefore, n log n
must also be o(en ).
en is o(nn ): The ratio en /nn equals (e/n)n . For n ≥ 3, e/n is less than 0.99 and (e/n)n ≤
0.99n , which eventually becomes and stays smaller than any positive constant. So
we conclude that en must be o(nn ).
2
2
2
nn is o(2n ): The ratio nn /2n equals 2n log n−n = 2n(log n−n) . When n ≥ 2, log n − n is
at most one so the ratio is at most 2−n , which eventually becomes and stays smaller
than any positive constant.
2
n
2
n
2
n
n
2 is o(22 ): The ratio 2n /22 equals 2n −2 . It can be proved by induction on n that
n2 < 2n−1 for all n ≥ 8. Therefore the desired ratio becomes eventually smaller
n−1
n
n−1
n−1
than 22 −2 = 2−2 . As n grows, 2n−1 tends to infinity and so 2−2
becomes
and stays eventually smaller than any constant.
(b) They come at the very end of the list in the order T (log n), T (n). To show this, first we
prove by induction that T (n) ≥ 2n−1 ≥ n for all n: This is true for n = 1, and assuming
it is true for a given n ≥ 1,
T (n + 1) = 2T (n) ≥ 2n = 2 · 2n−1 ≥ 2 · n ≥ n + 1,
it is also true for n + 1.
n
Here is one way to show that 22 = o(T (log n)). We can write
2n
2
22
log n
=2
22
2log log n
=2
.
By L’Hôpital’s rule from calculus, log log n is o(log n − 4). Since log n − 4 ≤ T (log n − 4),
we get that
2
22
2log log n
22
=2
2o(T (log n−4))
22
o(2T (log n−4) )
=2
2o(T (log n−3))
= 22
o(T (log n−2))
= 22
= 2o(T (log n−1)) = o(T (log n)).
These equations use the fact that if f is o(g) and g(n) tends to infinity as n gets large
then 2f must be o(2g ). This is true because the ratio 2f (n) /2g(n) = 2f (n)−g(n) eventually becomes smaller than 2−g(n)/2 (as f (n) ≤ g(n)/2 for sufficiently large n, which is
eventually smaller than any constant.
For the second inequality, since T is an increasing function, T (n − 1) = log T (n) =
o(T (n)), and so T (log n) ≤ T (n − 1) = o(T (n)).
5. Bottle T has 4 litres of tea and bottle C has 4 litres of coffee. In each step you pour 1 litre of
liquid from bottle T into bottle C, stir, pour back 1 litre of liquid from bottle C into bottle
T, and stir again. (This is a recipe for Yuanyang.) Let f (n) be the amount of coffee in bottle
T after n steps.
(a) Calculate the values f (0), f (1), and f (2).
(b) Write a recurrence for f (n).
(c) Solve the recurrence from part (b).
(d) What is limiting value of f (n) as n approaches infinity? How many steps do you need
to perform to approach this value within 0.01 litres?
Solution:
(a) Initially, bottle T only contains 4 litres of tea, so f (0) = 0.
In 1st step, we pour 1 litre of tea from bottle T to bottle C. So, bottle C has 1 litre of
tea and 4 litres of coffee. After stiring, we pour 1 litre of liquid, including 4/5 of coffee,
from bottle C to bottle T. Therefore, bottle T has 4/5 of coffee and so f (1) = 4/5. Also,
bottle C has 4 − 4/5 = 16/5 litres of coffee.
In 2nd step, we pour 1 litre of liquid, including 1/4 · 4/5 = 1/5 litres fo coffee from bottle
T to bottle C. So, bottle C has 5 litres of liquid, including 16/5 + 1/5 = 17/5 litres of
coffee. After stiring, we pour 1 litre of liquid, including (17/5)/5 = 17/25 litres of coffee,
from bottle C to bottle T. Therefore, bottle T has 4/5 − 1/5 + 17/25 = 32/25 litres of
coffee and so f (2) = 32/25.
(b) Note that both bottles remain 4 litres of liquid after each step. After n steps, bottle T
has f (n) litres of coffee and bottle C has 4 − f (n) litres of coffee, since the total amount
of coffee must be 4.
We start (n + 1)th step. We first pour 1 litre of liquid, containing 1 · f (n)
litres of
4
coffee, from bottle T to bottle C. Then, bottle C has 5 litres of liquid, including 4 −
f (n) + 14 f (n) = 4 − 34 f (n) litres of coffee. Next, we pour 1 litre of liquid, including
3
1 · 4 − 34 f (n) /5 = 45 − 20
f (n) litres of coffee, from bottle C to bottle T. After that,
1
3
bottle T contains f (n) − 4f (n) + 45 − 20
f (n) litres of coffee, that is, f (n + 1) =
4
3
4
3
1
f (n) − 4 f (n) + 5 − 20 f (n) = 5 + 5 f (n).
(c) We try to guess a solution by unwinding the formula for f (n):
4 3
+ f (n − 1)
5 5
2
4
3
4
3
· +
f (n − 1)
= +
5
5
5
5
2
3
4
3
4
3
4
3
= +
· +
· +
f (n − 1).
5
5
5
5
5
5
f (n) =
Continuing in this manner suggests the guess
4
f (n) = +
5
2
3
n−1
n
3
4
3
4
3
4
3
4
3
· +
· + ··· +
· +
· f (0)
· +
5
5
5
5
5
5
5
5
5
Since f (0) = 0, we can write
2
3
n−1
3
4
3
4
3
4
3
4
· +
· +
· + ··· +
·
5
5
5
5
5
5
5
5
4
3 n
1− 5
= 5
1 − 35
n
3
=2−2
5
f (n) =
4
+
5
We prove this is correct by induction
on n. When n = 0, both f (0) and 2 − 2
3 n
2. Now assume f (n) = 2 − 2 5 for some n. Then
4 3
4 3
f (n + 1) = + f (n) = +
5 5
5 5
3 n
5
are
n n+1
3
4 6 6 3 n
3
2−2
= + −
=2−2
5
5 5 5 5
5
as it should be.
(d) Since 35 < 1, it is easy to see lim f (n) = lim 2 − 2
n→∞
n→∞
3 n
5
= 2. So, the limiting value
of f (n) is 2.
Supposef (n) approaches to 2 within 0.01 liters after n0 steps. Then, 0.01 > 2 − f (n) =
n
3
2 − 2 35 . The solution of this inequality is n0 > log( 0.01
2 )/ log 5 = 10.3721. Therefore
11 steps are needed.
6. You want to move the Towers of Hanoi, but now you have four poles instead of three. The
rules are the same: n disks are initially stacked up from largest at the bottom to smallest on
top on the leftmost pole. The objective is to move them to the rightmost pole one by one so
that at no point does a larger disk cover a smaller one.
Consider the following strategy: If n ≤ 10, ignore one of the poles and apply the solution
from class for three poles. If n > 10, recursively move the top n − 10 disks to the second pole,
stack up the bottom 10 disks onto the last pole using the other three poles only, and then
recursively move the n − 10 remaining disks from the second pole to the last pole.
Let T (n) be the number of steps that it takes to move the whole stack of n disks.
(a) Write a recurrence for T (n). Explain why your recurrence is correct.
(b) Show that the recurrence from part (a) satisfies T (n) = O(2n/10 ).
√
(c) (Extra credit) Can you come up with a different strategy in which 2O(
sufficient?
n)
moves are
Solution:
(a) The number of moves the strategy makes for n disks and 4 poles equals twice the number
of moves for n − 10 disks and 4 poles, plus the number of moves for 10 disks and 3 poles
which equals 210 − 1 = 1023. Therefore the recurrence is
T (n) = 2T (n − 10) + 1023
for n > 10 and T (n) = O(1) for n ≤ 10.
(b) For n sufficiently large,
T (n) = 2T (n−10)+1023 = 22 T (n−2·10)+2·1023+1023 = 23 T (n−3·10)+(1+2+22 )1023.
After bn/10c steps, we get
T (n) = 2bn/10c T (n − bn/10c · 10) + (1 + 2 + · · · + 2bn/10c ) ≤ 2n/10 T (k) + (2bn/10c+1 − 1)
for some k between 1 and 10. The last expression is O(2n/10 ).
√
(c) When n ≥ 2, recursively move the top n − b nc disks to the second pole, stack up
√
the bottom d ne disks onto the last pole using the other three poles only, and then
√
recursively move the n − d ne remaining disks from the second pole to the last pole.
This gives the recurrence
√
√
T (n) = 2T (n − d ne) + 2d ne − 1
for the number of moves. Since T is an increasing function for every k in the range
n/2 ≤ k ≤ n, we can write
√
√
p
√
T (k) = 2T (k − d ke) + 2d ke − 1 ≤ 2T (k − d n/2e) + 2d ne .
Therefore for n sufficiently large
√
p
n/2e) + 2d ne
√
p
≤ 22 T (n − 2d n/2e) + (1 + 2)2d ne
√
p
≤ 23 T (n − 3d n/2e) + (1 + 2 + 22 )2d ne .
T (n) ≤ 2T (n − d
Continuing for just enough steps t so that the argument of T (·) drops below n/2, we get
that
√
T (n) ≤ 2t T (bn/2c) + (2t − 1)2d ne
√
The value of t can be at most 2d n/2e , so
√
√
√
√
√
T (n) ≤ 2d n/2e T (bn/2c) + 2d n/2e · 2d ne ≤ 2d ne T (bn/2c) + 22d ne .
We can derive the inequality
√
T (n) + 1 ≤ 2d
ne
T (bn/2c) + 22d
√
ne
√
+ 1 ≤ 2 · 22
n
(T (bn/2c) + 1).
Iterating this formula down to n = 2, we get that
√
√
√ 2
√
√
√
T (n) ≤ 2 · 22 n · 22 n/2 · · · 22 ≤ 2 · 22 n(1+1/ 2+1/ 2 +... ) = 2O( n) .
ESTR 2004 mini-project You have to tile a 30 × 1 hallway with unlimited supply of 1 × 1
red tiles, 2 × 1 red tiles, and 2 × 1 blue tiles. In how many ways can you tile:
(a) A 30 × 1 hallway for which you are allowed to use all types of tiles.
(b) A 30 × 1 hallway for which you are allowed to use all types of tiles, but no two red tiles
are consecutive.
(c) A 30 × 3 hallway for which you are allowed to use all types of tiles.
(d) (Extra credit) A 30 × 3 hallway for which you are allowed to use all types of tiles, but
no two red tiles are adjacent (share a side).
Solution:
(a) The set of possible tilings can be written as the disjoint union of tilings that start with
each of the three types of tiles allowed. Therefore the number of possible tilings f (n) of
an n × 1 hallway satisfies the recurrence
f (n) = f (n − 1) + 2f (n − 2)
with initial conditions f (0) = 1 and f (1) = 1. I used the following python program to
calculate the values of f from 0 up to 30:
f = [1, 1]
for i in range(29):
f.append(f[-1] + 2*f[-2])
to obtain the value f (30) = 715, 827, 883.
(b) The set of possible tilings can be written as the disjoint union of tilings that start with
a blue tile, a 1 × 1 red tile followed by a blue tile, and a 2 × 1 red tile followed by a blue
tile. This gives the recurrence
g(n) = g(n − 2) + g(n − 3) + g(n − 4)
for the number of tilings g(n) of a n × 1 hallway. The initial conditions are g(0) = 1,
g(1) = 1, g(2) = 2, and g(3) = 2. A similar computer program as the one in part (a)
gives the value g(30) = 74, 594.
(c) For each proper subset S of {1, 2, 3} let hS (n) be the number of tilings of an n × 1
hallway in which the tiles in the first column that are in rows indexed by the set S are
missing. For simplicity of notation we will write h, h1 , h13 instead of h∅ , h{1} , h{1,3} etc.
We are interested in the value h(30). The objective is to write a system of recurrences
that expresses the values hS (n) for various sets S in terms of hS evaluated at smaller
inputs.
By symmetry we can conclude that h1 = h3 and h12 = h23 , so we only need to understand
the behaviour of the five functions h, h1 , h2 , h12 , and h13 . If we write the set of tilings
counted by hS (n) as a disjoint union of tilings depending of the manner in which the
first column is tiled we obtain the system of recurrences
h(n) = 5h(n − 1) + 12h1 (n − 1) + 2h2 (n − 1) + 8h12 (n − 1) + 4h13 (n − 1) + 8h(n − 2)
h1 (n) = 3h(n − 1) + 2h1 (n − 1) + 2h2 (n − 1) + 4h12 (n − 1)
h2 (n) = h(n − 1) + 4h1 (n − 1) + 4h13 (n − 1)
h12 (n) = h(n − 1) + 2h1 (n − 1)
h13 (n) = h(n − 1) + 2h2 (n − 1).
The initial conditions are h(0) = 1, h(1) = 5, and h1 (0) = h2 (0) = h12 (0) = h13 (0) = 0.
A computer program gives the answer
h(30) = 340722451615340460551911168278528
which is about 3.41 × 1032 .