O'Reilly logo

Learning Java Functional Programming by Richard M Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

When to use recursion

There have been two main criticisms of recursion:

  • It takes longer to execute than an iterative version
  • It is hard to understand

In the early days of software development, the technique was even barred in some organizations.

While a recursive version may take longer, for many problems this efficiency issue is not a significant concern given the improved processing speed on modern machines. Recursive efficiency issues lie with its typical implementation using a program stack. It is the pushing and popping of the activation record during method invocation that is expensive. This concept was detailed in Understanding the program stack.

Not all problems are suited for recursive solutions. Recursion should be used when:

  • The problem lends ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required