00:01
So in this question we have been given to use a recursive function to find the sum of this series given over here whose ieth element is given by this formula i by 2 i plus 1 and we must print this series for i varying from 1 to all the way to 10.
00:23
So we have to use recursion here so we cannot use 4 loop.
00:27
So let's just see what what would happen if we do a recursion for this.
00:32
So for any of you.
00:33
Recursive function there are two main aspects that we must figure out the first is what is the portion of the operation that is repeating which we which we can do by calling our function within our function so that we don't have to use for loop and the second is a condition where it stops because the recursive function cannot keep going forever so there must be a stop function or a stop condition for it that's how the program will end and give you an output so in our case let's look at the values here.
01:06
So first is we have 1 by 3 which is basically nothing but 1 by 2 into 1 plus 1 because i is 1.
01:17
Let me write so i is 1 and the element let me call it is 1 plus 2 into 1 plus 1 which is 1 by 3.
01:39
That's the first thing.
01:41
When i is 2 it is 2 by 2.
01:43
2 into 2 plus 1 or 2 by 5 as you can see this will replicate this series as we go but what happens before we do that is that we take 1 plus 3 and we add 2 by 5 to it and then we find out 3 by 3 2 plus 1 which is equal to 3 by 7 and then we add this over here so basically our operation is to find out i 2 i plus 1 and then add it to our recursion operation.
02:23
So a recursion operation will find i minus 1 2 times i minus 1 plus 1 plus recursion.
02:31
So this will keep going and we can see that the end will happen when i is equal to 1 that's when it will become 1 by 2 into 1 plus 1 or 1 by 3 and from here on there is no more recursion.
02:43
So this is the stop condition.
02:45
Stop condition is that i must be equal to 1.
02:47
So for any i that is greater than 1 we keep doing this until it reaches i equal to 1.
02:52
So that's the way we will write a function.
02:56
So on the right side here, i have created one function, which is the main function that runs an i variable through a range of 1 to 11 because range function does not take the last value takes n minus 1...