DEV Community

Cover image for Algorithms: Recursion
Tamerlan Gudabayev
Tamerlan Gudabayev

Posted on • Edited on

2

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

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)
  }

  console.log(num)
  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)

Conclusion

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay