Quiz 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1. (20%) Prove that 1 • 1! + 2 • 2!+···+ n • n! = (n + 1)!

− 1 whenever n is a positive
integer. (You can use * to represent multiplication.)
Basis step: 1 * 1!=2! - 1
Recursive step: 1*1! + 2*2! + · · · + k*k! + (k + 1)*(k + 1)! = (k + 1)! − 1 + (k + 1)*(k
+ 1)! = (k + 1)!*(1 + k + 1) − 1 = (k + 2)! − 1

2. (35%) For a full binary tree T, n(T) and h(T) denote the number of vertices and the
height of T, respectively.
Use structural induction to show that n(T) ≥ 2h(T) + 1
Basis step: The root r is a leaf of the full binary tree with exactly one vertex r. This
tree has no internal vertices.
Recursive step: The set of leaves of the tree T = T1 · T2 is the union of the sets of
leaves of T1 and of T2. The internal vertices of T are the root r of T and the union
of the set of internal vertices of T1 and the set of internal vertices of T2.
Symbols you may need: ≤ ≥
Basis step: For the full binary tree consisting of just a root, the result is true
because n(T)=1 and h(T)=0, and 1 ≥ = 2*0 + 1.
Inductive step: Assume that n(T1) ≥ 2h(T1)+1 and n(T2) ≥ 2h(T2)+1 where
n(T1) = 1+n(T1) and h(T)=1+max(h(T1), h(T2)). Therefore n(T) = 2 + n(T1) + n(T2)
≥ 1 + 2h(T1)+1 + 2h(T2)+1 ≥ 1+2
3. (15%) Give a recursive algorithm for finding the sum of the first n positive
integers by filling the blanks below:

Procedure sum of first(n: positive number)


if ____ then return ___
else return _________________
n=1
1
Sum of first (n-1)+n

4. (30%) Use strong induction to show that every positive integer n can be written
as a sum of distinct powers of two, that is, as a sum of a subset of the integers 2 0
= 1, 21 = 2, 22 = 4, and so on. Let P(n) be the statement “n can be written as a sum
of distinct powers of two”. You can use 2^0 to represent 20; use (k + 1)/2 to
k+1
represent ; use * to represent multiplication
2

[Hint: For the inductive step, separately consider the case where k + 1 is even and
where it is odd. When it is even, note that (k + 1)/2 is an integer.]
Symbols you may need: ≤ ≥ ∈ ∀

Basis step: P(1) is true because 20 = 1


Inductive step: Assume P(i) is true ∀𝒊 ≤ 𝒌, 𝒊 ∈ 𝑵.
If k+1 is even, (k+1)/2 is an integer smaller than k, and P((k+1)/2) is true.
Therefore, P(k+1) is also true because k+1 can be written as 2 ∗(sum of
(k+1)/2).
If k+1 is odd, it can be written as 20 +2*(sum of k/2), which means P(k+1) is true.
This completes the inductive step.

You might also like