Iteration versus Recursion in the Fibonacci Sequence

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

The Fibonacci sequence is defined by , .

[more]

To calculate , say, you can start at the bottom with , then , and so on. This is the iterative method.

Alternatively, you can start at the top with , working down to reach and . This is the recursive method.

The graphs compare the time and space (memory) complexity of the two methods and the trees show which elements are calculated.

[less]

Contributed by: Ann Rajan (June 2016)
Special thanks to the University of Illinois NetMath Program and the mathematics department at William Fremd High School.
Open content licensed under CC BY-NC-SA


Snapshots


Details

Snapshot 1: iterative and recursive tree plots for

Snapshot 2: same for

Snapshot 3: same for

References

[1] T. Cormen et al., Introduction to Algorithms, 3rd ed., Cambridge: The MIT Press, 2009.

[2] E. Lantzman, "Iterative vs. Recursive Approaches." Code Project (blog). (Jun 14, 2016) www.codeproject.com/Articles/21194/Iterative-vs-Recursive-Approaches.



Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.
Send