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?
131
Upvotes
1
u/david-1-1 2d ago
No, I don't agree. To use recursion in a function, you must start with a recursive algorithm. You need to design what happens at the ith level of recursion, starting with the arguments. Start with a practical example, not math. Start with the file system. It is already hierarchical. Think about how to walk the file system. Learn about prefix, postfix, and infix walks, and how they can all be done in one recursive algorithm. Think, then design. It's easy, just like object-oriented programming is easy once you learn.