Presentation is loading. Please wait.

Presentation is loading. Please wait.

Appendix A: Summations Two types of summation problems in algorithms: 1) Prove by induction that formula is correct 2) Find the function that the sum equals.

Similar presentations


Presentation on theme: "Appendix A: Summations Two types of summation problems in algorithms: 1) Prove by induction that formula is correct 2) Find the function that the sum equals."— Presentation transcript:

1 Appendix A: Summations Two types of summation problems in algorithms: 1) Prove by induction that formula is correct 2) Find the function that the sum equals or is bounded by We encountered both types in analysis of insertion sort

2 Proof that example of induction on integers using if S(n-1) then S(n) How does “setup” change to use if S(n) then S(n+1)? What is I.H. in this method? Setup to use “if S(n-1) then S(n)” I.H.

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) Geometric series  k=0 to ∞ x k = 1/(1 – x) when |x| < 1

5 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

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

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

8 Base case n=1  k=0 to 1 3 k = 1+3=4 O(3 n=1 ) = O(3) Does 4 = O(3)? there exist c=4/3 such that 0<4<3c Similar argument applies n=2, etc. c 1 = O(c 2 ) for any constants c 1 and c 2.

9 Proof of  k=0 to n 3 k = O(3 n ) using if S(n-1) then S(n) Setup  k=0 to n 3 k =  k=0 to n-1 3 k + 3 n Assume (I.H.)  k=0 to n-1 3 k = O(3 n-1 ) Based on our assumption: there exist a c>0 such that  k=0 to n-1 3 k < c 3 n-1 To find the constraints on c and n, solve the inequality  k=0 to n 3 k < c 3 n-1 + 3 n < c 3 n RTA

10 Proof of  k=0 to n 3 k = O(3 n ) using if S(n-1) then S(n) To find the constraints on c and n, solve the inequality  k=0 to n 3 k < c 3 n-1 + 3 n < c 3 n Focus on the 2 nd inequality c 3 n-1 + 3 n < c 3 n c 3 n (1/3+ 1/c) < c 3 n (1/3+ 1/c) < 1 Since any dependence on n has been eliminated, we could use = to solve for c = 3/2. This approach cannot be used when the inequality still depends on both c and n. Result will be c as a function of n, which does not satisfy the definition of Big O.

11 When the problem includes the statement “Show the constraints on c and n.”, I am asking for a solution of the inequality even if a constant value of c can be found using the = option. If there is not constraint on n, simply state this and assign n 0 a value of 1.

12 CptS 350 Spring 2016 [All problems are from Cormen et al, 3nd Edition] Homework Assignment 5: due 2/5/16 1.ex A.1-3 p 1149 hint: use derviatives 2.ex A.1-6 p 1149 hint: let g k (n)=O(f k (n)) and use definition of Big O

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

14

15 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

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

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

18

19 CptS 350 Spring 2016 [All problems are from Cormen et al, 3nd Edition] Homework Assignment 6: due 2/8/16 1.ex A.2-1 p 1156 (hint: use integration) 2.part a of prop A-1 p 1156 using bound each term


Download ppt "Appendix A: Summations Two types of summation problems in algorithms: 1) Prove by induction that formula is correct 2) Find the function that the sum equals."

Similar presentations


Ads by Google