# Recursive Function

**Recursive Function** is a function which repeats or uses its own previous term to calculate subsequent terms and thus forms a sequence of terms.

Usually, we learn about this function based on the arithmetic-geometric sequence, which has terms with a common difference between them. This function is highly used in computer programming languages, such as, C, Java, Python, PHP.

The most common example we can take is the set of natural numbers, which start from one goes till infinity, i.e. **1,2,3,4,5,6,7, …., ∞** .

Therefore, in the sequence of natural number, each term has a common difference between them as 1, which means each time the next term calls its previous term to get executed.

## Recursion Meaning

When a recursive procedure gets repeated, it is called** recursion**. A recursive is a type of function or expression stating some concept or property of one or more variables, which is specified by a procedure that yields values or instances of that function by repeatedly applying a given relation or routine operation to known values of the function.

**Or **

A function which calls itself from its previous value to generate subsequent value.

**Or**

A function that calls itself during its execution.

You can understand the concept of recursion by taking a real life example. Suppose you are taking a staircase to reach from ground floor to the first floor. So you take steps one by one here. You can reach the second step only when you have stepped first. Again to reach the third step, you have to take the second step first. This is the process of repetition. With each next step, you are adding previous steps as a repeated sequence with a common difference between each step. This is the meaning of recursive.

Step 2 = Step 1 + ground floor

Step 3 = Step 2 + step 1 + ground floor

And so on.

### Recursive Function Formula

If a_{1},a_{2},a_{3},a_{4},…..,a_{n},… is a set of series or a sequence. Then a **recursive formula** for this sequence will require to compute all the previous terms and find the value of a_{n}.

i.e. **a _{n}=a_{n-1}+a_{1}**

This formula can also be defined as Arithmetic Sequence Recursive Formula. As you can see from the sequence itself, it is an **Arithmetic sequence**, which consists of the first term followed by other terms and a common difference between each term is the number you add or subtract to them.

A recursive function can also be defined for a **geometric sequence**, where the terms in the sequence have a common factor or common ratio between them. And it can be written as;

**a _{n}= r × a_{n-1}**

### Recursive Function Example

Let a_{1}=10 and** a _{n }= 2a_{n-1 }+ 1**

So the series becomes;

- a
_{1}=10 - a
_{2}=2a_{1}+1=21 - a
_{3}=2a_{2}+1=42 - a
_{4}=2a_{3}+1=85 - and so on.

**Points to Remember To Derive the Recursive Formula**

- Recursive functions call its own function for succeeding terms.
- Always check the type of sequence whether it is arithmetic or geometric, that means the number is added or subtracted in the next term of the sequence with a common difference or they are multiplied and have a common factor between them respectively.
- Find out the common difference for arithmetic series and the common factor for geometric series between each term in the sequence respectively.
- Then write the recursive formula based on first term and successive terms and the common difference or common factor between them for both the series.