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. We will learn this function here with the help of some examples.
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.
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.
A function which calls itself from its previous value to generate subsequent value.
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 a1,a2,a3,a4,…..,an,… 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 an.
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;
an= r × an-1
Recursive Function Example
Let a1=10 and an = 2an-1 + 1
So the series becomes;
- 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.
Study, related topics on recursive function by downloading BYJU’S- The Learning App and get interactive videos.