124k views
3 votes
Explain the benefits a recursive algorithm can provide. Use an example from a process in your organization or with which you are familiar.

User Abanmitra
by
6.8k points

1 Answer

6 votes

Step-by-step explanation:

Recursion is when the function calls itself inside it's definition.The advantages of recursion are as following:-

  1. The problems solved by recursion have small code and elegant as compared to it's iterative solution which will be big and ugly to look at.
  2. Recursion is best suitable for data structures such as trees it's solution more understandable and easy while it's iterative solution is very big and also a bit difficult.

#include<iostream>

using namespace std;

int factorial( int n1)

{

if (n1 == 0)

return 1;

return n1 * factorial(n1 - 1);

}

int main()

{

int no ;

cin>>no;

cout<<factorial(no)<<endl;

return 0;

}

Recursive function to find the factorial of a number.

User Tobias Gies
by
7.0k points