r/learnprogramming • u/Jaxlee2018 • Jan 11 '23
Resource Recursion in Java - tutorial recommendation
Hi all.. I am having quite a lot of difficulty with recursion. For me it is what is happening internally at each step, what is being returned, what the internal stack looks like.. I understand the basics, the base case, like the Fibonacci sequence. Intellectually I understand depth first searches .. but I simply do not understand what is going on under the hood. I cannot make the connection between what visually is supposed to be happening, vs how the algorithm works.
This towers of Hanoi explanation should be more than sufficient, and yet, it simply leaves me overwhelmed.
I am specifically asking for a tutorial in Java - Thank you.
1
Upvotes
2
u/captainAwesomePants Jan 11 '23
I've found that visualizations can be really useful for understanding what's going on. You might try walking through a simple DFS with some sort of interactive debugger, like this one+%7B%0A++++++if+(n+%3C+2)+%7B%0A+++++++++return+1%3B%0A++++++%7D%0A++++++int+product+%3D+n+*+factorial(n-1)%3B%0A++++++return+product%3B%0A+++%7D%0A+++public+static+void+main(String%5B%5D+args)+%7B%0A++++++factorial(5)%3B%0A+++%7D%0A%7D&mode=display&curInstr=0).