Recurrences. What is a Recurrence Relation? A system of equations giving the value of a function from numbers to numbers in terms of the value of the.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Chapter 6 Advanced Counting 6.1 Recurrence Relations.
A simple example finding the maximum of a set S of n numbers.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
11 Computer Algorithms Lecture 6 Recurrence Ch. 4 (till Master Theorem) Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
CS 2210 (22C:19) Discrete Structures Advanced Counting
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Prof. Dan Barrish-Flood Algorithms (su04)
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Recursion.
Analysis of Recursive Algorithms
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions BIL741: Advanced.
1 Divide and Conquer Binary Search Mergesort Recurrence Relations CSE Lecture 4 – Algorithms II.
Arithmetic.
Analysis of Recursive Algorithms October 29, 2014
Analyzing Recursive Algorithms A recursive algorithm can often be described by a recurrence equation that describes the overall runtime on a problem of.
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
Project 2 due … Project 2 due … Project 2 Project 2.
4.4 Recursive Algorithms A recursive algorithm is one which calls itself to solve “smaller” versions of an input problem. How it works: – The current status.
Module #17: Recurrence Relations Rosen 5 th ed., §
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
Recursion Recursion Chapter 12. Outline n What is recursion n Recursive algorithms with simple variables n Recursion and the run-time stack n Recursion.
Divide & Conquer  Themes  Reasoning about code (correctness and cost)  recursion, induction, and recurrence relations  Divide and Conquer  Examples.
Informal Analysis of Merge Sort  suppose the running time (the number of operations) of merge sort is a function of the number of elements to sort  let.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Data Structures & Algorithms Recursion and Trees Richard Newman.
CompSci 102 Discrete Math for Computer Science April 17, 2012 Prof. Rodger.
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Introduction to Algorithms Chapter 4: Recurrences.
COMP 170 L2 L11: Recursion, Recurrence, and Induction l Objective n Recursion  A problem solving technique that reduces big problems into smaller ones.
Recurrences (in color) It continues…. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. When an algorithm.
A Introduction to Computing II Lecture 7: Sorting 1 Fall Session 2000.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Analysis of Algorithms CS 477/677
COMP108 Algorithmic Foundations Divide and Conquer
COMP108 Algorithmic Foundations Divide and Conquer
Divide-and-Conquer 6/30/2018 9:16 AM
Recursion &Faster Sorting
Divide and Conquer.
Module #17: Recurrence Relations
Intro to Recursion.
CS 3343: Analysis of Algorithms
Data Structures & Algorithms
Mergesort Based on divide-and-conquer strategy
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Ch 4: Recurrences Ming-Te Chi
Module #17: Recurrence Relations
CS 2210 Discrete Structures Advanced Counting
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
Algorithms Recurrences.
Divide-and-conquer approach
Presentation transcript:

Recurrences

What is a Recurrence Relation? A system of equations giving the value of a function from numbers to numbers in terms of the value of the same function for smaller arguments Eg Fibonacci: –F 0 = 0, F 1 = 1, and for n>1, –F n = F n-1 +F n-2

A note on Fibonacci Incredibly, the Fibonacci numbers can be expressed as The second term is o(1) so the Fibonacci numbers grow exponentially

Towers of Hanoi Move all disks from peg 1 to peg 3 Move one disk at a time Never put a larger disk on a smaller disk

Recursive Solution How many moves H n to transfer all n disks? n = 1 => H 1 = 1 H n+1 = 2H n +1

Conjecture and Prove H 1 = 1 H 2 = 2H 1 +1 = 3 H 3 = 2H 2 +1 = 7 H 4 = 2H 3 +1 = 15 Conjecture: H n = 2 n -1 Works for n=1, 2, 3, 4 H n+1 = 2H n +1 = 2∙(2 n -1) + 1 = 2 n+1 -1 (by recurrence equation; by induction hypothesis; by simplifying algebraically)

Divide and conquer Determine whether an item x is in a sorted list L by binary search For convenience assume list L has 2 n elements for some n Algorithm: –If L is of length 1, check to see if the unique element is x and return T or F accordingly. –If L is of length 2 n+1 where n ≥ 0, compare x to L[2 n ]. –If x≤L[2 n ] then search for x in L[1..2 n ]. –If x>L[2 n ] then search for x in L[2 n n+1 ].

Analysis Let D n = # of comparison steps to find an element in a list of length n (which is a power of 2) D 1 = 1 D 2n = 1+D n D 2 = 2 D 4 = 3 D 8 = 4

Analysis Proof: n=1 (k=0) ✓ Assume D n = 1 + lg n D 2n = 1 + D n = 2 + lg n = 1 + lg(2n) ✓

Merge Sort Sort a list L of length n = 2 k as follows: If n = 1 the list is sorted If n = 2 k+1 and k≥0 then –Split the list into L[1..2 k ] and L[2 k k+1 ] –Sort each sublist by the same algorithm –Merge the sorted lists together T(1) = 1 T(2n) = 2T(n) + cn

Merge Sort Analysis T(1) = 1 T(2n) = 2T(n) + cn T(2) = 2+c T(4) = 2(2+c) + 2c = 4 + 4c T(8) = 2(4+4c) + 4c = c T(16) = 2(8+12c) + 8c = c T(32) = 2(16+32c) + 16c = c ? T(n) = n + c(n/2)lg n

Prove the Conjecture ? T(n) = n + c(n/2)lg n T(1) = 1 = 1 + c(1/2)lg 1 = = 1 ✓ T(2n) = 2T(n) + cn = 2(n+c(n/2)lg n) + cn = 2n + cnlg n + cn = 2n + cn(lg n + 1) = 2n + c(2n/2) lg (2n) ✓

FINIS