Tuesday 9 April 2013

Recursion V\S Iteration

Recursion V\S Iteration

1) Recursive function – is a function that is partially defined by itself whereas Iterative functions are loop based imperative repetitions of a process

2) Recursion Uses selection structure whereas Iteration uses repitation structure

3) An infinite loop occurs with iteration if the loop-continuation test never becomes false whereas infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on the base case.

4) Iteration terminates when the loop-continuation condition fails whereas recursion terminates when a base case is recognized

5) When using recursion multiple activation records are created on stack for each call when in iteration everything is done in one activation record

6) Recursion is usually slower then iteration due to overhead of maintaining stack whereas iteration does not use stack so it's faster than recursion

7) Recursion uses more memory than iteration
8) Infinite recursion can crash the system whereas infinite looping uses cpu cycles repeatedly

9) Recursion makes code smaller and iteration makes code longer.




Blog Author: Vijay Kumar

No comments:

Post a Comment