Search⌘ K
AI Features

When to use Recursion

Understand when recursion is the best approach for coding problems by learning to identify if problems break into smaller subproblems, require arbitrary nested loops, or feel natural to solve recursively. This lesson helps you decide between recursion and iteration to improve your problem-solving skills.

Ever wonder why programming languages such as Haskell, Scala, JavaScript, etc are so in demand nowadays? This is because these languages are based on Functional Programming, meaning the system is built around the concept of recursion. Entire languages are now being based on recursion. Interesting, right?

In general, almost any problem that can be solved with a non-recursive code can also be solved by recursion. In fact, most problems that can’t be solved by a non-recursive code can even be solved by recursion. This doesn’t mean, however, that you should always ...