How do I get good at this? I try to do the exercises without looking at the code but then I just stare at the screen for too long and no work gets done. Then I pretty much have no choice but to look at the solutions. This has been going on for MOST of part 2. Part 1 was not so bad.
My only reprise is to just redo all of Part 2 once I’m finished, maybe I’ll pick SOMETHING up. Anyway, just wanted to ask if there’s any easier way to learn recursive data structures?
I redid most of part 2. It’s definitely less difficult this time (I even feel I nailed BSTs) but wowsers, graphs are something else! Even tries are brutal. The going is so slow LOL but I got to be patient. I’m using this course as a foundation alongside my current CS courses.
I don’t think I got much better at recursion. I just understand how recursion works in non-linear data structures like trees. But my understanding still needs more work lol. In that case, it just takes repetition. Watch the videos and do the exercises again, you’ll get used to it like I did.
What I would do is try to solve it myself. If I get stuck, rewatch the previous videos. If still stuck, watch enough of the solution to get unstuck. When I have it working, try starting from scratch and see if I can make a working solution again (repeating the process). Iterate on that until I could solve it without referring to the videos.
One thing to be wary of is thinking you need to produce the exact same code as Mosh. This would be a mistake. You need to use the same algorithm, but your code does not need to be identical.
For recursion, you have to remember two things:
when does the function need to call itself again?
when does the function need to finish (or what is the base case)?
For lists, the base case is usually when you have no “next” node. For trees, the base case is usually when you reach a leaf node (or you find the target you are looking for). For graphs, it is often when there is nothing left to visit.