Multiple Recursive Calls
In this lesson, we look at recursive functions that do multiple recursive calls.
We'll cover the following
In the previous lesson, we started writing simple recursive functions. So far, all the functions that we looked at followed a simple recursive pattern of exactly one recursive call per equation. In this lesson, we will consider functions that require multiple recursive calls.
Fibonacci numbers
As an example, let’s write a function to compute the Fibonacci sequence.
The Fibonacci numbers are defined using a recursive equation. The first two Fibonacci numbers are 0
and 1
. The successive numbers are obtained by adding the two previous numbers. This leads to the sequence
The implementation as a recursive function is straightforward:
Get hands-on with 1200+ tech skills courses.