recursion

# recursion - Recursion Dr David A Gaitros...

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

Recursion Dr. David A. Gaitros [email protected]

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

View Full Document
Recursion This is the song that never ends, Yes it goes on and on my friend. Some people started singing it, not knowing what it was, And they'll continue singing it forever just because -> Written and composed by Norman Martin
Recursion A program or function that has the ability to call itself is said to be recursive. Mathematically, recursion is very interesting and has been around for quite some time. Take the Fibonacci numbers. A Fibonacci number is the sum of the two previous numbers f n = f n-1 + f n-2 Recursion is very useful in traversing tree structures

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

View Full Document
Simple Example #include <iostream> using namespace std; int SubtractOnetoZero int main(void) { int x=10; cout << “final number is “ << << SubtractOnetoZero(x) << endl; return 0; } int SubtractOnetoZero(int x) { if(x==1) return 0; else return SubtractOnetoZero(x-1); }
Recursive Routine A recursive routine will be one that has at least one function

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

recursion - Recursion Dr David A Gaitros...

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

View Full Document
Ask a homework question - tutors are online