Summations Alexandra Stefan
Math background - Review Series (the terms) and their summations: Geometric Arithmetic (This information is in the following slides and the class cheat sheet) Integrals From the Integrals cheat sheet see: The fundamental theorem of calculus Part II: Common integrals Cheat sheets and other useful links are on the Slides and Resources webpage.
Book Reference Book (CLRS) references for this lecture: Apendix A, especially pages 1145-1147, page 1150 (bounding the terms), Pages 1154-1156 (approximation by integrals)
Overview Summations Summation of arithmetic series: Where a1 is the first term and d is the step. Summation of geometric series: 𝑘=0 𝑛 𝑥𝑘 0< 𝑥<1 , 𝛩(1) 𝑥>1 , 𝛩( 𝑥 𝑛 ) 𝑥=1 , 𝛩(𝑛) (easy to check: 1+1+…+1) Approximation by integrals Induction You suspect/guess that a summation S = 𝛩 𝑓 𝑁 and prove/verify it using induction. See Dr. Bob Weems, “Notes 3: Summations”, section 3.D. Very useful exercise in strengthening one’s math skills.
Summations Summations are formulas of the sort: 𝑘=0 𝑛 𝑓(𝑘) Used to solve recurrences. Oftentimes, establishing upper bounds is sufficient, since we use big-Oh notation. If 𝑓 𝑘 ≥0 , then: 𝑘=0 𝒏 𝑓 𝑘 ≤ 𝑘=0 ∞ 𝑓 𝑘 Summing to infinity may give a simpler formula.
Summation of Arithmetic Series Examples: 1,5,9,13,17,21,…., ‘Step’ between terms: d = 4 First term: a1 = 1 Note that 1,2,3,…,n is a special case where the step is +1. 3,13,23,33,43,…. Step? First term (a1)? General formula: Here d is the step and a1 is the first term Summation: Summation of consecutive terms: Do not confuse the summation of terms with the count of terms! (See a future slide)
Summation of Geometric Series 0< 𝑥<1 Suppose that 𝟎< 𝒙<𝟏: Finite summations: 𝑘=0 𝑛 𝑥𝑘 = 1 − 𝑥 𝑛+1 1 − 𝑥 = 𝛩 ?? Infinite summations: 𝑘=0 ∞ 𝑥𝑘 = 1 1 − 𝑥 Important to note: 𝑘=0 𝑛 𝑥𝑘 ≤ 𝑘=0 ∞ 𝑥𝑘 = 1 1 − 𝑥 Therefore, 𝑘=0 𝑛 𝑥𝑘 =𝛩 1 . Why?
Summation of Geometric Series 0< 𝑥<1 Suppose that 𝟎< 𝒙<𝟏: Finite summations: 𝑘=0 𝑛 𝑥𝑘 = 1 − 𝑥 𝑛+1 1 − 𝑥 = 𝛩 1 Infinite summations: 𝑘=0 ∞ 𝑥𝑘 = 1 1 − 𝑥 Important to note: 𝑘=0 𝑛 𝑥𝑘 ≤ 𝑘=0 ∞ 𝑥𝑘 = 1 1 − 𝑥 Therefore, 𝑘=0 𝑛 𝑥𝑘 =𝛩 1 . Why? Because 1 1 − 𝑥 is independent of n. Strictly speaking we showed that it is O(1), but the sum is also ≠ 0 and so it is Ω(1).
Summation of Geometric Series 𝑥≥1 𝑥>1 The formula is the same, and can be rewritten as: 𝑘=0 𝑛 𝑥𝑘 = 𝑥 𝑛+1 −1 𝑥−1 Remember this formula! For example: 1 + 5 + 52 + 53 + … + 5𝑛= 5 𝑛+1 −1 5−1 =𝛩 5𝑛 5 is a constant and so: 5 𝑛+1 = 5∗5 𝑛 =𝛩 5𝑛 (Exponential!) 𝑥=1 =>
Do not confuse the summation of terms with the count of terms! Progression: 1,2,3,…n Summation of terms: 1+2+…+n = n(n+1)/2=Θ(n2) Count of terms: 1,2,3,…,n => n terms => Θ(n) Progression:1, 2, 4, …, 2i, ...2n Summation: Count of terms: n+1 Progression:1, 2, 4, …, 2i, ...2p≤n (last power of 2 less or equal to n) Count of terms: 1+lgn (more precisely: 1+floor(lgn))
Approximation by Integrals 𝑚−1 𝑛 𝑓 𝑥 𝑑𝑥 ≤ 𝑘=𝑚 𝑛 𝑓(𝑘) ≤ 𝑚 𝑛+1 𝑓 𝑥 𝑑𝑥 when f(x) is a monotonically increasing function. In most cases***, our end result will be: 𝑘=1 𝑛 𝑓(𝑘) = Θ( 0 𝑛 𝑓 𝑥 𝑑𝑥 ) when f(x) is monotonically increasing *** For the problems we look at, you can adjust the borders since the differences should result in lower order terms (see the worked-out example). But always be prepared to check the correctness.
Approximation by Integrals - Theory 𝑚−1 𝑛 𝑓 𝑥 𝑑𝑥 ≤ 𝑘=𝑚 𝑛 𝑓(𝑘) ≤ 𝑚 𝑛+1 𝑓 𝑥 𝑑𝑥 Suppose that f(x) is a monotonically increasing function: This means that 𝑥≤𝑦⇒𝑓 𝑥 ≤𝑓(𝑦). Then, we can approximate summation 𝑘=𝑚 𝑛 𝑓(𝑘) using integral 𝑚 𝑛+1 𝑓 𝑥 𝑑𝑥 . Why? Because 𝑘−1 𝑘 𝑓 𝑥 𝑑𝑥 ≤ 𝑓(𝑘) ≤ 𝑘 𝑘+1 𝑓 𝑥 𝑑𝑥 . Proof for: 𝑓(𝑘) ≤ 𝑘 𝑘+1 𝑓 𝑥 𝑑𝑥 For every 𝑥 in the interval [𝑘, 𝑘+1], 𝑥≥ 𝑘. Since 𝑓(𝑥) is increasing, if 𝑥 ≥ 𝑘 then 𝑓 𝑥 ≥ 𝑓(𝑘). (Remember that the integral is the sum of 𝑓 𝑥 on the interval [𝑘, 𝑘+1]of size 1. ) Similar proof for 𝑘−1 𝑘 𝑓 𝑥 𝑑𝑥 ≤ 𝑓(𝑘)
Approximation by Integrals - Example 𝑚−1 𝑛 𝑓 𝑥 𝑑𝑥 ≤ 𝑘=𝑚 𝑛 𝑓(𝑘) ≤ 𝑚 𝑛+1 𝑓 𝑥 𝑑𝑥 Example: approximate T(n) = 𝒌=𝟏 𝒏 𝒌𝟐 using an integral: Notice that T(n) is a sum of 𝒌𝟐 terms. We will use 𝑓(𝑥) = 𝑥2 to approximate this summation. 𝑓(𝑥) = 𝑥2 is a monotonically increasing function. O: T(n) = 𝑘=1 𝑛 𝑘2 ≤ 1 𝑛+1 𝑥2𝑑𝑥 = 𝑛+1 3 −13 3 = 𝑛3+2𝑛2+2𝑛+1 −1 3 =𝑂(𝑛3) Ω : T(n) = 𝑘=1 𝑛 𝑘2 ≥ 0 𝑛 𝑥2𝑑𝑥 = 𝑛3 −03 3 = 𝑛3 3 =Ω(𝑛3) => 𝑓 𝑛 = 𝛩(𝑛3)
Approximation by Integrals 𝑚−1 𝑛 𝑓 𝑥 𝑑𝑥 ≤ 𝑘=𝑚 𝑛 𝑓(𝑘) ≤ 𝑚 𝑛+1 𝑓 𝑥 𝑑𝑥 when f(x) is a monotonically increasing function. 𝑚 𝑛+1 𝑓 𝑥 𝑑𝑥 ≤ 𝑘=𝑚 𝑛 𝑓(𝑘) ≤ 𝑚−1 𝑛 𝑓 𝑥 𝑑𝑥 when f(x) is a monotonically decreasing function.
Worksheet 1) Find Θ for 2) Given summation: 1 + 25 + 35 + … + N5 Hint: pay attention to the borders for b). 2) Given summation: 1 + 25 + 35 + … + N5 Can you solve this in terms of Θ, Ω or O ?