{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

samp1

# samp1 - A LGORITHMS S AMPLE S OLUTIONS Sample Problems I 1...

This preview shows pages 1–4. Sign up to view the full content.

A LGORITHMS — S AMPLE S OLUTIONS Sample Problems I 1 Formulae you should know You should remember these properties from previous calculus classes: log a ( b · c ) = log a ( b ) + log a ( c ) , log a ( b/c ) = log a ( b ) - log a ( c ) , log a ( b c ) = c · log a ( b ) , c log a ( b ) = b log a ( c ) , 1 + x + x 2 + · · · + x n = x n +1 - 1 x - 1 . 2 Sample Problems 2.1 Summation Problem 1: Let S k n be the sum 1 k + 2 k + 3 k + · · · + n k . Then 1. Calculate S 1 n and S 2 n , and 2. Show that S k n = O ( n k +1 ) . Proof: 1. We recall the formulas ( x + 1) 2 = x 2 + 2 x + 1 and ( x + 1) 3 = x 3 + 3 x 2 + 3 x + 1 . Then S 2 n = 1 2 + 2 2 + 3 2 + · · · + n 2 = 1 + (1 + 1) 2 + (2 + 1) 2 + · · · + (( n - 1) + 1) 2 = 1 + (1 2 + 2 · 1 + 1) + (2 2 + 2 · 2 + 1) + · · · + (( n - 1) 2 + 2( n - 1) + 1) = (1 2 + 2 2 + · · · + ( n - 1) 2 ) + 2(1 + 2 + · · · + ( n - 1)) + n = ( S 2 n - n 2 ) + 2( S 1 n - n ) + n = S 2 n + 2 S 1 n - n ( n + 1) . Simplifying by S 2 n , one gets S 1 n = n ( n +1) 2 . 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Similarly, S 3 n = 1 3 + 2 3 + 3 3 + · · · + n 3 = 1 + (1 + 1) 3 + (2 + 1) 3 + · · · + (( n - 1) + 1) 3 = 1 + (1 3 + 3 · 1 2 + 3 · 1 + 1) + (2 3 + 3 · 2 2 + 3 · 2 + 1)+ · · · + (( n - 1) 3 + 3( n - 1) 2 + 3( n - 1) + 1) = (1 3 + 2 3 + · · · + ( n - 1) 3 ) + 3(1 2 + 2 2 + · · · + ( n - 1) 2 )+ +3(1 + 2 + · · · + ( n - 1)) + n = ( S 3 n - n 3 ) + 3( S 2 n - n 2 ) + 3 S 1 n - 1 + n = S 2 n + 3 S 2 n - n 3 - 3 n 2 + n + 3 · n ( n - 1) 2 = S 2 n + 3 S 2 n - n (2( n 2 +3 n - 1) - 3( n - 1)) 2 = S 2 n + 3 S 2 n - n (2 n 2 +3 n +1) 2 = S 2 n + 3 S 2 n - n ( n +1)(2 n +1) 2 . Simplifying by S 3 n , one gets S 2 n = n ( n +1)(2 n +1) 6 . 2. We recall that ( n + 1) k +1 = n k +1 + ( k + 1) n k + P k - 1 ( n ) , where P k - 1 is a polynomial of degree k - 1 . Then S k +1 n = 1 k +1 + 2 k +1 + 3 k +1 + · · · + n k +1 = 1 + (1 + 1) k +1 + (2 + 1) k +1 + · · · + (( n - 1) + 1) k +1 = 1 + (1 k +1 + ( k + 1) · 1 k + P k - 1 (1)) + (2 k +1 + ( k + 1) · 2 k + P k - 1 (2))+ · · · + (( n - 1) k +1 + ( k + 1) · ( n - 1) k + P k - 1 ( n - 1)) = (1 k +1 + 2 k +1 + · · · + ( n - 1) k +1 ) + ( k + 1)(1 k + 2 k + · · · + ( n - 1) k )+ +(1 + P k - 1 (1) + P k - 1 (2) + · · · + P k - 1 ( n - 1)) = ( S k +1 n - n k +1 ) + ( k + 1)( S k n - n k ) + O ( n k ) = S k +1 n + ( k + 1) S k n - n k +1 + O ( n k ) Simplifying S k n , one gets S k n = n k +1 k +1 - O ( n k ) , that is, S k n = O ( n k +1 ) . Problem 2: Calculate the sums n X k =0 k 2 k and n X k =0 k 2 2 k . Proof: Recall that n X k =0 x k = x n +1 - 1 x - 1 . By differentiation, one obtains: n X k =0 kx k - 1 = ( n + 1) x n ( x - 1) - x n +1 + 1 ( x - 1) 2 = nx n +1 - ( n + 1) x n + 1 ( x - 1) 2 . Multiplying by x , one gets: n X k =0 kx k = nx n +2 - ( n + 1) x n +1 + x ( x - 1) 2 , ( * ) and replacing x by 2, n X k =0 k 2 k = ( n - 1)2 n +1 + 2 . Differentiating ( * ) again, one obtains n X k =0 k 2 x k - 1 = ( n ( n + 2) x n +1 - ( n + 1) 2 x n + 1)( x - 1) 2 - 2( x - 1)( nx n +2 - ( n + 1) x n +1 + x ) ( x - 1) 4 . 2
Replacing x by 2, we obtain: n X k =0 k 2 2 k - 1 = n ( n + 2)2 n +1 - ( n + 1) 2 2 n + 1 - 2( n 2 n +2 - ( n + 1)2 n +1 + 2) = ( n 2 - 2 n + 3)2 n - 3 , that is, n X k =0 k 2 2 k = ( n 2 - 2 n + 3)2 n +1 - 6 . 2.2 Function Order Problem 3: Is 2 n +1 = O (2 n ) ? Is 2 2 n = O (2 n ) ? Proof: Yes. Take c = 2 and n 0 = 1 ; then, since 2 n +1 = 2 · 2 n for all n , we have that for each n 1 , 2 n +1 c 2 n . No. There are no c, n 0 such that for each n n 0 , 2 2 n c 2 n . To show this, assume there exist such c, n 0 . Then 2 2 n = 2 n · 2 n c · 2 n , which implies 2 n c . But no constant is bigger than 2 n . Contradiction. In fact 2 2 n = ω (2 n ) , since lim n →∞ 2 n / 2 2 n = lim n →∞ 1 / 2 n = 0 .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

samp1 - A LGORITHMS S AMPLE S OLUTIONS Sample Problems I 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online