 So in the previous video we talked about the idea of a sequence being a discrete function It's a function which has some gaps between The input value so that might seem like kind of a weird thing to do It's like why do we want breaks in the data? Well, it turns out that it might not be natural to have anything between them because of the way It's built as a sequence, but also this idea of this discrete gap actually leads itself very naturally Naturally to different constructions that don't seem to have a continuous comparison So a good example of this is is the idea of a recursive sequence Which actually provides another way of defining a sequence that is not based upon the general form But instead you can actually define the sequence by previous terms So as an example of this let's take as an example of a seek a recursive sequence You always have to define a few initial terms This is sometimes referred to as a base case of some kind And there might have to be more than one in this situation. They'll just be one So we take a base case s one equals one So this is the first term in our sequence everything will be based upon this or sometimes this is called a seed Because this is where the plant grows from now We have this sequence where the first term is going to be one and then subsequent terms So this is our right here our recursive relation our recursive relation And so the recursion here tells us that the previous or the next term of the sequence will be determined by the previous term And so in this situation sn which is the next term in our sequence It'll be based upon four times the previous term in our sequence So let's take a look at these things right here first term Right here our first term is going to equal to one because that's what we were told it was supposed to be Now the second term s2 By the recursive relationship s2 is gonna be four times s1 its predecessor Well looking back over here s1 was one so we're gonna take four times one four times one is four And so the second term in our sequence is going to be four and if we keep track of this We're gonna get one comma four the first two terms For the next term in our sequence s3 well We multiply by four times the previous term s2 well the previous term if we check over here is a four So we're gonna get four times four which is 16 which tells us that the third term in our sequence is a 16 Which we're gonna record that here 16 Doing the next term s4. We're gonna multiply the previous term s3 by four four times 16 is 64 So we see that the third term in the sequence is going to be 64 which we record that down here And then doing this one more time the fifth term in our sequence s5 We get this by multiplying the previous term as four by four four times 64. We get a 256 there and which course we record that down here and we can keep on going The next term in our sequence will be four times 256 The next term in our sequence will be four times whatever the term was before and we can keep on going to get this pattern Established by always computing the previous term by its predecessor Now it does turn out that one could describe this same sequence without recursion whatsoever. We're just taking powers of four But we start with the zero with power so we get four to the zero right here four to the first four squared four cubed Etc that gives us this general form Four to the n minus one we can go from a recursive formula to a general formula But there's some oftentimes a benefit from having a just a recursive formula Let's take a look at another example. We can actually define the so-called factorial sequence recursively and we'd start off with the with the base case that One factorial is equal to one and then we define recursively in factorial as n times n minus one factorial So we're just going to multiply by n the previous term in the sequence And so what we see here is the following one factorial is equal to one. We do that by definition Two factorial it's gonna be two times one factorial, but as we check one factorial is one Therefore we see that two factorial is going to equal two times one that is to say just a two For three factorial three factorial will be three times two factorial, which we see right here is two You're gonna end up with three times two, which is in six That's what three factorial is going to turn out to be four factorial Recursively we're going to define four factorial by taking four times three factorial Checking at the previous term in this list three factorial was six So we're going to get four times six, which is equal to 24 And then one last example we compute five factorial by taking five times four factorial five times 24 is 120 and this gives us the factorial sequence and we can actually We can find a pattern going on here that five factorial notice was five times four factorial But four factorial was four times three factorial three factorial three times two factorial two factorial was two times one Factorial and one factor was just a one So this this this 120 here turns out just to be five times four times three times two times one And that's the usual way people think of this factorial sequence Although we can define it completely recursively here Also as a as an aside, I do want to point out that the factorial sequence does include zero factorial And that's typically defined to well that that's going to be defined as one Some people erroneously think that zero factorial is supposed to be defined to be zero Because you should zero times anything should be zero But the issue here is that if you think of the definition of in factorial you're taking n times the predecessor The problem is zero factorial doesn't have a predecessor because there's nothing before it and therefore you're gonna have to Define it by some other rule not the recursion and so we're gonna find it to be one From this video it might not make sense why that's supposed to be one But as one starts thinking about Sequences and probabilities and things turns out zero factor equal one is actually the natural definition there Let's look at one more example, and let's actually look at a recursive sequence that involves two base cases This is often referred to as the Fibonacci sequence this example for which we define the first turn f1 to be one We define the second term f2 to also be one and then the Fibonacci sequence is based upon The following recursive seek of a recursive relation the next term in the sequence is then is then the sum of the two Previous terms so how does that work out? Well f1 will be one because we said it is f2 will be f will be one Because we skin we said it is f3 is computed as the sum of f1 plus f2 the previous two terms That gives you one plus one which is a two so we see that the third term of the sequence is a two F4 is then the sum of f2 plus f3, which was one plus two which is a three F5 will then be the sum of f3 and f4 F3 was a Sorry f3 was a two f4 was a three two plus three is Five like so and then lastly just as one more example f6 We take f4 plus f5 just the sum of the two previous terms you get three plus five, which is an eight And so everywhere you so the right here we can see the first couple terms of the Fibonacci sequence One plus one gives us a two One plus two gives us a three two plus three gives us a five three plus five gives us an eight Five plus eight gives us a thirteen eight plus thirteen gives you twenty one thirteen plus twenty one gets you thirty four twenty one Plus thirty four gets you fifty five thirty four plus fifty five gets you eighty nine fifty five plus eighty nine gives you one forty four And you see how the pattern continues and on and on and on We can very quickly determine the next term in the Fibonacci sequence just by adding together the two previous terms This is a one of the like the most famous sequences out there and is a recursive sequence It turns out the Fibonacci sequence shows up In art in nature because of its connections with the golden ratio Which is sort of a cult following we weren't gonna get into right now But curious enough this one this one's kind of impressive here curious enough You can actually show that the Fibonacci's recursion can actually be removed And you can actually use the general form of the Fibonacci sequence as Fn equals one plus the square to five to the nth minus one minus The square to five to the nth over two to the n times square to five for which the golden ratio is hidden inside of this formula right here this is often known as beignets formula and It might not seem at all obvious how in the world are does this simple recursion? Lead to this general form and this general form is actually kind of complicated here I mean if you actually think about the calculations with exponentials and square roots of five What have you and so in practice of one actually wants to calculate the Fibonacci sequence for the most part adding together a bunch of numbers It's gonna probably a simpler calculation than these type of calculations here But just so you're aware these recursive sequences the recursion can be removed and you can get this general formula Although sometimes the general formula is much more complicated than the recursion that we actually defaults to the recursive relation But I just want to show you in this video a way of defining sequences using this idea of recursion