This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Recursively Defined Objects Many functions are defined in terms of themselves. These functions are recursively defined. For those of you who have taken CS 1, these functions will look very similar to recursive functions in a programming language. In particular, writing a function to compute the examples I will show you in this lecture should be fairly easy. You all have already seen a very common example of a recursively defined function, factorial, which is defined as follows: 0! = 1 n! = n (n 1)!, for n > 0. So, we can compute any factorial value by repeatedly using the definition: 1! = 1 (1 1)! = 1 0! = 1 1 = 1. 2! = 2 (2 1)! = 2 1! = 2 1 = 2 3! = 3 (3 1)! = 3 2! = 6, etc. More generally, a recursively defined function f ( n ) for n 0 consists of the initial value f (0), and a recurrence relation which relates the value of f ( n ) in terms of the preceding value f ( n 1) for n 1. Minor variations of this recursive definition include a starting value different than 0, several starting values and a recurrence relating the function value to several of the preceding values, such as the Fibonacci number sequence which we will see later in the lecture. When a function is defined by a recurrence, the most natural way to prove the properties about the function is by using induction....
View Full Document
- Spring '09