Have you ever seen the movie Inception? If you don’t know Inception, you can click here for a quick plot summary. The point that I am getting it is that like Inception’s concept of a dream inside a dream, Recursion is a pattern in which involves a function calling itself in itself.

Recursion is a different way to think about writing a solution. It takes one problem and focuses on a smaller piece of it and tries to solve it a little at a time until you reach an end. It works by invoke the same function with a different input until you reach the end.

It is important to note that there are TWO very important things to have when creating a recursive function. The first is the “base case”. The base case is the condition required for the recursion to end. If you don’t have a base case, the function will never stop. Think of the base case as Ant Man’s regulator…. If he didn’t have a regulator, he would continue to shrink uncontrollably.

The second thing needed for recursion is to ensure that you are changing the input so that you can get to the base case. If you didn’t change the input, you would go nowhere.

Below is an example of recursion:




Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Location, location, location

5 minutes to Setup Hyperledger Fabric Explorer Custom UI


All you need to know about Ivy, The new Angular engine!

How to Install KeyCloak 17 on Windows Machine

Call to Action: Accelerating Node.js Growth

#Shorts - Mount Vs Render in React.js

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thomas Muscarello

Thomas Muscarello

Software Engineer

More from Medium

C++ Program to find all prime numbers from 0 up to a given number N

3 number sum in array problem

What is a Dynamic Array?