Download HW 7 solutions

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Proofs of Fermat's little theorem wikipedia , lookup

Line (geometry) wikipedia , lookup

Weber problem wikipedia , lookup

Transcript
CS 173: Discrete Mathematical Structures, Fall 2008
Homework 7 Solutions
1. [20 points] Big-O notation
Prove that the following big-O relationships hold.
(a)
x2 +x
x+1
is O(x2 )
Solution: Note that
x2 +x
x+1
= x for x ≥ 0. Certainly x ≤ x2 for
x > 0, so if we choose k = 0 and C = 1, it is easy to see that
is O(x2 ).
x2 +x
x+1
(b) x3 is O(x4 ), but x4 is not O(x3 )
Solution: x3 ≤ x4 when x > 0, so choosing k = 0 and C = 1
show that x3 is O(x4 ). Now, imagine that x4 was O(x3 ). Then
there would exist some k and C such that x4 ≤ Cx3 for all x > k.
Dividing through by x3 gives x ≤ C. But C is a constant, while
x can be arbitrarily large, so no such C and k exist, and x4 is not
O(x3 ).
(c) 10x + 100 is Θ(x)
Solution: We must show that 10x + 100 is O(x) and Ω(x). First,
clearly for x > 0 it is the case that 10x + 100 ≥ x, so choosing
k = 0 and C = 1 shows that 10x + 100 is Ω(x). Secondly, if
x > 100 then 10x + 100 ≤ 11x, so choosing k = 100 and C = 11
shows that 10x + 100 is O(x). Thus, 10x + 100 is Θ(x).
(d) log10 x is Θ(log2 x)
Solution: Note that by the change-of-base formula, log10 x =
log2 x
1
log2 10 , so choosing k = 0 and C = log2 10 shows that log10 x is
both O(log2 x) and Ω(log2 x) – in other words, it is Θ(log2 x).
1
2. [10 points] Induction
Define the function f on the natural numbers by:
(1) f (0) = 0
(2) For every k > 0, f (k) = k + f (b k3 c) + f (b k5 c) + f (b k7 c)
Use strong induction to prove that f (k) < 4k for every k > 0.
Solution: Base case: f (1) = 1 + 3f (0) = 1 < 4.
Inductive step: Assume f (j) < 4j for all 0 < j < k. We must show
that f (k) < 4k. First, consider the case where k < 3. Then b k3 c, b k5 c,
and b k7 c are all equal to 0, and f (k) = k which is less than 4k (since
k > 0).
Next, consider the case where k ≥ 3. Then b k3 c > 0, so we can apply
the inductive hypothesis to get f (b k3 c) < 4b k3 c. Since bkc ≤ k, this
implies that f (b k3 c) < 4k
3 .
Now, b k5 c is either greater than or equal to 0. In the former case,
following the above line of reasoning for b k3 c, we find that f (b k5 c) <
4k
k
5 . In the latter case, f (0) = 0, so it is certainly the case that f (b 5 c) <
k
4k
4k
5 . Similarly, we can show that f (b 7 c) < 7 .
4k
4k
Adding the terms together gives f (k) < k + 4k
3 + 5 + 7 =
is less than 4k for k > 0. Thus, for all k > 0, f (k) < 4k.
389k
105 ,
which
Alternate solution: Alternatively, we can simplify the inductive step
by proving more base cases.
Base cases: f (1) = 1 + 3f (0) = 1 < 4.
f (2) = 2 + 3f (0) = 2 < 8.
f (3) = 3 + f (1) + 2f (0) = 4 < 12.
f (4) = 4 + f (1) + 2f (0) = 5 < 16.
f (5) = 5 + f (1) + f (1) + f (0) = 7 < 20.
f (6) = 6 + f (2) + f (1) + f (0) = 9 < 24.
Inductive step: Assume f (j) < 4j for all 0 < j < k, where k ≥ 7.
We must show that f (k) < 4k. Since k ≥ 7, b k3 c, b k5 c, and b k7 c are
all at least 1, and so we can apply our inductive hypothesis to get
f (k) = k + f (b k3 c) + f (b k5 c) + f (b k7 c) < k + 4b k3 c + 4b k5 c + 4b k7 c. Since
4k
4k
389k
bxc ≤ x, we know that f (k) < k + 4k
3 + 5 + 7 = 105 , which is less
than 4k for k > 0. Thus, for all k > 0, f (k) < 4k.
2
3. [4 points] Recursive definition 1
Define the set S ⊆ Z2 by
(1) (0, 0) ∈ S
(2) If (x, y) ∈ S, then (x + 3, y + 3) ∈ S.
(3) If (x, y) ∈ S, then (x − 1, y + 2) ∈ S.
(4) If (x, y) ∈ S, then (x + 1, y − 2) ∈ S.
Describe the contents of S in words, draw a picture of the set, and
briefly justify your answer.
Solution:
By applying rules 3 and 4 to the base case, we can see that S contains
points on the line y = −2x, spaced at regular intervals. By applying
rule 2 to the points on this line, we get points on the parallel line
y = −2x+9. (It is easy to check that this is the line parallel to y = −2x
that contains the point (3, 3)). By repeating this process, we get a
grid formed from all the points with integer coordinates on the lines
y = −2x + 9k, for all natural numbers k. (Note that this is just one of
many possible descriptions of the set.)
A section of the graph of S looks like this:
3
4. [6 points] Recursive definition 2
(a) Suppose that A = (x, y) and B = (p, q) are 2D points with real
coordinates. Here is the definition of a simple, familiar geometrical object based on A and B. Name it!
X(A, B) = {(αx + (1 − α)p, αy + (1 − α)q) : α ∈ [0, 1]}
Remember that [0, 1] is the set of real numbers between 0 and 1,
inclusive.
Solution: X(A, B) is the line segment between (x, y) and (p, q).
(b) The set T ∈ R2 is defined by
(1) (1, 0), (1, 3), (4, 0) ∈ T
(2) If (x, y) ∈ T , then (−x, y) ∈ T .
(3) If (x, y) ∈ T and (p, q) ∈ T , then
(αx + (1 − α)p, αy + (1 − α)q) ∈ T , for every α ∈ [0, 1],
Describe the contents of T in words, draw a picture of the set,
and briefly justify your answer.
Solution: Given the result from part a, rule 3 says that for any
two points in T , all the points on the line segment between them
are also in T . What are the implications of this rule?
First, it is certainly the case that the line segments between the
three points in rule 1 are in T – in other words, the edges of
the triangle whose corners are (1, 0), (1, 3), and (4, 0) are in T .
Let’s call this triangle R. Furthermore, we can apply rule 3 to the
points added in this way, so the line segment between any two
points on the edge of the triangle is also in T . Thus, the entire
interior of the triangle R is in T .
Now, applying rule 2 adds the reflection of the triangle R over
the y-axis. So our set T now contains two triangles. Applying
rule 3 again, T must also contain all the line segments between
points in the triangle R and points in the reflection of R. So
T also contains the rectangular area between the two triangles.
In short, T contains the trapezoid with corners at (1, 3), (4, 0),
(−1, 3), and (−4, 0).
The graph of T is:
4
A clarification on terminology – for clarity, I’ve said that a line
segment is in T if all the points on the line segment are in T , and
an area is in T if all the points in the area are in T . T does not
actually contain any line segments or areas, only points on or in
them.
5. [10 points] Structural induction
Define a set M ∈ Z2 is defined by
(1) (0, 1) ∈ M
(2) If (x, y) ∈ M , then (x + 1, y + 2x + 3) ∈ M
(a) Starting with (0, 1), write out the six pairs with the smallest first
coordinates.
Solution: (0, 1), (1, 4), (2, 9), (3, 16), (4, 25), (5, 36)
(b) State the (simple) relationship that holds between the first and
second coordinates of all pairs in M .
Solution: If the pair (x, y) is in M , then y = (x + 1)2 .
(c) Use structural induction to prove that your answer to (b) is correct.
Solution:
Base case: (0 + 1)2 = 1. So the relationship holds for (0, 1).
Inductive step: Assume that for some (x, y) ∈ M , y = (x+1)2 . We
must show that the property holds for (x + 1, y + 2x + 3), in other
words, that y+2x+3 = ((x+1)+1)2 . That is, y+2x+3 = (x+2)2 .
We know from the inductive hypothesis that y = (x + 1)2 . So
y +2x+3 = (x+1)2 +2x+3 = x2 +2x+1+2x+3 = x2 +4x+4 =
(x + 2)2 .
Thus, for any pair (x, y) in M , y = (x + 1)2 , by structural induction.
5