Recursive Function is the type of function which calls itself.It is a looping technique. This forms a loop where every time the function is called. It can call the function itself again and again. The function which can call itself again and again is called recursion. This kind of function requires a stopping condition so that they can stop looping continuously.

The function() calls itself within the original function() on each of the smaller components. It is used for elegant and straight forward coding. The recursion make the coder look shorter and cleaner.

## Characteristics

- It is a type of function which call itself.
- Its speed is slow.
- It must have a termination condition or stopping condition and recursive expression.

## Advantage

- Recursion makes the code cleaner.
- It shorten the complex and nested codes.

## Disadvantage

- It is hard to understand the logic behind the recursion function
- It is tough to debug recursion function.

## Application

- It is used in dynamic programming language.
- It is also used in divided and conquer algorithm.
- We can divide the problem into sub-problem or that makes it easier to solve. Recursion has a similar process, which is why it is used to implement such algorithms.The solution is then built back up piece by piece.

## Example

```
recursion_function<-function(x)
{
if(x==0 || x==1)
{
return(1)
}
else
{
return(x*recursion_function(x-1))
}
}
recursion_function(6)
```

**Output:** [1] 720

- Log in to post comments