DEV Community

Discussion on: Recursion Revealed

pinotattari profile image
Riccardo Bernardini

Both examples shown have the advantage of simplicity, but they could be also easily implemented in an iterative way. This could give the impression that recursion is just a fancy way to do something.

I think it would be nice to have also an example of "pure recursion," that is a problem that is easily solved with recursion, but not so easily in an iterative way. The only examples that come to my mind right now are the Hanoi tower and recursive figures like the Sierpiński triangle (the latter can be implemented iteratively using an expansion in base N, but it is not as immediate as the recursive solution).

ionabrabender profile image
Iona Brabender Author • Edited on

Thanks for the comment, Ricardo. As someone who is relatively new to concepts such as recursion, I wanted to explain it in a simple way that would make sense to beginners, as that was the type of material I was looking for when I first started out. Providing more complex examples could be something that I examine in the future.