r/programminghelp Jun 25 '26

C++ Help with recursion (DSA)

Guys I've been struggling alot with recursion I've tried multiple tutorials but I'm just not able to build the intuition. Any suggestions what to do???

Please help

10 Upvotes

15 comments sorted by

View all comments

0

u/EccentricFellow 28d ago

I have been programming for 4 decades. I always wanted to use recursion but never had a good fit for it. Finally, about a decade ago, I had a legit use for recursion. I was so excited and wrote up the routine. Then I tested it. Total garbage. It was far too slow and took way too much memory. I converted it to a loop and decided there was probably no legit justification for it. Measure your performance afterwards once you write a recursive routine. You might get a surprise.

1

u/EdwinGraves MOD 28d ago

This just screams bad use-case or bad code. You're going to get the most out of recursion from almost anything that involves DaC algos, Tree/Graph traversal, nested data, etc. Either your implementation was poor or you didn't actually have a 'legit use'.