Image for post
Image for post
Original comic from Safely Endangered. No idea who created this variant of the meme.

Disclaimer

This article is not meant to introduce more advanced concepts like dynamic programming. Instead, it will introduce the mentality required to start solving recursive problems.

The examples are in Javascript, but I’ll write answers in Python and C++ in the bottom of this article.

What is recursion

Since you are reading this article, I’m assume that you have a vague idea of recursion, so I won’t go deep into the context of it. Personally, I like to think of recursion as the following.

Recursion is a way to solve a problem by solving smaller subproblems.

Before we start …

About

Jack Chen

Full Stack Engineer

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