recursion

recursion - Recursion Dr. David A. Gaitros...

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

View Full Document Right Arrow Icon
Recursion Dr. David A. Gaitros dgaitros@admin.fsu.edu
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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); }
Background image of page 4
Recursive Routine A recursive routine will be one that has at least one function
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online