Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 2
    Some problems are simply more naturally expressed using recursion. Tree traversal, for example. Commented Apr 24, 2017 at 21:06
  • Updated my answer to address that point, Commented Apr 25, 2017 at 1:16
  • 1
    With regards to "naturalness": tree traversal without recursion, for example, tends to produce larger, less general purpose code. Consider for example using polymorphic calls to traverse the tree, with different behavior for leaf and composite nodes. This is not possible without recursion. Commented Apr 25, 2017 at 13:41
  • 1) Did you take up my challenge to define "natural" yet? 2) Since it is possible to simulate recursion using a stack data-structure, it is possible to implement tree traversal that way too. It may not be the most efficient way ... and it won't give you the most readable code ... but it is definitely possible, and practical to do it. Commented Apr 25, 2017 at 14:12
  • By the way, the first programming language that I learned (FORTRAN 4) did not support recursion at all. Commented Apr 25, 2017 at 14:15