Today s Outline. CS 362, Lecture 4. Annihilator Method. Lookup Table. Annihilators for recurrences with non-homogeneous terms Transformations

Similar documents
Intro to Annihilators. CS 362, Lecture 3. Today s Outline. Annihilator Operators

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

CS 361, Lecture 14. Outline

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

Today s Outline. CS 362, Lecture 13. Matrix Chain Multiplication. Paranthesizing Matrices. Matrix Multiplication. Jared Saia University of New Mexico

data structures and algorithms lecture 2

University of New Mexico Department of Computer Science. Midterm Examination. CS 361 Data Structures and Algorithms Spring, 2003

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline

University of New Mexico Department of Computer Science. Final Examination. CS 362 Data Structures and Algorithms Spring, 2007

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Mergesort and Recurrences (CLRS 2.3, 4.4)

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

CS383, Algorithms Spring 2009 HW1 Solutions

Lecture 6 September 21, 2016

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

Today s Outline. CS 561, Lecture 15. Greedy Algorithms. Activity Selection. Greedy Algorithm Intro Activity Selection Knapsack

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Notes for Recitation 14

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2

Lecture 3. Big-O notation, more recurrences!!

CS173 Lecture B, November 3, 2015

Selection and Adversary Arguments. COMP 215 Lecture 19

Data selection. Lower complexity bound for sorting

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

CSC236 Week 3. Larry Zhang

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

Classes of Problems. CS 461, Lecture 23. NP-Hard. Today s Outline. We can characterize many problems into three classes:

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Lecture 7: Dynamic Programming I: Optimal BSTs

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

CS 561, Lecture: Greedy Algorithms. Jared Saia University of New Mexico

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

Recurrences COMP 215

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Analysis of Algorithms - Using Asymptotic Bounds -

Chapter 5 Divide and Conquer

Lecture 2 September 4, 2014

Ch 5.7: Series Solutions Near a Regular Singular Point, Part II

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

Pre-lecture R: Solving Recurrences

Divide-and-Conquer Algorithms Part Two

Dictionary: an abstract data type

Divide-and-conquer: Order Statistics. Curs: Fall 2017

CS 2110: INDUCTION DISCUSSION TOPICS

Fundamental Algorithms

Partition and Select

Multidimensional Divide and Conquer 1 Skylines

Lecture 10: The Normal Distribution. So far all the random variables have been discrete.

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

CS Data Structures and Algorithm Analysis

COMP 382: Reasoning about algorithms

Dot Products, Transposes, and Orthogonal Projections

CS 4349 Lecture August 30th, 2017

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Notes on Recurrence Relations

Approximation, Taylor Polynomials, and Derivatives

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

CS 4407 Algorithms Lecture 2: Growth Functions

4.4 Recurrences and Big-O

Design and Analysis of Algorithms

Hon.Algorithms (CSCI-GA 3520), Professor Yap Fall 2012 MIDTERM EXAM. Oct 11, 2012 SOLUTION

CS483 Design and Analysis of Algorithms

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Recursion. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Fall 2007

Outline. Computer Science 331. Cost of Binary Search Tree Operations. Bounds on Height: Worst- and Average-Case

Divide and Conquer Problem Solving Method

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Math Lecture 18 Notes

University of New Mexico Department of Computer Science. Final Examination. CS 561 Data Structures and Algorithms Fall, 2006

Lecture 3: Big-O and Big-Θ

Midterm 1 for CS 170

Recurrence Relations

A SUMMARY OF RECURSION SOLVING TECHNIQUES

Algorithms And Programming I. Lecture 5 Quicksort

Writing proofs for MATH 51H Section 2: Set theory, proofs of existential statements, proofs of uniqueness statements, proof by cases

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

Asymptotic Analysis and Recurrences

Appendix: Solving Recurrences

CSCI 3110 Assignment 6 Solutions

Data Structures and Algorithms CSE 465

Disjoint-Set Forests

CS 161 Summer 2009 Homework #2 Sample Solutions

Dictionary: an abstract data type

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

University of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers. Lecture 5

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

CS 151. Red Black Trees & Structural Induction. Thursday, November 1, 12

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Today s Outline. CS 362, Lecture 23. Classes of Problems. NP-Hard. Review NP-Hardness and three more reductions. Jared Saia University of New Mexico

Transcription:

Today s Outline CS 362, Lecture 4 Jared Saia University of New Mexico Annihilators for recurrences with non-homogeneous terms Transformations 1 Annihilator Method Lookup Table Write down the annihilator for the recurrence Factor the annihilator Look up the factored annihilator in the Lookup Table to get general solution Solve for constants of the general solution by using initial conditions (L a 0 ) b 0(L a 1 ) b 1... (L a k ) b k annihilates only sequences of the form: p 1 (n)a n 0 + p 2(n)a n 1 +... p k(n)a n k where p i (n) is a polynomial of degree b i 1 (and a i a j, when i j) 2 3

Examples Example Consider the recurrence T (n) = 7T (n 1) 16T (n 2)+12T (n 3), T (0) = 1, T (1) = 5, T (2) = 17 Q: What does (L 3)(L 2)(L 1) annihilate? A: c 0 1 n + c 1 2 n + c 2 3 n Q: What does (L 3) 2 (L 2)(L 1) annihilate? A: c 0 1 n + c 1 2 n + (c 2 n + c 3 )3 n Q: What does (L 1) 4 annihilate? A: (c 0 n 3 + c 1 n 2 + c 2 n + c 3 )1 n Q: What does (L 1) 3 (L 2) 2 annihilate? A: (c 0 n 2 + c 1 n + c 2 )1 n + (c 3 n + c 4 )2 n Write down the annihilator: From the definition of the sequence, we can see that L 3 T 7L 2 T + 16LT 12T = 0, so the annihilator is L 3 7L 2 + 16L 12 Factor the annihilator: We can factor by hand or using a computer program to get L 3 7L 2 +16L 12 = (L 2) 2 (L 3) Look up to get general solution: The annihilator (L 2) 2 (L 3) annihilates sequences of the form (c 0 n + c 1 )2 n + c 2 3 n Solve for constants: T (0) = 1 = c 1 + c 2, T (1) = 5 = 2c 0 + 2c 1 + 3c 2, T (2) = 17 = 8c 0 + 4c 1 + 9c 2. We ve got three equations and three unknowns. Solving by hand, we get that c 0 = 1,c 1 = 0,c 2 = 1. Thus: T (n) = n2 n + 3 n 4 5 Example (II) At Home Exercise Consider the recurrence T (n) = 2T (n 1) T (n 2), T (0) = 0, T (1) = 1 Write down the annihilator: From the definition of the sequence, we can see that L 2 T 2LT +T = 0, so the annihilator is L 2 2L + 1 Factor the annihilator: We can factor by hand or using the quadratic formula to get L 2 2L + 1 = (L 1) 2 Look up to get general solution: The annihilator (L 1) 2 annihilates sequences of the form (c 0 n + c 1 )1 n Solve for constants: T (0) = 0 = c 1, T (1) = 1 = c 0 + c 1, We ve got two equations and two unknowns. Solving by hand, we get that c 0 = 0,c 1 = 1. Thus: T (n) = n Consider the recurrence T (n) = 6T (n 1) 9T (n 2), T (0) = 1, T (1) = 6 Q1: What is the annihilator of this sequence? Q2: What is the factored version of the annihilator? Q3: What is the general solution for the recurrence? Q4: What are the constants in this general solution? (Note: You can check that your general solution works for T (2)) 6 7

Non-homogeneous terms Example Consider a recurrence of the form T (n) = T (n 1) + T (n 2) + k where k is some constant The terms in the equation involving T (i.e. T (n 1) and T (n 2)) are called the homogeneous terms The other terms (i.e.k) are called the non-homogeneous terms In a height-balanced tree, the height of two subtrees of any node differ by at most one Let T (n) be the smallest number of nodes needed to obtain a height balanced binary tree of height n Q: What is a recurrence for T (n)? A: Divide this into smaller subproblems To get a height-balanced tree of height n with the smallest number of nodes, need one subtree of height n 1, and one of height n 2, plus a root node Thus T (n) = T (n 1) + T (n 2) + 1 8 9 Example Example Let s solve this recurrence: T (n) = T (n 1) + T (n 2) + 1 (Let T n = T (n), and T = T n ) We know that (L 2 L 1) annihilates the homogeneous terms Let s apply it to the entire equation: (L 2 L 1) T n = L 2 T n L T n 1 T n = T n+2 T n+1 T n = T n+2 T n+1 T n = 1, 1, 1, This is close to what we want but we still need to annihilate 1, 1, 1, It s easy to see that L 1 annihilates 1, 1, 1, Thus (L 2 L 1)(L 1) annihilates T (n) = T (n 1) + T (n 2) + 1 When we factor, we get (L φ)(l ˆφ)(L 1), where φ = 1+ 5 2 and ˆφ = 1 5 2. 10 11

Lookup General Rule Looking up (L φ)(l ˆφ)(L 1) in the table We get T (n) = c 1 φ n + c 2ˆφ n + c 3 1 n If we plug in the appropriate initial conditions, we can solve for these three constants We ll need to get equations for T (2) in addition to T (0) and T (1) To find the annihilator for recurrences with non-homogeneous terms, do the following: Find the annihilator a 1 for the homogeneous part Find the annihilator a 2 for the non-homogeneous part The annihilator for the whole recurrence is then a 1 a 2 12 13 Consider T (n) = T (n 1) + T (n 2) + 2. The residue is 2, 2, 2, and The annihilator is still (L 2 L 1)(L 1), but the equation for T (2) changes! Consider T (n) = T (n 1) + T (n 2) + 2 n. The residue is 1, 2, 4, 8, and The annihilator is now (L 2 L 1)(L 2). 14 15

Consider T (n) = T (n 1) + T (n 2) + n. The residue is 1, 2, 3, 4, The annihilator is now (L 2 L 1)(L 1) 2. Consider T (n) = T (n 1) + T (n 2) + n 2. The residue is 1, 4, 9, 16, and The annihilator is (L 2 L 1)(L 1) 3. 16 17 In Class Exercise Consider T (n) = T (n 1) + T (n 2) + n 2 2 n. The residue is 1 1, 4 4, 9 8, 16 16, and the The annihilator is (L 2 L 1)(L 1) 3 (L 2). Consider T (n) = 3 T (n 1) + 3 n Q1: What is the homogeneous part, and what annihilates it? Q2: What is the non-homogeneous part, and what annihilates it? Q3: What is the annihilator of T (n), and what is the general form of the recurrence? 18 19

Limitations Transformations Idea Our method does not work on T (n) = T (n 1)+ n 1 or T (n) = T (n 1) + lg n The problem is that n 1 and lg n do not have annihilators. Our tool, as it stands, is limited. Key idea for strengthening it is transformations Consider the recurrence giving the run time of mergesort T (n) = 2T (n/2) + kn (for some constant k), T (1) = 1 How do we solve this? We have no technique for annihilating terms like T (n/2) However, we can transform the recurrence into one with which we can work 20 21 Transformation Now Solve Let n = 2 i and rewrite T (n): T (2 0 ) = 1 and T (2 i ) = 2T ( 2i 2 ) + k2i = 2T (2 i 1 ) + k2 i Now define a new sequence t as follows: t(i) = T (2 i ) Then t(0) = 1, t(i) = 2t(i 1) + k2 i We ve got a new recurrence: t(0) = 1, t(i) = 2t(i 1) + k2 i We can easily find the annihilator for this recurrence (L 2) annihilates the homogeneous part, (L 2) annihilates the non-homogeneous part, So (L 2)(L 2) annihilates t(i) Thus t(i) = (c 1 i + c 2 )2 i 22 23

Reverse Transformation Success! We ve got a solution for t(i) and we want to transform this into a solution for T (n) Recall that t(i) = T (2 i ) and 2 i = n t(i) = (c 1 i + c 2 )2 i (1) T (2 i ) = (c 1 i + c 2 )2 i (2) T (n) = (c 1 lg n + c 2 )n (3) = c 1 n lg n + c 2 n (4) = Θ(n lg n) (5) Let s recap what just happened: We could not find the annihilator of T (n) so: We did a transformation to a recurrence we could solve, t(i) (we let n = 2 i and t(i) = T (2 i )) We found the annihilator for t(i), and solved the recurrence for t(i) We reverse transformed the solution for t(i) back to a solution for T (n) 24 25 Now Solve Consider the recurrence T (n) = 9T ( n 3 ) + kn, where T (1) = 1 and k is some constant Let n = 3 i and rewrite T (n): T (2 0 ) = 1 and T (3 i ) = 9T (3 i 1 ) + k3 i Now define a sequence t as follows t(i) = T (3 i ) Then t(0) = 1, t(i) = 9t(i 1) + k3 i t(0) = 1, t(i) = 9t(i 1) + k3 i This is annihilated by (L 9)(L 3) So t(i) is of the form t(i) = c 1 9 i + c 2 3 i 26 27

Reverse Transformation In Class Exercise t(i) = c 1 9 i + c 2 3 i Recall: t(i) = T (3 i ) and 3 i = n t(i) = c 1 9 i + c 2 3 i T (3 i ) = c 1 9 i + c 2 3 i T (n) = c 1 (3 i ) 2 + c 2 3 i = c 1 n 2 + c 2 n = Θ(n 2 ) Consider the recurrence T (n) = 2T (n/4) + kn, where T (1) = 1, and k is some constant Q1: What is the transformed recurrence t(i)? How do we rewrite n and T (n) to get this sequence? Q2: What is the annihilator of t(i)? What is the solution for the recurrence t(i)? Q3: What is the solution for T (n)? (i.e. do the reverse transformation) 28 29 A Final Example A Final Example Not always obvious what sort of transformation to do: Consider T (n) = 2T ( n) + log n Let n = 2 i and rewrite T (n): T (2 i ) = 2T (2 i/2 ) + i Define t(i) = T (2 i ): t(i) = 2t(i/2) + i This final recurrence is something we know how to solve! t(i) = O(i log i) The reverse transform gives: t(i) = O(i log i) (6) T (2 i ) = O(i log i) (7) T (n) = O(log n log log n) (8) 30 31

Todo HW 1 Start Chapter 15 in text 32