CS 312: Algorithm Analysis Lecture #7: Recurrence Relations a.k.a. Difference Equations Slides by: Eric Ringger, with contributions from Mike Jones, Eric.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Analysis of Algorithms
1 Recursive Algorithm Analysis Dr. Ying Lu RAIK 283: Data Structures & Algorithms September 13, 2012.
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
CS 2210 (22C:19) Discrete Structures Advanced Counting
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Introduction to Analysis of Algorithms
Discrete Structures Chapter 6 Recurrence Relations
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Recursion.
Recursion A recursive function is a function that calls itself either directly or indirectly through another function. The problems that can be solved.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
CS 312: Algorithm Analysis Lecture #3: Algorithms for Modular Arithmetic, Modular Exponentiation This work is licensed under a Creative Commons Attribution-Share.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
CS 312: Algorithm Analysis
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
CS 3343: Analysis of Algorithms
Chap. 7 (c) , Michael P. Frank1 Chapter 7: Advanced Counting Techniques.
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
14.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo –Divide & conquer –Master’s method.
CS 312: Algorithm Analysis Lecture #8: Non-Homogeneous Recurrence Relations This work is licensed under a Creative Commons Attribution-Share Alike 3.0.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
Module #17: Recurrence Relations Rosen 5 th ed., §
RECURRENCE Sequence Recursively defined sequence
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data.
CS 312: Algorithm Analysis Lecture #32: Intro. to State-Space Search This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
CS 312: Algorithm Design & Analysis Lecture #23: Making Optimal Change with Dynamic Programming Slides by: Eric Ringger, with contributions from Mike Jones,
CS 312: Algorithm Design & Analysis Lecture #12: Average Case Analysis of Quicksort This work is licensed under a Creative Commons Attribution-Share Alike.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Recurrence.
CS 312: Algorithm Design & Analysis Lecture #24: Optimality, Gene Sequence Alignment This work is licensed under a Creative Commons Attribution-Share Alike.
CS 312: Algorithm Design & Analysis Lecture #2: Asymptotic Notation This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Recursion Algorithm : Design & Analysis [3]. In the last class… Asymptotic growth rate The Sets ,  and  Complexity Class An Example: Maximum Subsequence.
CSC310 © Tom Briggs Shippensburg University Fundamentals of the Analysis of Algorithm Efficiency Chapter 2.
Algorithm Analysis Part of slides are borrowed from UST.
CHAPTER TWO RECURRENCE RELATION
CS 312: Algorithm Analysis Lecture #8: Non-Homogeneous Recurrence Relations This work is licensed under a Creative Commons Attribution-Share Alike 3.0.
CS 312: Algorithm Analysis
CS 312: Algorithm Analysis Lecture #31: Linear Programming: the Simplex Algorithm, part 2 This work is licensed under a Creative Commons Attribution-Share.
RECURRENCE Sequence Recursively defined sequence
CS 312: Algorithm Analysis Lecture #31: Linear Programming: the Simplex Algorithm, part 2 This work is licensed under a Creative Commons Attribution-Share.
1 RECURRENCE 1. Sequence 2. Recursively defined sequence 3. Finding an explicit formula for recurrence relation.
CS 312: Algorithm Analysis Lecture #9: Recurrence Relations - Change of Variable Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer,
CS 312: Algorithm Design & Analysis Lecture #26: 0/1 Knapsack This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
CS 312: Algorithm Analysis Lecture #30: Linear Programming: Intro. to the Simplex Algorithm This work is licensed under a Creative Commons Attribution-Share.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
CS 3343: Analysis of Algorithms
Module #17: Recurrence Relations
Analysis of Algorithms
Module #17: Recurrence Relations
Fundamentals of the Analysis of Algorithm Efficiency
CS 2210 Discrete Structures Advanced Counting
Fundamentals of the Analysis of Algorithm Efficiency
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
Analysis of Algorithms
Presentation transcript:

CS 312: Algorithm Analysis Lecture #7: Recurrence Relations a.k.a. Difference Equations Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License

Announcements  HW #4 Due Now  Project #2  Early: next Wednesday  Due: Friday 2/1  Much more challenging than Project #1 – plan accordingly  Career Fair!

Objectives  Goal: Analyze Divide and Conquer recursive algorithms using recurrence relations (RRs)  Also known as Difference Equations  Working up to such RRs  Today: Focus on a special type of RRs  Homogeneous  Linear  Constant Coefficients  Leading up to a proof of the Master Theorem

Recall: Analysis Framework Given a problem,  Identify platform’s elementary operations (sometimes implicit)  Formulate solution as an algorithm  Define the measure of the input size  Measure time efficiency by counting the number of times an elementary operation is executed  Measure space efficiency by counting the number of memory units consumed by the algorithm  The efficiency of some algorithms may differ significantly for inputs of the same size.  Distinguish among worst-case, average-case, and best-case efficiencies. Choose one.  Plot efficiency vs. input size  Establish order of growth. Use asymptotic notation. n0n0 c 1 g(n) c 2 g(n) f(n) Where is the difficulty for Analyzing Recursive Functions?

Nonrecursive Algorithms Example: Element Uniqueness Problem, check whether all elements in an array are distinct. function UniqueElements(A[0…n-1]) for i=0 to n-2 for j = i+1 to n-1 if A[i]=A[j] return false return true Define input size Define elementary operation Distinguish worst-case

Recurrence Relations

Recursive Algorithms Example: Compute Factorial function N! function Factorial(N) if N=0 return 1 else return Factorial(N-1)*N Assume 32-bit integers Define input size: _____ Define elementary operations: Focus on worst-case What sequence is generated by this recurrence relation? In order to answer that question we need an initial condition! Now we can build a table of values: How long to compute C(1,000,000)? Want: C(N) in closed form for quick computation. N C(N)

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. How to solve?

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one.

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. Can you figure out an explicit (closed form) formula for this sequence? As before, build a table, recognize the pattern OR Use substitution, recognize the pattern OR Appeal to theory of recurrence relations n C(n)

Recursive Algorithms Example: Tower of Hanoi, move all disks to third peg without ever placing a larger disk on a smaller one. Can you figure out an explicit (closed form) formula for this sequence? As before, build a table, recognize the pattern OR Use substitution, recognize the pattern OR Appeal to theory of recurrence relations n C(n)

Substitution k y(k)

Recurrence Relations The most general form for our purposes:

Constant Coefficients

Example Capital growth in your savings account y(n)= $$ in account end of day n i = interest rate earned each day (at start of day) D(n) = Deposit on day n W(n) = Withdraw on day n You try it! Write a recurrence relation for y(n)

Order of Recurrence Relations What is the order of this RR?

Forcing Function

Homogeneous

What kind of RR is this? k y(k)

Terminology Review Note the alternate notations.

Terminology Review Note the alternate notations.

Existence and Uniqueness Theorem

Starting Point

Example Goal: find solution t n

Example Goal: find solution t n

General Solution

Solution?

Assignment  Read: Recurrence Relations Notes, Part II  HW #5: Part I (Section 1.2) Exercises in the RR notes.

End

Extra: Big Picture  Look at the big picture: functions as “systems”

Recurrence Relations So why should we care about recurrence relations? Generalizes the idea of a function to an operator or dynamic system A function is like a table that takes a number in and gives a number out. f xy xy x y x y

Recurrence Relations Functions can also take in a vector of numbers or yield a vector out. f x1x2y1y2y y1y1 x1x1 x2x2 y2y2 x1x1 x2x2 y3y3 x1x1 x2x2

Recurrence Relations What if the input and output vectors of a function were infinitely long? f Then x and y themselves are functions! f becomes a map from one function to another! We call maps that take functions as inputs or generate functions as outputs operators, or systems. An operator is like a rule, it’s the mathematical description of a subroutine! k x k y

Recurrence Relations S x(k) y(k) k x k y

Recurrence Relations S x(k) y(k) Unlike a simple function, an operator can have local variables that store intermediate calculations—just like a subroutine. In other words, S is a map that can have memory!

Recurrence Relations S x(k) y(k) Subroutine Description static memory: w = 0 function S (x,k) if k=0 then y  y o else y  w + x w  y return y Math Description y(0)=y o

Math Description Subroutine Description static memory: w = 0 function S (x,k) if k=0 then y  y o else y  5w + x w  y return y Recurrence Relations S x(k) y(k) y(0)=y o

Subroutine Description static memory: w 0, w 1 = 0 function S (x,k) if k=0 then y  y o else if k=1 then y  y 1 else y  a 1 w 1 + a o w 0 +x w 0  w 1 w 1  y return y Math Description Recurrence Relations S What if more than one number is stored in memory? x(k) y(k) y(0)=y o, y(1) = y 1