Recursion has been a critical topic in 148 for a while now, and now I get a write about it!
Recursion is a topic heavily discussed, and for good reason since it is difficult to wrap your head around.
Using the function in the body of the code of the same function not only is hard to describe in words, but is a ridiculous concept in itself. Obviously, without some rules, the function would explode and keep going until the end of time (if there was no recursion limit!). To prevent this, and to keep the entire recursive function working, there is always a base case to stop the function from repeating itself. Figuring how to write a base case for a recursive function is the most difficult part of recursion, as it takes an understanding of how the function is being called EACH time and the code has to work EACH time as well. Recursive functions are very useful for things such as nested lists, as it allows python to go over each nested list separately and it doesn't matter how deep the nested list is. Once a recursive call is traced, you know the value of that call so I found it very helpful to use the value that is produced from the call instead of tracing the entire call from the beginning over and over again.
Recursion is a useful tool that I hope to master by the end of this course!
No comments:
Post a Comment