Thinking about thinking...
This week after spending time on practice questions I decided to place my focus on recursion.
Recursion is something that has come up a few times when pair programming with my boyfriend. He is a senior software developer and is a big fan of it, I on the other hand was not as convinced. A function calling itself? now that's confusing, however, it did get my attention.
So I decided to delve deeper, reading and watching various software engineers' blogs and explanations to try and help me get a better grasp on the concept.
My boyfriend and I have also been putting recursion into practice, having a go at some common problems that lend themselves to a recursive solution and working through them.
One of these was inverting a binary tree, which after looking at data structures last week at least meant I knew what this would visually look like. As we worked through the problem before I knew it my function was calling itself, using it to swap the left and right nodes and invert the tree. Success! If not still a bit magical for my liking. Recursion is definitely teaching me to think about things differently and to gain a deeper understanding of how my code runs.
After solving more problems using recursion, I definitely have a greater appreciation for how on occasion it can create a more elegant solution than perhaps my trusted for loop. However, like preventing the dreaded infinite loop, I am learning the hard way to ensure I add an end state to prevent infinite recursion.
So, with that being said I'm going to continue thinking about thinking...until my next blog!
Things to check out:
- https://www.freecodecamp.org/news/quick-intro-to-recursion/- an intro to recursion and what it is.
- https://www.youtube.com/watch?v=6oDQaB2one8 - a video taking you through examples of recursion.
- https://codeburst.io/learn-and-understand-recursion-in-javascript-b588218e87ea - a blog about understanding recursion in JavaScript.
Stay motivated:
“You must learn a new way to think before you can master a new way to be."
-Marianne Williamson