Are there advantages for using recursion over iteration - other than sometimes readability and elegance?

Posted by Prog on Programmers See other posts from Programmers or by Prog
Published on 2014-06-03T15:07:23Z Indexed on 2014/06/03 15:52 UTC
Read the original article Hit count: 455

Filed under:

I am about to make two assumptions. Please correct me if they're wrong:

  1. There isn't a recursive algorithm without an iterative equivalent.
  2. Iteration is always cheaper performance-wise than recursion (at least in general purpose languages such as Java, C++, Python etc.).

If it's true that recursion is always more costly than iteration, and that it can always be replaced with an iterative algorithm (in languages that allow it) - than I think that the two remaining reasons to use recursion are: elegance and readability.

Some algorithms are expressed more elegantly with recursion. E.g. scanning a binary tree.

However apart from that, are there any reasons to use recursion over iteration? Does recursion have advantages over iteration other than sometimes elegance and readability?

© Programmers or respective owner

Related posts about recursion

Related posts about iteration