You are on page 1of 7

COMP2804: Discrete Structures II

Assignment 2
Question 1
Write your name and student number on the top of the assignment

Question 2

In Lecture 6 we proved that any subset of {1, … , 2n} of size at least n + 1 contains a
divisible pair; a pair distinct values x and y such that x/y is an integer.

1. Using the same approach, prove that any subset of S⊆ {1, … , 3n} of size at least
2n + 1 contains a pair of distinct values a and b such that a/b is a power of 3; i.e.,
a/b = 3k for some positive integer k.
Answer 1

Letx1 , … , x2n+1 be a (2n + 1) -element subset of {1, … , 3n} . For each


i ∈ {1, … , 2n + 1}, repeatedly remove factors of 3 from xi to express it as
xi = yi 3ti where ti ≥ 0 is an integer and y1 mod 3 ∈ {1, 2}.
Now, the number of integers y ∈ {1, … , 3n} such that y mod 3{1, 2} is 2n.
Therefore, by the Pigeonhole Principle, there must exist disting i, j ∈ {1, … , 2n + 1}
such that yi = yj . Since xi ≠ xj , it must be that ti ≠ tj . Without loss of generality we
may assume that ti > tj . Then

xi yi ⋅ 3ti 3ti ti −tj k


= t = t = 3 = 3 ,
xj yj ⋅ 3 j 3j
where k = ti − tj is a positive integer, as required.
Question 3

1
:
Suppose that we want to place disks of radius 1 so that

their centers are all contained in a single disk of radius r ; and


no pair of disks overlap.

Answer the following questions

1. (Use something similar to the Pigeonhole Principle to) prove that it is impossible to place
more than (r + 1)2 disks in this way. (Hint: a disk of radius x has area πx2 .)
2
2. Explain, in words, why it is impossible to place more than (r + 1) − 1 disks this way.

Answer 3.1

Let D be a set of k disks that satisfy the conditions of the question. We need to show that
k ≤ (r + 1)2 . The area of each disk in D is π and, since they are disjoint, the area A of
their union is kπ . On the other hand, since all these disks have centers inside a disk of radius r ,
they are all contained in a disk B of radius r + 1 . The disk of radius r + 1 has area
π(r + 1)2 . Therefore, kπ ≤ π(r + 1)2 , so k ≤ (r + 1)2 .
Answer 3.2

In the previous question we already established that k ≤ (r + 1)2 . Since k is an integer, we


therefore only need to show that k < (r + 1)2 . In other words we need only show that
k ≠ (r + 1)2 . Suppose for the sake of contradiction that k = (r + 1)2 . Then
area(∪D) = π(r + 1)2 = area(B). This means that if we take away all the
disks in D from B , then there is no area left, i.e., area(B ∖ (∪D)) = 0. But this
certainly can't be the case since, for example, there are small areas near the boundary of B that
are not covered by any disk.

Question 4
:
This question involves a (fairly simple) recurrence equation. You probably want to watch the
beginning of Lecture 7 before attempting it.

We have two parallel shelves that can each hold n + 1 beer bottles. Each beer bottle is red,
green, or blue and we have infinitely many bottles of each colour. Someone has already glued a
red bottle to the leftmost location on the top shelf and a green bottle to the leftmost location on
the bottom shelf, so we still have to place n bottles on each shelf. We want to do this so that:

If two bottles are adjacent on one of the shelves then they should have different colours. (For
example, we should never have a red bottle immediately to the right of another red bottle).
If one bottle is placed directly above another bottle then these two bottles should have
different colours.

Let Fn denote the number of ways there are to place 2n additional bottles so that they satisfy
our requirements.

1. What is the value of F0 ?


2. Give a recurrence equation for Fn , when n ≥ 1.
n
3. Prove, by induction on n, that Fn =3 .

Answer 4.1

F0 ask how many ways we can place 0 bottles in addition to the two bottles that are already
placed. There is only one way to do this (by doing nothing), so F0 = 1.

Answer 4.2

To place 2n bottles, we must first place the first two bottles on each shelf and then place the
remaining n − 1 bottles on each shelf. There are already two bottles placed immediately to the
left of the first two bottles we want to place, and these already-placed bottles have different
colours. Suppose without loss of generality that they are red (top shelf) and green (bottom shelf).
Then the first two bottles we place can have colors (green,red), (green,blue), or (blue, red).
Therefore, there are 3 ways to place the first two bottles.

After we do this, we are left with the problem of placing n − 1 bottles on each of the two
shelves and the two leftmost bottles are preceded by already-placed bottles having two different
colours. By definition, there are Fn−1 ways to do this. This gives us the recurrence equation

1 if n = 0
Fn = {
3 ⋅ Fn−1 if n ≥ 1
:
Answer 4.3

This is an easy inductive prove. The base case n = 0 asserts that F0 = 30 = 1, which is
n−1
true by definition. For the inductive step, we assume that Fn−1 = 3 and now

Fn = 3 ⋅ Fn−1 = 3 ⋅ 3n−1 = 3n .
Question 5
This is the same setup as in Question 4, but now the requirements are different. Let t0 , … , tn
be the bottles placed on the top shelf and let b0 , … , bn be the bottles placed on the bottom
shelf. In both cases, these are listed in left-to-right order and the bottles t0 and b0 are already
glued to the shelf (t0 is red and b0 is green). Now we only require that,

for each i ∈ {0, … , n − 1}, the bottles in {ti , ti+1 , bi , bi+1 } should
include at least one red, at least one green, and at least one blue bottle.

Let Gn be the number of ways there are to place 2n bottles so that they satisfy our
requirements.

1. What are the values of G0 and G1 ?


2. Give a recurrence equation for Gn , when n ≥ 2.
1 – –
3. Prove, by induction on n, that Gn = 4
((2 − √6)n+1 + (2 + √6)n+1 ) .
Hint: Once you think you've figured out the recurrence for Part 1, you can use Wolfram Alpha to
solve it and see if it gives the solution you're expecting.

Hint: For Part 2, you must still prove by induction that the solution to your recurrence is indeed
1 – –
4 ((2 − √6)n+1 + (2 + √6)n+1 ) . Don't just say Wolfram Alpha told you so. Try

to follow the steps in the proof that the n th Fibonnaci number is (φ − ψ )/√5 . Notice
n n
that φ and ψ are special because they're the solutions to a certain quadratic equation.

Answer 5.1

As before G0 leaves us with only one option (do nothing), so G0 = 1. But G1 leaves us
with several options; we just have to make sure we include at least one blue bottle. This gives us
five options (blue, red), (red,blue), (blue, green), (green,blue) or (blue,blue), so G0 = 5.
Answer 5.2
Again, we start by placing the leftmost bottles that are not already placed, assuming that
immediately to the left of these there are two already-placed bottles of different colours. Without
loss of generality, these two already-placed bottles have colours (red,green).

There are two mutually exclusive possibilities:

1. The first two bottles we place have different colours. These could be (blue, red), (red,blue),
(blue, green), or (green,blue). After this we are now left with the problem of placing
n − 1 bottles on each shelf assuming that there are already two different coloured bottles
:
placed immediately to the left of these. By the Product Rule, the number of options in this
case is 4Gn−1 .
2. The first two bottles we place have the same colour, (blue,blue). Then we're not quite done,
since these two bottles have the same colour. In this case we place two more bottles, which
must be (red,green) or (green,red) and then we're left with the problem of placing n−2
bottles on each shelf assuming that there are already two different coloured bottles placed
immediately to the left of these. By the Product Rule, the number of options in this case is
2Gn−2 .
Therefore, by the Sum Rule, we have

⎧1 if n = 0
Fn = ⎨ 5
⎩ if n = 1
4Fn−1 + 2Fn−2 if n ≥ 2
Answer 5.3

The proof is by induction on n. For the two base cases n = 0 and n = 1, just evaluate the
given expression when n=0 and n=1 and verify that this gives values 1 and 5,
respectively.

Now for the inductive step we will assume that


1 – –
Fx = 4 ((2 − √6)x+1 + (2 + √6)x+1 ) for all x ∈ {0, … , n − 1}.
– 2
First observe that 2 ± √6 are the two solutions the quadratic equation x = 4x + 2. (1)

Then we get

Fn = 4Fn−1 + 2Fn−2 (from t


– – – –
= (2 − √6)n + (2 + √6)n + 12 (2 − √6)n−1 + 12 (2 + √6)n−1 (from the indu
– – – –
= (2 − √6)n−1 ((2 − √6) + 12 ) + (2 + √6)n + 12 (2 + √6)n−1
– – –
= 14 (2 − √6)n−1 (4(2 − √6) + 2) + (2 + √6)n (multiply

+ 12 (2 + √6)n−1
– – – –
= 14 (2 − √6)n−1 (2 − √6)2 + (2 + √6)n + 12 (2 + √6)n−1
– – –
= 14 (2 − √6)n+1 + (2 + √6)n + 12 (2 + √6)n−1
– –
= 14 (2 − √6)n+1 + 14 (2 + √6)n+1
– –
= 14 ((2 − √6)n+1 + +(2 + √6)n+1 )
Question 6
The sequence s0 , s1 , s2 , … of bitstrings is defined recursively as follows:

s0 = 1, i.e., the bitstring of length 1 consisting of one 1.


For n ≥ 1 , sn is obtained from sn−1 by replacing each 1 by 100 and by replacing
each 0 by 1.

0 = 1 1 = 100 2 = 10011 3 = 10011100100


:
For example, s0 = 1, s1 = 100, s2 = 10011, s3 = 10011100100, and so
on.

For each n ≥ 0, let Ln denote be the length of sn and let On be the number of 1's in sn .
1. Determine L0 , L1 , O0 , and O1 .
2. Prove that, for n ≥ 2, On = Ln−1 .
3. Prove that, for n ≥ 2 , Ln = Ln−1 + 2On−1
4. Write a recurrence for Ln that does not involve On and use Wolfram Alpha to solve it.
(You don't need to prove that Wolfram Alpha solved it correctly, just write the recurrence
and the solution Wolfram Alpha gave you for it)
5. Find a closed-form expression for On .

Answer 6.1

By inspection, L0 = 1, L1 = 3, O0 = 1 and O1 = 1.
Answer 6.2

For each n, let Zn be the number of zeros in sn , which means that Ln = On + Zn .


To make sn we start with sn−1 and replace each zero with a one (this makes Zn−1 ones in
sn ) and replace each one with a 100 (this makes On−1 ones in sn ). Therefore,
On = Zn−1 + On−1 = Ln−1 .
Answer 6.3

To make sn we start with sn−1 and replace each zero with a one (this contributes Zn−1 to
the length ofsn ) and replace each one with 100 (this contributes 3On−1 to the length of
sn ). Therefore Ln = Zn−1 + 3On−1 = Ln−1 + 2On−1 .
Answer 6.4
Using the answers to the last two questions we have
Ln = Ln−1 + 2On−1 = Ln−1 + 2Ln−2 . Wolfram Alpha says this solves to
Ln = 13 ((−1)n+1 + 2n+2 ).
Answer 6.5

From Parts 2 and 4, we know that On = Ln−1 = 13 ((−1)n + 2n+1 ) .


Question 7
Consider the following two recursive algorithms, each of which takes as input an integer
n ≥ 1 that is a power of two:
Foo(n):
if n = 1 then return 1
x = Foo(n/2)
return 1+x
:
Bar(n):
if n = 1 then return 1
x = Bar(n/2)
return n+x

1. Determine the output of Foo as a function of n


2. Determine the output of Bar as a function of n

Answer 7.1

F oo(n) = 1 + log2 n . Now we verify this by


By trying a few values, we guess that
0
induction. For the base case n = 1 = 2 and 1 + log2 (1) = 1 + 0 = F oo(1) .
For n ≥ 2 , we have

F oo(n) = 1 + F oo(n/2) = 1 + (1 + log2 (n/2)) = 1


+ (1 + log2 (n) − 1) = 1 + log2 (n)
Answer 7.2

Bar(n) = 2n − 1. For the base case n = 1 we


By trying a few values we guess that
have 2 × 1 − 1 = 2 − 1 = 1 = Bar(1). For n ≥ 2 we have

Bar(n) = n + Bar(n/2) = n + 2(n/2) − 1 = 2n − 1 .


:

You might also like