The topic of recursion can be intimidating and daunting at first to newcomers, and one can get frustrated and find difficulties wrapping their heads around this topic. π€
MIT OpenCourseWare
Prof. Eric Grimson framed recursion in a straightforward and easy to understand way. He also introduced a simple yet powerful concept that goes with recursion called memoization. π€―
One can think of memoization is essentially a list of performed tasks and its values, and if the task at hand is in the list, just get the value; else add the task and value to the list.π
Notes:
Here is a great resource for Python beginners on recursion:
Recursion in Python(A Gentle Introduction)
Elijah Jeremiah L. Barba γ» Dec 16 '19
Jokes aside, after watching the video, you're at least a little confident with recursionπππ Happy Coding!
Top comments (1)
Cool post-Elijah!, Memoization works great for recursion! Although it kinda sounds like Tweety bird pronouncing memorization the same way he pronounces "I thought I thaw a putty cat". Nevertheless here is how you can implement it in Python.
Instead of doing this which consumes a lot of memory:
You add memoization to optimize the recursion:
Or you can also use a builtin python tool:
Here is the complete video explaining it clearly, plus it is where I got this code from.