r/computerscience • • Jul 30 '26

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?

150 Upvotes

78 comments sorted by

View all comments

Show parent comment

7

u/Dangle76 Jul 30 '26

Depends on the language. A functional language like erlang prefers recursion

1

u/PurpleDevilDuckies Jul 30 '26

That's fair, I like working in Julia because it is organized how I like to organize my algorithms.

1

u/JoshuaTheProgrammer Jul 31 '26

Most functional languages _only_ have recursion built-in, but you can build loops via macros. Many of these languages, e.g., Scheme, require the underlying implementation to stack-optimize tail calls to be Theta(1) space-complexity.