Recursion Vs Iteration (Limitations of recursion)

There are two approaches to writing repetitive algorithms. 
      1. Loops (Iteration)
      2. Recursion.

Iteration: Use for loops, do..while, while loops.

Example: Factorial of a number

int factorial(int num)
{
      int k=num;
      while(num != 0)
      {
            k=k*(num-1);
            num--;
      }
      return num;
}

-----------------------------------------------------------------------------------------------------

Recursion: Recursion is a repetitive process in which a function calls itself.

Limitations of Recursive Approach:
      1. Recursive solutions may involve extensive overhead because they use function calls. Each function call requires push of return memory address, parameters, returned result,etc. and every function return requires that many pops. 
      2. Each time you call a function you use up some of your memory allocation may be in stack or heap. If there are large number of recursive calls – then you may run out of memory.

Example:

int factorial(int num)
{
      if(num != 0)
      {
            num=num*factorial(num-1);
      }
      return num;
}

When to Use:
For large number of iterations, use loops(iterative approach).
For small number of iterations, use recursion.