Recursion Methods

Recursion is the method which calls it self. It can be applicable where the solution of a problem is depended on the smaller instances of the same program. For example assume that we need to find the nth factorial,

  • n! = n* (n-1) * (n-2)*…………………..*3*2*1
  • Here, the
    • n! = n * (n-1)!
  • Likewise
    • (n-1)! = (n-1) * (n-2)!
    • (n-2)! = (n-2) * (n-3)!
    • (n-3)! = (n-3) * (n-4)!
    • (n-4)! = (n-4) * (n-5)!
    • (n-5)! = (n-5) * (n-6)! And so on.
  • So when we find the solution for the smaller instance it will help to find the solution for the corresponding nth

Like this there are many problems which are depended on their smaller instances. So recursion methods can be helpful in such cases

Advantages of recursion method

  1. Makes algorithms more elegant
  2. Reduces the amount of codes or procedures
  3. Can solve problems easily while the iteration method is more complex

Disadvantages of recursion method

  1. It is hard to trace the recursion idea since it is logical
  2. Always need a termination control
  3. It consumes lots of stack space, not preferable when the program size is small
  4. Need more processing time.

 

Mathanraj Sharma
University of Jaffna

 

Add Comment