From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Memory considerations with recursive algorithms

Memory considerations with recursive algorithms - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

Memory considerations with recursive algorithms

- [Narrator] Recursion as a powerful and useful tool. But it does have some potential issues that it is important to be aware of. The first we will look at is memory usage. Whenever cursive function is called, frames containing the data for each successive call added to the (indistinct) stack. This has implications in terms of memory. And Python has a default limit for how many times a recursive function can call itself to avoid using up too much memory. Let's take a look at how this works. So you can see when I run this program which is the same factorial function which we've looked at previously, then we get an error when I try and do factorial of a thousand and the error is recursion error, maximum recursion depth exceeded in comparison. So this is evidence that (indistinct) is limiting the number of recursive calls that we can make. So what we can do, is to import the SYS module that's the system module, and have a…

Contents