99-recurrences

# 99-recurrences - Algorithms Appendix Solving Recurrences O...

This preview shows pages 1–2. Sign up to view the full content.

Algorithms Appendix: Solving Recurrences “...O Zarathustra, who you are and must become” behold you are the teacher of the eternal recurrence – that is your destiny! That you as the ﬁrst must teach this doctrine – how could this great destiny not be your greatest danger and sickness too? — Friedrich Nietzsche, Also sprach Zarathustra (1885) [translated by Walter Kaufmann] Solving Recurrences 1 Introduction A recurrence is a recursive description of a function, usually of the form F : IN IR, or a description of such a function in terms of itself. Like all recursive structures, a recurrence consists of one or more base cases and one or more recursive cases . Each of these cases is an equation or inequality, with some function value f ( n ) on the left side. The base cases give explicit values for a (typically ﬁnite, typically small) subset of the possible values of n . The recursive cases relate the function value f ( n ) to function value f ( k ) for one or more integers k < n ; typically, each recursive case applies to an inﬁnite number of possible values of n . For example, the following recurrence (written in two different but standard ways) describes the identity function f ( n ) = n : f ( n ) = ( 0 if n = 0 f ( n - 1 )+ 1 otherwise f ( 0 ) = 0 f ( n ) = f ( n - 1 1 for all n > 0 In both presentations, the ﬁrst line is the only base case, and the second line is the only recursive case. The same function can satisfy many different recurrences; for example, both of the following recurrences also describe the identity function: f ( n ) = 0 if n = 0 1 if n = 1 f ( b n / 2 c f ( d n / 2 e ) otherwise f ( n ) = 0 if n = 0 2 · f ( n / 2 ) if n is even and n > 0 f ( n - 1 1 if n is odd We say that a particular function satisﬁes a recurrence, or is the solution to a recurrence, if each of the statements in the recurrence is true. Most recurrences—at least, those that we will encounter in this class—have a solution; moreover, if every case of the recurrence is an equation, that solution is unique. Speciﬁcally, if we transform the recursive formula into a recursive algorithm , the solution to the recurrence is the function computed by that algorithm! Recurrences arise naturally in the analysis of algorithms, especially recursive algorithms. In many cases, we can express the running time of an algorithm as a recurrence, where the recursive cases of the recurrence correspond exactly to the recursive cases of the algorithm. Recurrences are also useful tools for solving counting problems—How many objects of a particular kind exist? By itself, a recurrence is not a satisfying description of the running time of an algorithm or a bound on the number of widgets. Instead, we need a closed-form solution to the recurrence; this is a non-recursive description of a function that satisﬁes the recurrence. For recurrence equations , we sometimes prefer an exact closed-form solution, but such a solution may not exist, or may be too complex to be useful.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

99-recurrences - Algorithms Appendix Solving Recurrences O...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online