What is Recursion in Python?

Recursion VS Iteration


A program is called Recursive when an entity calls iteself and A program is called Iterative , the programs contains Loops...While dicussing recursion,a basic question comes in the mind that which is better ? -Recursion or Iteration.The answer to this question depends upon what we are trying to do...Below I have listed some properties of Recursion and Iteration.

Recursion


  • A Recursive call terminates when the base case is reached.
  • A Recursive Program requires extra memory that an Iterative Program.
  • Some Problems like finding the factorial of a number can be easily solved by using Recursion.
  • Recursion has Smaller Sizes of Code i.e. less lines of code.
  • In Recursion,the time complexity is very high.

Iteration


  • An Iteration stops when the specified condition is proven to be false.
  • It does not require any extra space like in Recursion.
  • Some problems are not obvious as of a Recursive Solution.
  • Size of Code is larger in comparison to Recursion.
  • Time Complexity is relatively lower.

From the above points you can understand the differences between Recursion and Iteration.

No comments: