When Is Recursive Good?

When should I use recursion? Recursion is made for solving problems that can be broken down into smaller, repetitive problems. It is especially good for working on things that have many possible branches and are too complex for an iterative approach. One good example of this would be searching through a file system.

Is recursion a good thing?

Recursion is a useful technique for making code terse and comprehensible. However, it is less performant and breeds stack overflow exceptions in non tail call optimized languages. Carefully scrutinize your use case when choosing between recursive and iterative functions.

What are the benefits of recursion?

  • Recursion can reduce time complexity. ...
  • Recursion adds clarity and reduces the time needed to write and debug code. ...
  • Recursion is better at tree traversal. ...
  • Recursion can be slow. ...
  • Iteration: A function repeats a defined process until a condition fails.
James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.