Hi, everyone.
So in this video, we are going to solve this question, Jack Element, Besant Inari.
So we need to solve this question using equation.
We can easily solve this question with the help of our Lopevi look, but since we are learning it so
we will use it to solve this question, the question is very simple.
So given an every.
So inside out, you will have many elements.
So you want to search for a value, let's say.
So if the value of X is five, so you have to tell whether five is present in the area or not.
So if five is present, you need to return.
True, if the value of X effects is not present in the area.
I will return false.
So you just have to check whether the element is present in the area or not.
So our function function rebel.
Function will take it as input and it will take size as input.
So since we are going to use recursion, so I told you there are two ways of making already.
So first of all, is like this will break the idea like this.
And the second way of using recursion, and that is it will break our array like this.
So let's discuss both the approaches.
So first, let's discuss this approach.
So what will do?
This is already.
So I will take a value X, which we need to find.
So what if I am splitting my if I'm breaking my error like this?
So I will work only on this part.
So first of all, I will check.
So if this value.
So if they Nix's it also if you offer zero as it goes to the value of X, that means X is present here.
So in that case, I will return to I have to return a boolean value so I will return true.
Otherwise I will lose.
So I will call the equation on the rest of the area.
So this is a and this is a plus and a number of elements and minus one.
So I will call the equation on the side and the question will return the answer.
True or false.
True.
If the value X is present in this small area and the equation will return, false equation will return
false if the value is not present in this small.
Very simple.
So let's write the code.
So what do you want to do?
Level and we just need to check.
So is president.
Of the function is as pleasant, it will take it as input.
And we will take how many elements?
And will take a value X, which we need to find out.
So basically, it's a very simple.
If size is zero, if my head is empty, so if it is empty, it will likely return false.
If that is empty value X cannot be present inside already.
So I will return false.
So first of all.
This is the area I'm standing here.
So this is the next first I will check whether here or not.
So let's check where the next president or not.
So if.
AOF zero.
Is equals two X. So in this case, I will return to.
I find out x axis in that desert, and so I will return to.
So if this is not the case, so what I will do, I will call the Guardian on this small lady, so this
is a plus one and number of celebrities and minus one.
So if it turns true, that means X is present.
So I will return.
True.
If it is false, that means X is not present here and zero zero is also not equal to X, so I will return
false.
So basically I just need to return.
Basically I just need to return the answer of this Mollari and that will be my final answer.
So the answer to this Mollari will be my final answer.
So like Lyttleton, let's copy the name of the function is present.
As president, we will give every.
That is a plus one number of elements and minus one.
And minus one, and the value which you want to search for is X.
So let's call this function.
So the function is present if it's present at a number of elements, five, and I want to search for
three.
So let's bring the message here.
Found.
In the last part, we're going to bring in our town.
So let's test.
So please present to you present in the area.
That's why the output is found.
So let's write a novel called.
So basically, this is our area, one, two, three, four, five.
And number five, so size is not zero and the zero element, so one is not equal to X is basically five,
X is basically three.
This is the value of X, so one is not the to three.
So I will call on this one, three, four, two, three, four and five.
Two, three, four and five, a number of elements for and the value of X is remaining same, so the
value of X is three.
Size is not zero and two is not equal to three, so I will call on this Mollari.
Three, four and five.
Number three, the value of X history.
So now size is not zero, but X is equal to the first element.
So excessive collateral of zero.
So I will return.
True.
So I will return to.
So basically is present in this very experiment in decided, that's why I'm getting through.
So whatever value you are getting, just done that.
So I'm getting through.
So just don't do so.
So three percent in this area.
Whatever value you are getting from the equation, just like that value.
So I will return to.
So if I'm returning to this condition is true, I will be found.
So let's take one more example in which the element is not present.
So I want to search for sex and sex is not present.
So the output should be not found.
So the output is coming out to be not found.
So now let's see how it will work.
So if this is already.
Elements are one, two, three, four and five.
Number five, the value of X history, and this is the value of any size is not zero and one is not
equal to three.
So we will call on this, Mollari.
This is two, three, four and five number of elements for value of accessory sizes, not zero.
And the first element, two is not close to three.
So I will call on this, Mollari, so I will call on three, four and five number of elements, three
and the value of X history.
OK, so the value of X versus the value of X is six, the value of X is six, sorry.
So size is not zero and six is not equal to three.
So I will call on this Mollari.
So I will call on four and five.
Number of elements is to.
The value of ethics, so size is not zero and four is not close to six, so I will call on the smaller
sizes.
One say it is not zero and the first element, the first element, five is not equal to six.
So I will call on the empty.
So I'm calling on the empty added number of elements is zero and the value which you are searching for
is six.
So I have decided zero have decided zero return false.
So I will return false.
So whatever value you are getting from the equation, you are just likely returning that value.
So I will unfold.
I will return false.
And finally I will return false.
So that's why the output is coming out to be not found.
So currently what we are doing.
So if this is Mary.
So first, I am checking whether this value is equal to X or not, and then I am calling on that equation
and then I'm calling it a collision on this Mollari.
OK, you can see first I am checking and then I am calling so we can do the opposite.
Also what they can do.
So first.
Let's first check whether expert in this area or not, so let's call that equation for this.
Well, first check this.
I will parsecs.
So it will return to things.
It will return to or it will return false.
So if it returns through, that means the value that is present here.
So my answer will be to.
But if a return false, that means X is not present in this area, then we will check whether X is present
at this next or not.
So if it is false, then I will check if of zero equals equals X or not.
So if X is present here, I will return.
True, if X is not present here, I will return false so we can start a discussion like this one like
this also.
So let us write the code.
Let's copy the function.
So Bulle is presenta.
This case will remain same now.
We will remove it from here.
So first, I need to check so bull.
Let's say left president.
Or let's call it smaller and smaller.
Or let's call it lefty, so I'm calling this area as right, Teddy.
So this is right, Teddy.
So is the ex-president in the right area?
This is right, Terry, so let's rename it or what else can we named a better name?
So remaining at it, let's call it remaining at.
So instead of Friday, let's call it remaining at a.
So if.
The value is found in the remaining.
So if remaining, that is true.
So in that case, I will return to.
Simple.
So what I'm doing, I'm calling the location, I'm calling the location and the output of this is basically
the remaining area.
I'm calling it location on the remaining area.
So it will return.
True.
So if it is returning true, if it is true, then I am returning.
True.
Yes.
The value is present here.
Now at this line.
The output is false.
So now I will check for disvalue.
So now let's check.
So if aof zero equals equals X, then in that case you will return to.
And the ultimate, you will return false.
Simple.
So now let us test this experimental.
So six is not present, so the output should be not found.
So the output is not found.
So I did one mistake here, I am calling this president also I should write is president to hear.
Let's test it one more time.
So the output is not found and let's take a value, which is Besant, so I want to search for five,
five is present, so output should be found.
So the output is coming out.
We found.
Simple, so let's see how it is working.
Let's take one example, let's take this example.
Only one, two, three, four and five.
So one, two, three, four and five number of elements is five, and the value of X is also five.
So first of all, what you will do, you are calling you are just actually calling the recursion.
You are passing the smaller number of elements.
So I'm likely calling the recursion two, three, four and five.
Now, a number of elements for the value of access.
Five, again, size is not zero.
So called recursion, three, four, five, three exits, five sizes, not zero, so called precaution
four and five number of elements is to and I want to search for five.
So again, the size is not zero.
Size is not zero.
So again, collocation on the small number of elements.
One, the value of excess five.
So again, the size is not zero.
So you will call the equation and size becomes zero.
You want to search for five.
So it is a zero.
If the size is really well done, false, you will return false.
So this really is basically fault, so I will not go into effect, so I will reach here, I will check
the first element.
So first element is five.
Now five is equal to the X, so you will return.
True.
So this thing will return to.
So ForFour, you are getting through, you are getting through from the air.
So that means the value of the remaining air is basically to.
Because you are able to find the value of if you are able to find the value of life in the small area.
So you are getting to see the value of remaining crystal.
If it is true, you will return to.
So you will return.
True.
So, again, you are able to find X in this area.
That's why you are getting through.
So the value is through.
So you will return to.
Now you are able to find.
This X and this that's why you are getting through if you are getting through.
If this is true, you will return.
True.
So now you are able to find.
The value of X in this area.
That's why you are getting through, so if the value is true, you will return.
True.
So I will return true.
Since I'm getting through, I am printing this message found.
So that's how it is working.
So now I told you.
There are two ways, so we write the code for this approach.
Now let us also discuss this approach.
So what will do if I will make my error like this, if my if I break my error like this?
So first of all, this is.
And my one.
So first of all, I can check.
Is the value X present here?
So first of all, I can write a very simple check if the last element is, of course, two X, in that
case, you found the element, so you will return.
True.
Otherwise, what you will do, you will call the recursion on this area.
So this area will either return true or this area will either return false.
So if the value is present, if the X is present in this area, then in that case my output will be
true.
If X is not present in this area, then in that case, my output will be false.
So basically, if I'm getting through, I'm running through.
If I'm getting false, I'm returning false.
So basically we can just directly return the value of the onset of the smaller dancer for the smaller.
It will be the answer for the big area also.
OK.
So now let's write the code and what is the idea.
So it is the same, but the number of elements is less number of elements and minus one.
But we are passing the completely so bulle.
Is three, I will take it as input.
Number of elements and ex.
So this case will remain, Tim.
If that isn't pretty, you will false.
Either way, what you need to do.
So, first of all, I will check the last element.
So you have the last element.
Is it close to X?
Then in that case, I will return to.
Otherwise, what they need to do, so I will call an equation on this Mollari.
So let's copy this history, I am putting the complete number of elements and minus one.
And the value is X.
So let's call the function is presently.
Let's see.
So it should be found.
So our report is coming out.
We found.
So let's underscore how it will work.
One, two, three, four and five.
I want to search a number of elements for if I want to search for five.
Size is not zero, and the last element is equal to five, the last element is equal to five.
Written to say Willerton to.
Simple, so if the value which you want to so justly so, Teresa, also present over what will happen,
size is not zero and five is not close to three.
So you will call on this Mollari, you will call on one, two, three, four.
Number of elements is for anyone to search for three.
So size is not zero and four is not equal to three, so I will call on this Mollari one, two, three.
Size number three, and you want to search for three sizes, not zero, but the last elementary is equal
to three.
So you will return to.
If found, return to.
So for this area I am getting through from the left side, I'm getting through from the left side,
whatever value you are getting, just like Lyttleton, you are getting to return to.
So for this area I am getting through from the left side, so that means to use the left side, so whatever
value you are getting, just like any return that value.
So I will return.
True.
So that's how it will work.
So one thing, what is the difference between this approach and this approach?
So what is the difference between this approach?
And this approach, so the only defense is basically we are planning to close in on this, Eddie.
Here we are playing accordion on this area.
So basically, if you can see there are two ways of traversing the very first raised, I think the area
like this, which is exactly like this approach, secondly of traversing the area.
Basically, we can traverse from and to start, which is exactly like this.
So basically, since there are two ways for traversing the area from start to end and we can also traverse
the area from and to start.
So that's where there are two ways of using the equation on Eddy.
You can apply recursion from start to end like this.
You can make the array like this and you can also make the array like this.
So this is very similar to.
So these are very similar.
Exactly same.
And similarly here we are moving from end to start and to like this, moving from and to start.
So I told you that there is one more approach in next I approach.
So let's use your next high approach.
Let's write the call for index.
I also.
So we will take a variable in next, how do I treat ordinary?
So Bulle is presently.
It's president for I am taking it and put into an.
And X and I, so I'm using I will use variable to write over the area.
So what I want to say here is.
This is your area.
This is index and minus one, and this is the last index and which does not exist.
This is a net zero.
So in error.
So if this is already we can use a for a loop to iterate over the area to this recursive approach is
very similar.
You are taking a variable index, you're taking an index, i.e. the value of I will be zero, I will
pass Valerii zero from mean.
So what I will do, I will traverse over this area and then I will reach here.
So when the value of it becomes and so I will start Diversey when I, when I becomes.
And so that means value not found.
Well, not found.
You want to search for X, so if you reach and so, for example, when you're traversing here, if you
reach the lasting X, that means the value is not present.
Similarly, if I become, then that means the value not found.
If you found the value in between.
Then you will return to.
Simple, so here what he used to write like this, if you are using AI Group, reverse psychology.
Lieutenant Shapelessness.
So if Yoffie is equal to X, you will return.
True.
So this is for loop.
This is what you will write using for loop, so we will we are just trying to simulate that approach
here.
We are passing a variable.
If I listen after everything, the whole area, if I am not able to find the value inside the array,
I will return false value not found if the value is present in between the array.
If the values present in the area.
So in that case, what will happen if I will become equals to X and in that case I will return.
True.
So you can see.
We are just trying to simulate the follow up approach, using the recursion by just taking a variable
eye.
So let's write the code.
So what is the best case?
So if I become sequel's to end after I think the whole area, if I reaches and or the other way to say
is basically if that is empty.
So you can see this line in this if it is the last or next or if that is empty, then the value is not
present.
So in that case, you will return false.
Otherwise, you can check.
So if if I is it close to X?
So in that case, you will return to.
Otherwise, what you will do, you will call this function is pleasant for.
You will get better.
You will give any number of elements will not decrease.
You will give X and you will give a plus one.
See, what I'm doing here is.
So here I used to write a placeless so check check out the current position, if not present Movahed,
check out this position, if not present, move ahead.
So basically, I am checking.
I am checking and I am moving ahead.
What I'm doing here, I am checking if found return true otherwise for moving ahead.
I am doing a plus one.
See, we are just trying to simulate the for loop approach using the recursion I am explaining one more
time.
Check at the current position, check out the current position, if found, return to check out the
current position.
If found, return to.
If not found, move to the next position.
Basically a plus plus, similarly, if not found, move to the next position.
So this is for moving to next position.
And finally, if the loop gets over, if you reach at this line.
So what is the meaning at this line?
If I become second to and then in that case, you will return false value not found.
So similarly, we are trading we are just ideating over the and if I reach the last index, the value
is not present, so I will return false.
So let's test let's call this function is present for and then we will Dhiren also.
Is President Ford.
Let's say I want to search for food and we need to pass the value of I so I is zero.
I will start from I will start searching the area from index zero.
OK, I will start searching the area from Exito.
So it will be found.
So I would put this phone and similarly, if you will give another element, which is not pleasant,
let's say.
Zero.
Let's say sorry, let's say you want to search for zero zero zero is not present inside this area,
so it will be false, not found.
So zero is not pleasant.
So now let's batten, although I think there's no need to underscore, it's very simple, but let's
write in so that you can so you guys can have a better understanding.
So this is the Eddie.
The value of any number of elements, five, let's say I want to search for four and the value of a
zero, I am passing zero.
So this is a.
So sources, first of all, I'm checking I is not equal to zero, is not close to five and one is not
equal to four.
So in that case, I will call on this Mollari.
Two, three, four, five and one, so a number of elements will remain the same remains same size and
same sex remains same, so the same X will remain same and the value of five will become one.
So one is not close to five and this is a two is not close to four.
So we will move ahead.
So this is one, then two, then three, then four and then five.
Number of elements to maintain X and the value of, I don't know, so two is not close to five and this
is a.
So three is not equal to four.
So what will happen?
You will move ahead.
So one, two, three, four and five and five X is four, and the value of eye is three, so three is
not equal to five.
This is a.
Four, is it close to four, so Alphie, is it close to you, Will?
So I will return to.
Whatever value you are getting from the record, just like Lyttleton, so I will return to I will return
true.
And finally I will return true.
So basically for this present, I decided that I am getting return.
That's why I am getting through.
Now, can you observe first the value of five zero, now the value of Aizman.
Now the value of I used to and now the value of Estie.
So we are just linearly trading over the area exactly like the for loop.
So this is very similar to for loop.
We are just iterating over the.
You can see the value of 5.0, then it becomes one, then it becomes two, then it becomes three.
And similarly it will keep increasing.
And finally, if I will reach the index and then I will return false.
That means the value is not present.
And whatever value you are getting, you are just dagbladet.
So, for example, if you want to search for, let's say, six, so six is not present, so you will
call ahead.
You will call one, two, three, four and five, five, six, and the of I will become four.
So now you will check.
So I is present here.
So you will take four and five not equal and five is not close to six.
So you will call one more time.
One, two, three, four and five, the value of five now, so it reaches here.
So this is your next and this is not possible.
The value of an is five and you want to search for six.
So now five equals five, eight ages and ages.
And so in that case, I will return false.
So I will return false.
And whatever value you are getting from the equation, you are just likely returning.
So I will return.
False return.
False written.
False return.
False return false.
And finally, I will return false.
Six is not present this idea that the output is false.
So that's how it is working.
So this approach passing the index.
This is exactly like the for loop approach.
It is the same number of elements.
Same exact same.
Just only this condition.
This is like a placeless.
And this is the best case, and this is if the value founded on.
So this is from this video.
I will see you in the next one.