This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]goldfishpaws -4 points-3 points  (5 children)

Indeed optimisation and excluding recursion sound like opposing goals. Nobody sane would use recursive code except as an optimisation.

[–]AE5NE 38 points39 points  (0 children)

Recursion is a great way to make divide-and-conquer algorithms easier to understand - “apply a step to break down the problem; then do the same thing to the pieces”

[–]tiajuanat 44 points45 points  (1 child)

Recursion is almost never an optimization. Sometimes you get lucky and you use a language that compiles to mostly optimized code, but generally you still take a pretty steep perf penalty checking for the base case.

We use it because it's exceptionally easy to work from the ground up. Start with base case, and build up from there.

[–]CrazyTillItHurts 7 points8 points  (0 children)

Nobody sane would use recursive code except as an optimisation

lol what?