MHN

Ask HN: Is Recursion Worth It?

14 points by nigamanth·1403 days ago·Show in HN

Is recursion really worth it? My CS teacher told me to avoid recursion when possible.

Apparently recursion takes up more memory space than nested for loops (I'm talking about 4-5 for loops) and I lose grades for the same.

Add a comment on Hacker News →
1 of 44 comments
  1. It’s worth learning as an important CS concept, as it can be intuitive to express an idea and understand the algorithm on a conceptual level. Although implementing recursion can sometimes feel very confusing, apart from the fact that you might also hit a stack overflow and it runs slower than an iterative solution.

    In fact, a few days ago I implemented a flood fill algorithm for a drawing app I am developing. I later converted it to an iterative solution. Here’s a comparison between the two solutions

    https://zkpunk-xyz.vercel.app/posts/recursion_vs_iterative/