Ch
t
3 R
i
Chapter 3: Recursion
This material is based on contents the book: “Data structures, Algorithms, and
Software Principles in C”, from T.A. Standish. Parts also under permission from
David McCaughan, University of Guelph, Canada.
USF – COP4530 – Data Structures
Summer 2009
1 of 21

This ** preview** has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
Fibonacci numbers
•
Is the following sequence of numbers
–
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, …
•
First two Fibonacci numbers:
–
0, 1. Each other number is the sum of the previous two
•
How can the recursive function be defined?
–
First, the mathematical definition eases thinking
n
if (n <= 1)
Fibonacci(n) =
Fibonacci (n-1) + Fibonacci(n-2)
otherwise
n
USF – COP4530 – Data Structures
Summer 2009
2 of 21