 recursion is basically when a function is able to call itself. So imagine we have a basic function like this. We have an f and it has an argument x. If we in any point in that function called that function again, that is a recursive function. So a function that executes itself is a recursive function. So in most cases you're going to see something like this. You're going to see an x minus 1 in the recursive call of a recursive function. And the reason people do this is because usually you want to change what arguments are passed to recursive function every time. There are cases where you don't want to change the arguments being passed but that's pretty rare. So let's actually take a look at how a recursive function flows. So I set up this little animation how this recursive function runs and I'm going to step through it to like really show you what it's doing. So at a very fundamental level our recursive function like this is going to call itself over and over and over and over again infinitely. And let me show you how this runs. So imagine you have an f and this f is taking a 2. So in place of x we have a 2 and then it calls recursively the f again with 2 minus 1. And when we do that we get an f with a 1 being passed to it. And then that f is going to recursively be called with a 1 minus 1. So it's going to be a 0. So then we have this function 1 with a 0 and again it's going to recursively call that 0 with a minus 1. So it's going to be negative 1. Then a negative 2. Then negative 3. And a negative 4. And this is going to just continue infinitely with no end. This is why we need something called a base case when we run our recursive functions. A base case is simply a way of telling the function if you ever get to this part of the code stop recursing and return some result. So here is my example of base case. In this function a base case is if x is equal to 0 return 0. So we're telling our function instead of returning the f return the 0. Because when you return the 0 you are you're kind of like stopping the recursive calling of this function. So let me show you how this is going to work. So we have our f and we are calling our f with a 2. So in place of the x we have a 2 now. And we are going to recursively call our f again with 2 minus 1. And we do that because our x is not equal to 0. So now we have our f being called with a 1. And again our x is not equal to 0. So we are going to recursively call our f again. Then our f is equal to 0. So because it's equal to 0 we are going to return 0. This is the base case. This is telling our recursive function to stop recursing. And because of that it's going to return 0. When it returns to 0 it's going to return that value to our function. So it's going to evaluate to 0. Then it's going to return the value to our function again and it's going to evaluate to 0. And the result of this execution is just 0. Here's another example that is kind of more useful. So we have a function f and this f is taking an x. And if x is equal to 0 it's going to return 1. If it's not equal to 0 it's going to return 1 plus f. So let's see how this runs. We have our f and we're going to call it with a 2. So if 2 is equal to 0 return 1. That's not the case. So we are going to return 1 plus f. So we have to recursively call our f. And when we do that we are going to call f with a 1. And when we call it with a 1 we are basically doing this whole process again. And finally we get to our base case. So our base case is if x is equal to 0 then return 1. And because f has been called with a 0 we have to stop recursing. We have to return that 1. So that's our base case. And when we return that we are returning 1. When we return 1 to our calling function it's going to evaluate to 1. And it's going to return a 1 plus 1. So we get 2. Then it's going to return that to our function again. So it's going to be a 1 plus 2. So it's going to give us a 3. So the result of this recursive function is a 3. And let's do one more. But this one is going to be a little more complicated. So in this one we have a function which is going to call our recursive function plus another recursive function. So if x is less than 1 we're going to return 1. If not we are going to return f plus f. So let's actually see how this evaluates. So we have our function and we're going to call it with a 2. And when we call it we are going to check okay if 2 is less than 1 return 1 that's not the case. So we're going to call our f which is going to call 2 minus 1. And when we do that we are going to get f with a 1. Then we're going to recursively call that again. So we're going to call it with a 0. And because we are calling it with a 0 we are going to return 1 because we hit our base case. Then we're going to return that to our function which is going to give us a 1 here. Then we're going to execute the other side. And this side is also going to turn 1. So the result of that side is going to be a 2. So there we have a 2 plus. Then we have to execute the other side of this recursive function. So when we do that we are going to do the same thing that we did on the one side. So again we are getting a f1 then a f0. Then we are getting a 1. Then we are returning that. Then we are getting a f0 again. Then we are returning that to so we get 2. And then we return to and we get a 4. So that's basically how recursive functions run. It's really useful to visualize recursive functions because when you really see how they run it really shows you exactly what they are doing. Instead of just looking at the code and saying oh I have no idea what this is doing because the syntax isn't really that optimized for recursive function understanding.