Presentation is loading. Please wait.

Presentation is loading. Please wait.

Appendix A: Summations Motivation: Evaluating and/or bounding sums are frequently needed in the solution of recurrences Two types of evaluation problems:

Similar presentations


Presentation on theme: "Appendix A: Summations Motivation: Evaluating and/or bounding sums are frequently needed in the solution of recurrences Two types of evaluation problems:"— Presentation transcript:

1 Appendix A: Summations Motivation: Evaluating and/or bounding sums are frequently needed in the solution of recurrences Two types of evaluation problems: Prove by induction that formula is correct Find the function that the sum equals or is bounded by Encountered both types in analysis of insertion sort

2 Prove by induction that  j=1 to n j = n(n+1)/2 Called the arithmetic sum Text p 1059

3 Use the arithmetic sum to evaluate the sums in the analysis of insertion sort runtime

4 Important sums to remember Arithmetic  k=1 to n k = n(n+1)/2 =  (n 2 ) Geometric  k=0 to n x k = (x n+1 – 1)/(x – 1) when x  1 Harmonic  k=1 to n (1/k) = ln(n) +  (1)

5 Alternate forms of geometric sum useful in tree analysis  k=0 to n-1 x k = (x n – 1)/(x – 1) when x  1 How do we show this is true?  k=0 to ∞ x k = 1/(1 – x) when |x| < 1

6

7 Integration and differentiation can be used to evaluate sums derivative: d{  f(x)}/dx =  df/dx integral:  dx {  f(x)} =   dx f(x) Example: eq. A.8 p1148 Show  k=0 to ∞ k x k = x/(1 – x) 2 when 0< |x| < 1

8 See bottom p1147 for simpler approach

9 Bounding sums Prove a bound by induction Bound ever term in sum Bound by integration monotone increasing and decreasing summands

10 Prove by induction on integers that  k=0 to n 3 k = O(3 n )

11 there exist c=4/3 such that 0<4<3c Similar argument applies n=2, etc. Property of sums independent of what we are trying to prove and (1/3 +1/c) 3/2; therefore, c=3/2 or larger will work in the definition of big O Hence  k=0 to n 3 k = O(3 n ) by definition 3 Base case n=0 is true < c3 n which implies

12 Example of bound sum by bounding every term Show that (n/2) 2 <  k=1 to n k < n 2

13

14 Bound by integration: monotone increasing summand Shaded area is integral of continuous function f(x) Sum equals area of “upper sum” rectangles Same f(x) different limits on integration Sum equals area of “lower sum” rectangles

15 Note the difference for monotone increasing and decreasing summand Method not applicable if summand is not monotone increasing or decreasing

16 Use bounding by integrals for informal proof that  k=1 to n k -1 =  (ln(n))

17

18 CptS 450 Spring 2015 [All problems are from Cormen et al, 3nd Edition] Homework Assignment 3: due 2/4/15 1.ex A.1-3 p 1149 2.ex A.1-6 p 1149 3.ex A.2-1 p 1156 (hint: use integration) 4.part a of prop A-1 p 1156 using bound each term


Download ppt "Appendix A: Summations Motivation: Evaluating and/or bounding sums are frequently needed in the solution of recurrences Two types of evaluation problems:"

Similar presentations


Ads by Google