Recursion vs Iteration
Comparison of recursion and iteration
Recursion
|
Iteration
|
Recursion uses a selection structure which is
based on the control structure
Recursion achieves repetition through repeated
function calls
Recursion terminates when a base case is
recognized
Recursion with a gradual approach to termination
keeps producing simpler versions of the original problem until the base case
is reached
Infinite recursion occurs if the recursion step
does not reduce the problem each time in a manner that converges on the base
case
|
Iteration uses a repetition structure which is
based on the control structure
Iteration explicitly uses a repetition structure
Iteration terminates when the loop-continuation
condition fails
Iteration with a counter-controlled repetition,
keeps modifying a counter until the counter assumes a value that makes the
loop-continuation condition fail
An infinite loop occurs with iteration if the
loop-continuation test never becomes false.
|