Recursion vs iteration

Recursion vs iteration

This post is about using recursion vs using iteration.

The most straightforward application of recursion is to replace iteration using a recursive function instead of for/while loops. Such recursive functions allow to iterate over data structures, taking as parameter the index that would be used in a for loop. As an example, let's consider the following code printing a c++ vector:

Pagination


© 2021 Franco Fernando. All rights reserved.