UMBC
CMSC 201
Fall '06
CSEE
|
201
|
201 F'06
|
lectures
|
news
|
help
Search Notes:
Recursion vs. Iteration
Both recursion and iteration are important
All modern programming languages support them
Most compilers can compile recursive functions into efficient code
Some problems are easy using one and difficult using the other
Use recursion when
A recursive algorithm is obvious
Optimal speed is not an issue
The data being processed is recursive (e.g., a hierarchical directory structure)
Clarity and simplicity of code is important
Use iteration when
The problem is a natural fit for iteration (e.g., processing a 2D image)
Efficiency is critical
Some recursive patterns are more efficient than others
There are many recursive patterns.
Some recursion, such as tail recursion, can be compiled into iteration.
Other patterns, such as the doubly recursive fibonacci program, are inherently inefficient ways to do a computation.
CSEE
|
201
|
201 F'06
|
lectures
|
news
|
help
Last Modified - Tuesday, 22-Aug-2006 07:14:19 EDT