Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
char *ptr; /*a pointer*/
Recursion is basically a sort of loop. Every recursion has an iterative equivalent. Loops are easy because you see the loop variable that stores the state, right?
Recursion can seem confusing because the state is somewhat hidden in the call stack which tells you at what recursion level you are.
Unless you have tail call optimisation so that there is no call stack, in which case the compiler is clever enough to figure out an iterative equivalent of the recursion, i.e. a loop. -
@Fast-Nop I think it mainly comes down to having trouble figuring out how to establish the base case. Like, picking the problem apart to see how it goes together. Maybe it’s just a practice thing.
-
Remember that recursion is risky. Always make sure your condition will be met for all inputs.
-
Khepu1486yHow i got to feel recursion was learning prolog. Any kind of lisp or haskell will also help a lot. Imo other languages don't lend themselves for recursion and that's why many people find it hard.
Related Rants
Scheduled an on-site. *internal screaming*
Does anyone have any resources for studying distributed computing and operating system topics or have any pointers for studying for a systems design interview?
Also, how did y’all get comfortable with recursion? I don’t have issues with problems I already know the solutions to but it’s like when that’s not the case my brain just goes into panic mode for a bit.
Teach me your ways?
question
tech interviews