Lecture 10 -Recursive Definition

# Lecture 10 -Recursive Definition - Recursive...

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

Recursive Definitions (Computer Science Notes) Recursive Definitions Recursive function definitions in mathematics are basically similar to recursive procedures in programming languages. A recursive definition defines an object in terms of smaller objects of the same type. Because this process has to end at some point, we need to include explicit definitions for the smallest objects. So a recursive definition always has two parts: Base case or cases Recursive Formula For the summation E from i = 1to n (i) can be defined as Base Case g(1) = 1 Recursive Formula g(n) =g(n-1) + n for all n>=2 Both the base case and the recursive formula must be present to have a complete definition. However, it is traditional not to explicitly label these two pieces. You’re just expected to figure out for yourself which parts are base case(s) and which is the recursive formula. The input values are normally assumed to be integers The true power of recursive definition is revealed when the result for n depends on the results for more than one smaller value, as in the strong induction examples Finding Closed Forms Many recursive numerical formulas have a closed form, i.e. an equivalent expression that doesn’t involve recursion (or summation or the like) Sometimes you can find the closed form by working out the first few values of the function and then guessing the pattern. More often, you need to use an organized technique. The simplest technique for finding closed forms is called “unrolling.” The idea behind unrolling is to substitute a recursive definition into itself, so as to re-

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 / 4

Lecture 10 -Recursive Definition - Recursive...

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

View Full Document
Ask a homework question - tutors are online