00:01
So in this problem, we are asked to find or we are asked to write a function using recursion, which takes a list of numbers and outputs the largest number in the list.
00:15
So let's first look at the part of the program that inputs the list.
00:20
So here i ask the user to enter a list of numbers using separate by commas.
00:28
And then using the input function it stores the string format of that input to numms and then i use the split attribute of the string using split by comma by this character and what it does is that it splits all the things within between these commas as elements of a list so that is what we are reassigned to nums so now nums is a list of numbers which are still characters but they are different numbers that have been separated by comma.
01:03
And then finally we go into the nums, take each element of nums using this for any numbs.
01:08
First check if there is a empty character because what can happen is that you could have an input which is 2 comma 3 comma 4 comma which means there is a comma and there is something on this side which is none which is empty.
01:21
There's no number associated with it so we must not take that into account or there could be a situation where there could be two commas and so there's another empty thing here which again has no number and so we must not take that into account so to avoid that we do this check and if there is no empty character we append the eval output of this of this string as the number and append it to the end into an empty list called num list so eval will convert that string into a number so that's what we do and this is how we first take the list into the program and then this is the recursive function, the largest number, and say it takes three inputs.
02:05
The first is the list itself, the list of the numbers.
02:08
The next is the key or the index location where we are right now and the current largest number that has been found out in the list.
02:19
So there are two things that we have to always figure out for any recursive function.
02:23
First is what is the operation that repeats in itself? what is the operation that can be used as recursion? and the second portion of that is that we must always find out where will this recursive function end.
02:35
What is the reference or the base value or the base case where this recursion will end? so let's look at how we would go about it.
02:44
So if you have any, this is a little bit related to binary search algorithm.
02:50
So let's say you have these numbers here.
02:55
So if you want to find recursively the operation you would do is that you would take any two numbers.
03:00
Let's say we start from one end to the other.
03:02
So that there is a order to this.
03:04
So we check a and b first and we find out that let's say the largest value is b.
03:11
So then what we do is that we have here we have checked two values.
03:15
We have found a largest value and we know what key we are in.
03:18
So the key we are in is zero index.
03:22
Largest value is b and list is the same list here.
03:25
Right.
03:25
So i'm telling you in terms of the three inputs that go into the function.
03:29
Then we go, we pass on this zero plus one to the.
03:34
Next case.
03:36
So we go to next part.
03:37
We go check b and c.
03:39
Let's say b is still the largest here.
03:41
So this still remains b and the index becomes one.
03:46
And let's say we go next.
03:48
We check between c and d.
03:53
And let's say actually we are not checking between c and d.
03:56
We are checking between the largest number is already there, b and d.
03:59
So we are checking with we check with b first, a and b.
04:04
We check with b and c.
04:05
Now we check.
04:05
Would be in d.
04:07
Let's see d is the biggest one now.
04:08
So this will be updated to d.
04:11
The largest number will be updated to d in this line and the index becomes two.
04:16
So like this you can keep going and figuring out.
04:18
So all you need to know when you go to the next part of the thing is that where you are in the list and what has been the largest number that have been found till now and the list itself.
04:27
So these are the three things you need to make sure that you can keep recursively doing this.
04:31
And the check booth for this would be or the reference base case where the end comes is that you have reached the last portion of the last element of the list because there's nothing to check further.
04:43
So that would be the check.
04:45
So i have put this here in terms of the check first.
04:47
So always we do a check first because if the check has been reached, we need to end the program...