Implementing recursive algorithms


As you might have already guessed, recursion is implemented via nested function calls, as we learned earlier in this course. However, a recursive function calls itself instead of calling some other function. Now that we know about stack frames and stack memory, it is easy to visualize how these recursive function calls work under the hood.

Continuing our ATM queue example, let us look at how a recursive function can implement the recursive relation.

  1. C++

  2. Java

  3. Typescript

  4. Javascript

  5. Python

The recursive function call in the code above works in three steps to return the result.

Liking the course? Check our discounted plans to continue learning.