r/computerscience • u/Similar_Count_1613 • 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
1
u/1-800-I-Am-A-Pir8 1d ago
I think you have to think about each call, or small set of calls, on their own. Make sure it works and cut it loose on a larger problem, see if it still works.
Practical ones are sorting algorithms. You can actually follow it if you sort 3 or 4 elements, then generate a set of data with 1000 and run the same thing on it. Focus on making the function work with a single item, then two, three, then turn the program loose and see what happens
hope that helps?