3 ms·
> 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. Iter
by RHSeeger 4y ago
> 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.
- kmeisthax 4y agoMore 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.
- vbezhenar 4y agoThose algorithms usually use non-tail recursion. Most tail recursion uses usually is trivial to rewrite in a loops.
- wtetzner 4y ago> 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.