DEV Community

Cover image for Algorithms: Recursion
Tamerlan Gudabayev
Tamerlan Gudabayev

Posted on • Updated on

Algorithms: Recursion

There are just way to many algorithms in the world.

Fortunately, you don't have to learn them all.

They all mostly come in certain types.

One of these types is recursion.

That's what we will be discussing today.

What you will learn today:

  • What is recursion?
  • Recursive algorithms


Recursion put simply is when a function calls itself.

But why would it do that?

Because it breaks down the problems into subproblems.

Alt Text

This is the main premise of recursion, breaking down big problems into subproblems.

Here's a simple example:

function countDown(num){
  if(num == 0){
    return console.log(0)

  countDown(num - 1)
Enter fullscreen mode Exit fullscreen mode

Recursive Algorithms

There are many algorithms that use recursion but the most notable ones are:

  • Merge Sort
  • Quick Sort
  • Binary Search
  • Greatest Common Divisor (GCD)


Today was a pretty simple post, we learned what recursion is, and what algorithms use it. I hope you learned something today, and stay tuned for next week.

Top comments (0)