Handout 10

Handout 10 - Mehran Sahami CS103B Handout #10 January 23,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Mehran Sahami Handout #10 CS103B January 23, 2009 Analysis of Algorithms: The Recursive Case We again thank Maggie Johnson for portions of this handout. Up until now, we have been analyzing non-recursive algorithms, looking at how big-Oh notation may be used to characterize the growth rate of running times for various algorithms. Such algorithm analysis becomes a bit more complicated when we turn our attention to analyzing recursive algorithms. As a result, we augment the analytic tools in our repertoire to help us perform such analyses. One such tool is an understanding of recurrence relations, which we discuss presently. Recurrence Relations Recall that a recursive or inductive definition has the following parts: 1. Base Case : the initial condition or basis which defines the first (or first few) elements of the sequence 2. Inductive (Recursive) Case : an inductive step in which later terms in the sequence are defined in terms of earlier terms. The inductive step in a recursive definition can be expressed as a recurrence relation , noting how earlier terms in a sequence relate to late terms. We more formally define this notion below. A recurrence relation for a sequence a 1 , a 2 , a 3 , . .. is a formula that relates each term a k to certain of its predecessors a k-1 , a k-2 , . .., a k-i , where i is a fixed integer and k is any integer greater than or equal to i . The initial conditions for such a recurrence relation specify the values of a 1 , a 2 , a 3 , . .., a i-1 . A recursive definition is one way of defining a sequence in mathematics (other ways to define sequences include enumerating the sequence or coming up with a formula to express the sequence). Suppose you have an enumerated sequence that satisfies a given recursive definition (or recurrence relation). It is frequently very useful to have the formula for the elements of this sequence in addition to the recurrence relation, especially if you need to determine a very large member of the sequence. Such an explicit formula is called a solution to the recurrence relation. If a member of the sequence can be calculated using a fixed number of elementary operations, we say it is a closed form formula . Solving recurrence relations is the key to analyzing recursive subprograms. Example 1 A single pair of rabbits (one male and one female, of course) is born at the end of January 2009. Assume the following interesting conditions: 1. Rabbit pairs give birth to one new male/female pair at the end of every month after the month in which they are born. 2. No deaths ever occur (not even from exhaustion. ..)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Problem : Find a recurrence relation that can be used to tell us how many rabbits we will have at the end of one year (i.e., the end of January 2010). Solution
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/26/2009 for the course CS 103B taught by Professor Sahami,m during the Winter '08 term at Stanford.

Page1 / 17

Handout 10 - Mehran Sahami CS103B Handout #10 January 23,...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online