Day 13: Tail Recursion and Python Baselines

Tried to figure out what was wrong with my code that would lead it to need a recursion limit of eleven to run a recursive function with a depth of 5-6 (still trying to figure out which one it is). I found out that there is a baseline limit of 2 or 3. Also got introduced to the term “Tail Recursion” which I still need to look into. Overall I am still diving deeper into this rabbit hole LOL.

TLDR;

Okay, so here are the highlights of what I did:

  • Still reading through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. I tried to determine what “depth” evaluates to in recursive algorithms. I haven’t figure out what is causing the seemingly extra recursive calls that are hitting the limit too soon. One thing that stood out to me in a Stack Overflow question was the concept of inclusion vs. exclusion on limits. For example if my code is arguably requiring a recursion limit that is double of my estimated depth of the call, the recursion limit would need to be set to one about that value to ensure that the code runs. It seems that the recursion limit in python is not inclusive. If I understood the explanation correctly, it means that a limit set at 1000 will only allow recursion up to 999. If the code were to recurse to a depth of 1000 exactly the code would timeout with an error. The recursion limit would therefore need to be set to 1001 to allow for a recursion with a depth of 1000. I still have a lot more to read up on but that definitely helped me understand a bit of the problem. I imagine that python also calls some function onto the stack by default which is causing the recursion limit to demand a value above at least 3.

Conclusion

That’s all for today. This is my sixth round of the “#100daysofcode” challenge. I will be continuing my work from round five into round six. I am currently working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal is to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in term derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.

I have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects.