Chapter 3 Summations

advertisement
Chapter 3 Summations
Arithematic Series
n
1 2  3  n  k 
k 1
1
n(n  1)   (n 2 )
2
e.g. Insertion Sort
Geometric Series (Exponential Series)
n
1  x  x 2  x3    x n   x k 
k 0
x n1  1
x 1
x  1, n  

x

k
k 0
1
1 x
n
Q.
 (2k  1) =?
k 1
Harmonic Series
1 1 1
1
    Hn
2 3 4
n
1 1 1 1 1 1
1
 1          k , n  2k
2 2 4 4 4 4
2
 1111
(k個)
1
 log n  O(1)
Q. Prove the following:
n
1
 2k  1  ln(
n )  o(1)
k 1

Some series can be obtained by integrating or differentiating other series.




1
x
kxk  x kxk 1  x ( x k )  x( x k )  x(
 1) 

1 x
(1  x) 2
k 0
k 1
k 1
k 1
Telescoping Series
n
a
k 1
k
 a k 1  a n  a 0
e.g.
n 1
n 1
1
1
1
1
 k (k  1)   k  k  1  1  n
k 1
k 1
Products
n
a
k
k 1
n
n
k 1
k 1
lg(  a k )   lg a k

Problem:
n
S   2  4k
k 1
n
n
n
n
k 1
k 1
k 1
k 1
lg S   lg( 2  4 k )   lg 2  lg 4 k   lg 2   2k  n  lg 2  (1  n)  n
 n(lg 2  1  n)  n  (2  n)
Q. Show a close form of the following product.
n
1
 (1  k
k 2
2
)
Bounding Summations
1. Mathematical Induction
 Problem. To prove
n
1
 k  2 n(n  1)
k 1
It holds for n=1
Suppose it holds for n, we will show that it holds for n+1
n 1
n
k 1
k 1
1
1
 k   k  (n  1)  2 n(n  1)  (n  1)  2 (n  1)(n  2)

n
3
k
Problem: Prove
 c  3n
k 0
It holds for n=1
Suppose it holds for n, we will show that it holds for n+1
n 1
3
k
k 0
c
1 1
 c  3n  3n 1  (  1)  3n 1  c  3n 1  (  )  c  3n 1
3
3 c
as long as
1 1
3
  1 i.e. c 
3 c
2

A fallacious proof for
n
 k  O ( n)
k 1
It holds for n=1.
Suppose it holds for n, we show that it holds for n+1 as follows:
n 1
n
k 1
k 1
 k   k  (n  1)  O(n)  n  1  O(n  1)
This is incorrect because
n 1
n
k 1
k 1
 k   k  n  1  c  n  (n  1)  c  (n  1)  c  (n  1) NOT  c  (n  1)
2. Bounding the terms
n
n
k  n  n
k 1
k 1
n
a
k 1
k
when
n
a
k 0
k
 n  amax
a k 1
 r 1
ak
 n  a0

n
a  a
k 0
k


k 0

0
 r k  a 0   r k  a0 
k 0
1
1 r
Problem: Prove
k
3
k 1
2
k
k 1
a k 1 3 k 1
k 1 1 2


 
k
ak
k 3 3
3k
for k  1

k
3
Thus
k 1


1 1
1

 3 1
2 3
3
1
3
Note that this

e.g.
k
ak 1
must be a constant, rather than a bound.
ak
1
k
k 1
a k 1
k

1
ak
k 1
But you cannot conclude that this summation converges.
3. Splitting summations
n
k 0 1
k 0
k 0
 ak   ak 
n
 ak   (1) 
k  k0
n
a
k  k0
k

e.g.
a k 1
ak
2
k2
k2  k2

  k  O(1)


k
k
k 0 2
k 0 2
k 3 2
(k  1) 2
k 1
(k  1) 2 8
 22


9
k
2k2
k
2
when k  3
lg n  2 1 1
lg n 
1 lg n 2 1 1
  i  1  lg n  1
e.g.    i
k 1 k
i 0 j 0 2  j
i 0 j 0 2
i 0
i
n
i
lg n 
Q. show the asymptotic upper bound is
n
k 

k 0
  2
(by using bounding each term and
letting n+R be a power of 2)
4. Approximation by Integral
See Fig. 3.1

n

n 1
m 1
m
n
f ( x)dx   f (k )  
n 1
k m
m
n
n
f ( x)dx   f (k )  
k m
m 1
f ( x)dx
if f(x) is a monotonically increasing function.
f ( x)dx
if f(x) is a monotonically decreasing function.

n 1
1
n
1
1
dx  
k
k 1 k
n
1
k 1 k
ln( n  1)  
n
1
n
1
 k  1  k  1 
k 1
n
1
k 2
1
dx  1  ln n
k
n
Q. Approximate
k
k 1
Exercise: 3.2-1.
3
w/ an integral
Chapter 4 Recurrences

Recall the execution T(n) for Merge Sort
 (1)

T ( n)  
n
2T ( 2 )   (n)
if n  1
n 1
For now, ignore the floor and ceiling.
 Substitution Method
1. Make a good guess
2. Substitute the values in the recurrence by using the guess
3. Verify its validity on both the recurrence and the boundary.

Problem:
n
T (n)  2T ( )  n
2
Guess T (n)  c  n lg n
n n
T (n)  2  c  lg  n  c  n(lg n  lg 2)  n  c  n lg n  c  n  n  c  n lg n
2 2
T (1)  1
T (1)  c  1  lg 1  0
NOT VALID!
Use T(2) as the boundary condition
T (2)  2  2  4
T (2)  c  2  lg 2  2  c when c  2


How to make a good guess?
Problem:
n
T (n)  2T (    17)  n
2
We can guess T (n)  c  n lg n
Exercise. Prove the above by using substitution method.


Add terms of lower order
Problem:
c  1
n
n
T ( n)  T (   )  T (   )  1
2
2
It is natural to guess T (n)  cn.
n
n
T (n)  c     c     1  c  n  1 NOT  cn
2
2
Guess T (n)  cn  b
n
n
T (n)  (c    b)  (c    b)  1  cn  2b  1  cn  b
2
2
b  1
 Pitfalls
Guess T (n)  O (n)
n
T (n)  2(c    )  n  cn  n  O(n)
2
 Wrong
Changing Variables
T (n)  2T
 n   lg n
Let m  lg n
m
2
T (2 )  2T (2 )  m
m
m
S ( m)  2  S ( )  m
2
S (m)  O(m lg m)
T (n)  O(lg n lg lg n)
Exercise: 4.1-2.
Iteration Method
n
n
n
n
n
n
T (n)  3T (   )  n  n  3(    3T   )  n  3   9(    3T   )
4
4
16 
4
16 
 64 
3
9
27
n  n 
n
 n  3   9   27      n  n  n  n    3log4 n
4
16
64
 4  16 
 64 

3
 n   ( )i   (n log4 3 )  4n  O(n)  O(n)
i 0 4
Recursive Trees
n
T (n)  2T ( )  n 2 see Fig. 4.1
2
n
2n
T ( n)  T ( )  T ( )  n
3
3
see Fig. 4.2
Q: Use iteration to solve T (n)  T (n  a)  T (a)  n
n
Exercise: Use recursion tree to solve T (n)  4T (   )  n
2
Generating Functions
(1  ax)(1  bx)(1  cx)
 1  (a  b  c)  x  (ab  bc  ac) x 2  abcx 3
n
n
n
n
n
(1  x) n  ( )  ( )  x  ( ) x 2  ( ) x 3    ( ) x n
0
1
2
3
n
n
n
n
n
e.g. ( )  ( )  ( )    ( )  2 n
0
1
2
n
 Problem:
n
n
n
( ) 2  ( ) 2    ( ) 2 =?
0
1
n
Method 1:
It is the constant term of
1
(1  x) n (1  ) n  x  n (1  x) 2 n
x
2n
coefficient of x n  ( )
n
Method 2. Use constructive combinatorics to choose n objects from 2n objects
choose i
choose n-i
n obj
 Q. Prove that
n
n
n
n
( )  2( )  3( )    n( )  n  2 n 1
1
2
3
n
n
n
n
n
( )  ( ) x  ( ) x 2    ( ) x n  (1  x) n
0
1
2
n
differentiating both sides
Characteristic Equations

Linear Recurrence Relation
n obj
an  an1  an2 (Fibonacci Seq)
Its characteristic equation is  2    1  0
where  is the characteristic root.
1 5
1 5
, 2 
2
2
The total solution is
1 
1 5 n
1 5 n
)  A2 (
)
2
2
a 0  0  A1  A2
a n  A1 (
1 5
1 5
 A2
2
2
1
1
A1 
, A2 
5
5
a1  1  A1 
 Problem:
an  6an 1  12an  2  8an 3  0
a0  1, a1  2, a2  8
 3  6 2  12  8  0
(  2) 3  0
an  ( A1n 2  A2 n  A3 )( 2) n
1
1
A1  , A2 
, A3  1
2
2
 Problem:
an  2an1  n  3 , a0=0.
Solve an  2an1  0 gives the homogenous solution
For the particular solution
Assume an  B  n  D
3B  n  3D  2 B  n  3
1
11
B , D
3
9
n 11
Thus an  A  (2) n  
3 9
16
a0  3  A 
9
Generating Function
A(2) n
Let A(x) be the generating function of the sequence (a0 , a1 , a2 ,) i.e.
A( x)  a 0  a1 x  a 2 x 2    a n x n  
 Problem: Solve
an  an1  2(n  1) , a0=2.



n 1
n 1
n 1
 an x n   an1 x n  2 (n  1) x n
A( x)  a 0  x  A( x) 
A( x) 
2x 2
(1  x) 2
a0  2
2x 2
2

3
(1  x) 1  x
n2
 1 


(1  x) 3 
term is 
(n  2)!
1
之 x n2
3
(1  x)
Therefore a n  n(n  1)  2

3  4  5    n n(n  1)

(n  2)!
2
Q. Using generating function to solve an  2an1  n  3

Problem: Solve the following recurrence equations:
an ,r  an 1,r 1  an 1,r
an , 0  1 n  0, an ,r  0 n  r
Fn ( x)  an , 0  an ,1 x  an , 2 x 2    an ,r x r  



r 1
r 1
r 1
 an,r x r   an1,r 1  x r   an1,r  x r
Fn ( x)  an , 0  xFn 1 ( x)  Fn 1 ( x)  an 1, 0
Fn ( x)  (1  x) Fn 1 ( x)
Fn ( x)  (1  x) Fn 1 ( x)

 (1  x) n  a0, 0  (1  x) n
n
an , r  ( )
r
Exercise: Solve a n ,r  a n ,r 1  a n 1,r
a n , 0  1, a n ,r  0 if n  r
Download