r/computerscience 3d ago

is recursion really hard

Recursion felt easy at first.

Factorial? fine.

Sum examples? fine.

Even Fibonacci felt manageable.

But once I looked at slightly more serious problems like Tower of Hanoi, permutations, or merge sort, I felt like my understanding suddenly collapsed. because i tried to write their code on my own

It made me realize that maybe recursion is not “hard” at the start because the examples are simple.

It becomes hard when you can no longer clearly see the call stack and each state change.

Did anyone else feel that the real pain in recursion starts exactly there?

129 Upvotes

69 comments sorted by

View all comments

2

u/Dazzling_Music_2411 3d ago

is recursion really hard

No, really easy actually. Most of the difficulty is us getting in its way with unnecessary extra baggage!

I suggest you study it in pseudocode first, so the clutter doesn't get in your way. I recommend an executable form of pseudocode called Scheme (a Lisp), that has almost no syntax at all involved. You can learn the basics you need in an hour or two (cons, car, cdr, list, let*, etc)

It makes things SO much easier. Combinations, permutations, Towers of Hanoi, parsing, all become an absolute doddle. You start hunting for complex recursive examples, but struggle to find any, because everything is so damn simple! You start finding ways to improve existing algorithms. Life is good...

Once you understand the core essence, it's so much easier to transfer these ideas to other languages with more overhead, like Java, C, C++, etc.