DOC PREVIEW
ASU CSE 310 - L03-04

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE310 Lectures 03-04: Recurrences And the Master MethodTopics of this lectureRecurrences-General FormRecurrences-First ExampleRecurrences-Second ExampleThe Master MethodExample 1: T(n) = 8T(n/2) + n2. a=8, b=2, f(n)=n2.Example 2: T(n) = T(n/2) + 1. a=1, b=2, f(n)=1.More Examples.It Does Not Work All the TimesThe Substitution MethodSummaryReadings and [email protected] Lectures 03-04:CSE310 Lectures 03-04:Recurrences And the Master MethodRecurrences And the Master MethodGuoliang (Larry) XueDepartment of CSEArizona State Universityhttp://optimization.asu.edu/[email protected] of this lectureTopics of this lectureRecurrencesGeneral form of recurrence1st example: block matrix multiplication2nd example: searching a sorted sequenceThe Master MethodCase 1: f(n) = O(…)Case 2: f(n) = (…)Case 3: f(n) = (…), and …Examples of using the Master [email protected] FormRecurrences-General FormVery often, the time complexity of an algorithm is given by a recurrence equation. We need to solve for it. The following is the general form:T(n) = a T(n/b) + f(n), a  1 and b > 1.How do we solve such recurrence?In this lecture, we will present a very general method, known as the Master [email protected] ExampleRecurrences-First ExampleLet A be an N-by-N matrix and B be an N-by-N matrix. We can use block multiplication to get the product of A with B.Assume that we partition A into A11, A12, A21, A22. We partition B into B11, B12, B21, B22. Let C be the product of A with B. Then Cij = Ai1 B1j + Ai2 B2jTherefore the time complexity of multiplying two N-by-N matrices is T(N) such thatT(n) = 8T(n/2) + n2. a=8, b=2, f(n)[email protected] ExampleRecurrences-Second ExampleLet T(n) be the time to search a sorted array of n elements, using binary search. Then we haveT(n) = T(n/2) + 1. a=1, b=2, f(n)[email protected] Master MethodThe Master MethodIf f(n) = O(nlogba-) for some constant  > 0, thenT(n) = (nlogba) .If f(n) = (nlogba), thenT(n) = (nlogba lg n).If f(n) = (nlogba+) for some constant  > 0, and a*f(n/b)c*f(n) for some constant c < 1 and all sufficiently large n, thenT(n) = (f(n)) [email protected] 1Example 1: T(n) = 8T(n/2) + n: T(n) = 8T(n/2) + n22. a=8, b=2, f(n)=n. a=8, b=2, f(n)=n22..This is the recurrence we got from the block matrix multiplication.lg28 = 3. So we have the first case (=0.5).Using the master method, we conclude that T(n) = (n3).We can also prove this using mathematical [email protected] 2Example 2: T(n) = T(n/2) + 1: T(n) = T(n/2) + 1. a=1, b=2, f(n)=1.. a=1, b=2, f(n)=1.This is the recurrence we got from binary searching of a sorted array.lg21 = 0. So we have the second case.Using the master method, we conclude that T(n) = (lg n).We can also prove this using mathematical induction, but it is not as easy as [email protected] Examples.More Examples.Exercise 4.5-1.Exercise 4.5-2.Exercise 4.5-4.Exercise [email protected] Does Not Work All the TimesIt Does Not Work All the TimesThere are some cases where the master method does not work.Consider the straight forward method for computing the n-th Fibonacci number.T(n) = T(n-1) + T(n-2) + 1.Well, the master method is not always useful…[email protected] Substitution MethodThe Substitution MethodGuess and Prove…Example on Page 83.Example on Page 85.Pitfalls, Page 86.Exercises 4.3-1, 4.3-2, [email protected]Recurrences.The Master [email protected] and ExercisesReadings and ExercisesThe materials covered in this lecture can be found in Section 4.5. Problem 4-1.Lecture 05 will be on Insertion sort and quick-sort. To preview, read Sections 2.1 and


View Full Document

ASU CSE 310 - L03-04

Documents in this Course
Load more
Download L03-04
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view L03-04 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view L03-04 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?