Courses
Courses for Kids
Free study material
Offline Centres
More
Store Icon
Store

Understanding Recursive Functions in Maths

Reviewed by:
ffImage
hightlight icon
highlight icon
highlight icon
share icon
copy icon
SearchIcon
widget title icon
Latest Updates

How Do Recursive Functions Work? Step-by-Step Guide

Recursion is a process of defining objects based on previously defined other objects of the same type. A recursion relation defines some rules and a few initial values to build up an entire class of objects. Here it must be noted that if an object is defined in terms of itself, it causes self-recursion and leads to infinite nesting. A real-world example of recursion is when you are climbing a ladder. To reach the 3rd rung of the ladder, you need to reach the 2nd rung. Basically, it means that completing each step is dependent on the completion of the previous rung. 


Recursive Function Definition – When a function calls itself and uses its own previous terms to define its subsequent terms, it is called a recursive function. It is the technical recursive function’s definition, i.e., a recursive function builds on itself.

The Recursive Function has 2 parts:

  • The value of the smallest or the first term in the sequence, usually given as f(0) or f(1)

  • The pattern or the rule which can be used to get the value of any term, given the value of the term preceding it. In other words, the definition of f(n) when values of f(n-1), f(n-2), etc are given.

We will now explore this by looking at the recursive function example below:

We are given a sequence of numbers 3, 5, 7, 9…

a(1) = 3 –> the first term in the series

a(n) = a(n-1) + 2 -> The rule or pattern where you need to add 2 to the last term to get the next term in the series.

So in order to find say the 6th term, we would need to find all the terms before that as shown below:


A(1) = 3

A(2) =A (1) + 2 = 3 + 2 = 5

A(3) =A (2) + 2 = 5 + 2 = 7

A(4) =A (3) + 2 = 7 + 2 = 9

A(5) =A (4) + 2 = 9 + 2 = 11

A(6) =A (5) + 2 = 11 + 2 = 13


What makes this function recursive is that it needs to know its own terms to figure out its next terms. 


Expanding the recursive function formula for Arithmetic Progression – The process of defining a recursive formula for an arithmetic progression can be done by carrying below 

mentioned steps:

  • You must determine that it is an arithmetic sequence, which means you either add or subtract the same constant value from one term to get the next term.

  • Find the number that you add or subtract, or the common difference between consecutive terms

  • Now the recursive formula can be created by stating 

    • The first term

    • The formula which involves the previous term and the common difference.

  • So it looks like this: 

    • a1 -> first term of the series

    • an = an-1 + d, 

    • here an-1 is the previous term, d is the common difference, an is the nth term in the series, and n the ordinal number of the term


The recursive formula for a geometric sequence – It is easier to create recursive formulas for most geometric sequences than an explicit formula. In this, the common ratio can be seen easily and can be used to create the recursive formula quickly. Let us look at a recursive function example for geometric series:

3, 6, 12, 24…


Here we can see that the first term is a1 = 3 and an = 2*an-1


Now we will look at the method to write a recursive function for a geometric series: 

  • You must determine that it is a geometric sequence, which means you either multiply or divide the same constant value from one term to get the next term.

  • Find the number that you multiply or divide by or the common ratio between consecutive terms

  • Now the recursive formula can be created by stating 

    • The first term

    • The formula which involves the previous term and the common ratio.

  • So it looks like this: 

    • a1 -> first term of the series

    • an = r * an-1

    • here an-1 is the previous term, r is the common ratio, an is the nth term in the series, and n the ordinal number of the term


Visualization of Recursive Function – A Pascal’s triangle is the most famous example of a recursive sequence. In this, you can see that each term is obtained by adding 2 other parts of the triangle. Below is a visualization of the triangle:


Conclusion - A recursive function is a function that builds by calling itself and is calculated using a starting value and a pattern or rule which gives the next value in the series. It can be applied to arithmetic as well as geometric series. A common difference is used to add or subtract for getting the next term in an arithmetic progression, and a common ratio is used to multiply or divide to get the next term in a geometric progression. These functions are widely used in coding algorithms where one needs to traverse hierarchies or find the factorial of a number. 

FAQs on Understanding Recursive Functions in Maths

1. What is a recursive function in mathematics?

A recursive function is a function that defines each term of a sequence based on the preceding terms. Instead of calculating a term directly, it uses a rule that 'refers back' or 'calls upon' its own previous values. A simple example is an arithmetic progression where you find the next number by adding a constant to the current number.

2. What are the two essential components of a recursive formula?

Every recursive formula must have two key parts to work correctly:

  • The Base Case: This is the initial value or a set of starting values. It's the 'seed' from which all other terms are generated and prevents the function from calling itself infinitely. For example, a(1) = 5.
  • The Recursive Step: This is the rule or formula that defines how to get the next term (n) from the previous term(s) (n-1, n-2, etc.). For example, a(n) = a(n-1) + 2.

3. Can you give a simple example of a recursive definition for a sequence?

Certainly. Consider a sequence where the first term is 4 and each subsequent term is 3 times the previous term. The recursive definition would be:

  • Base Case: f(1) = 4
  • Recursive Step: f(n) = 3 * f(n-1) for n > 1
This generates the sequence 4, 12, 36, 108, and so on.

4. How is a recursive formula different from an explicit formula?

The main difference lies in how you calculate a term:

  • An explicit formula allows you to calculate any term in the sequence directly, without needing to know any other terms. For example, to find the 10th term, you just plug n=10 into the formula.
  • A recursive formula requires you to calculate all the previous terms in order up to the one you want. To find the 10th term, you must first find the 9th, which requires the 8th, and so on, all the way back to the base case.

5. How do you find a specific term, like the 4th term, using a recursive formula?

You must work your way up from the base case. Let's use the formula f(1) = 5 and f(n) = f(n-1) + 10. To find the 4th term, f(4):

  1. Start with the base case: f(1) = 5.
  2. Calculate the 2nd term: f(2) = f(1) + 10 = 5 + 10 = 15.
  3. Calculate the 3rd term: f(3) = f(2) + 10 = 15 + 10 = 25.
  4. Finally, calculate the 4th term: f(4) = f(3) + 10 = 25 + 10 = 35.
You cannot jump directly to the 4th term.

6. Why is the Fibonacci sequence a classic example of a recursive function?

The Fibonacci sequence is a perfect example because its very definition is recursive. Each number in the sequence (after the first two) is the sum of the two preceding numbers. It has two base cases, F(0) = 0 and F(1) = 1, and its recursive step is F(n) = F(n-1) + F(n-2). It beautifully illustrates how a term's value can depend on more than one previous term.

7. What is a major drawback of using recursive functions in practice?

The main drawback is inefficiency when trying to find a term that is far into a sequence. For instance, to find the 500th term, you must perform 499 separate calculations, one for each preceding term. An explicit formula, if one exists, would be much faster as it would only require a single calculation.

8. Are recursive patterns found only in number sequences?

No, recursion is a fundamental concept that appears in many areas beyond simple number sequences. In geometry, fractals like the Koch snowflake are drawn using recursive rules where a shape is repeatedly applied to itself. In computer science, recursion is a powerful technique for solving complex problems, such as sorting data or searching through nested folders on a computer.