HW 1
HW 1
HW 1
N (N − 1)...(N − n + 1) N!
P = n
=
N (N − n)!N n
(b).Let random varible X be the times of coin-throwing
∞
X 1
EX = i(1 − p)i−1 p =
i=1
p
here ri+2 < ri /2, so r1 < a/2, r3 < a/22 ... r2 < b/2, r4 < b/22 ... until ri = 0
So at most we have ⌈log a⌉ + ⌈log b⌉ times O(1), so the running time is O(log a + log b)
Problem 4 (40 points).
1. We prove for h2 = 3, h1 = 2
After calling INSERTIONSORT(h2 ),we have S[1] ≤ S[4] ≤ S[7]..., S[2] ≤ S[5] ≤ S[8]..., S[3] ≤
S[6] ≤ S[9]... And INSERTIONSORT(h1 ) sort independently on S1 = {S[1], S[3], ...} and
S2 = {S[2], S[4], ...} to form a new array A[1], A[2], A[3].... What we want to prove is that
A[i] ≤ A[i + 3], 1 ≤ i ≤ n − 3
We have |S1 | = (n + 1)/2, |S2 | = n/2. When i is odd, because S[1] ≤ S[4], S[3] ≤ S[6]..., there
are (n − 2)/2 elements in S1 smaller than a specific element in S2 , after sort independently,
A[i + 3] is bigger than (i + 1)/2 elements in S2 , so it is bigger than (i + 1)/2 elements in S1 , so
A[i] ≤ A[i + 3] ,that is to say, A[1] ≤ A[4], A[3] ≤ A[6]. Similarly, we can prove for i is even.
2. Lemma:if ht+1 , ht is co-prime, ∀n ≥ ht ht+1 , ∃x, y ∈ N, s.t. xht+1 + yht = n
Proof. When gcd(ht+1 , ht )=1, we have a′ , b′ ∈ Z s.t. a′ ht+1 + b′ ht = 1, let x′ = a′ n, y ′ = b′ n,
we have x′ ht+1 + y ′ ht = n = xht+1 + yht , so x = x′ + kht , y = y ′ − kht+1 , k ∈ Z so n can be
written in the unique form
n = xht+1 + yht , 0 ≤ x < ht
When n > ht ht+1 , cause 0 ≤ x < ht , we must have y ≥ 0
Now we want to prove that each element will be moved by at most ht+1 ht /ht−1 steps when
ht+1 , ht is co-prime.
First we show that ∀j, l < j − ht+1 ht ,we have A[l] ≤ A[j]. This is because j − l > ht ht+1 , so
∃x, y ∈ N s.t. xht+1 + yht = j − l, so