Difference between Recursion and Iteration
RECURSION
|
ITERATIONS
|
Recursive function – is a function that is partially defined by itself
|
Iterative Instructions –are loop based repetitions of a process
|
Recursion Uses selection structure
|
Iteration uses repetition structure
|
Infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on some condition.(base case)
|
An infinite loop occurs with iteration if the loop-condition test never becomes false
|
Recursion terminates when a base case is recognized
|
Iteration terminates when the loop-condition fails
|
Recursion is usually slower then iteration due to overhead of maintaining stack
|
Iteration does not use stack so it's faster than recursion
|
Recursion uses more memory than iteration
|
Iteration consume less memory
|
Infinite recursion can crash the system
|
infinite looping uses CPU
cycles repeatedly
|
Recursion makes code smaller
|
Iteration makes code longer
|
Comments
Post a Comment