# Recursion - Recursion A recursive definition is one in...

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

A recursive definition is one in which the item being defined is part of the definition. For example, there is a suite of tools for Unix and Linux named gnu. The definition of gnu is gnu's not unix. As you can see, the word gnu is also part of the definition. However, this definition is not well formed, since this leads to infinite recursion. There is no rule that stops the recursion. A mathmatical definition that is recursive is the definition of the Fibonacci Numbers. This is defined as: f(n)=f(n-2) + f(n-1). where f(1)=1 and f(0)=0 This is well formed, since sooner or later you will get to the stopping conditions of n=1 or n=0. A trivial example that you might be more familiar with is the sum of the first n numbers. You might know that the sum of the first n numbers is (n 2 +n)/2. Another way to solve the sum of the first n numbers is with a loop. sum=0; for(i=0; i< n;i++) { sum+=i; } Another approach that will lead to the correct answer is to realize that the sum of the first n numbers is n + sum(n-1) where sum(1)=1; This is the recursive definition for summing n integers. Implementing the recursive definition of the sum of the

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

Recursion - Recursion A recursive definition is one in...

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

View Full Document
Ask a homework question - tutors are online