Hacker News new | past | comments | ask | show | jobs | submit login

> If you need to add two arrays of numbers, use loop or array addition

There are plenty of algorithms that make more sense when expressed using recursion. Iterating over a list of numbers generally isn't one of them. But walking a tree is a good example.




More specifically: if you don't want to recursively iterate a tree, you have to hold a list of prior nodes to return to anyway... which is no different from weaving that information into the stack. Non-recursive iteration in this case literally requires you to emulate the recursion.


Those algorithms usually use non-tail recursion. Most tail recursion uses usually is trivial to rewrite in a loops.


> Most tail recursion uses usually is trivial to rewrite in a loops.

Except for tail calls that aren't self-calls. Which for code I write is actually fairly frequent.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: