Hello, everyone.
So in this video, we will try to solve one more recursion problem, so I want to calculate power.
OK, so I want to calculate X to the power and OK, so X is any number and and is a whole number.
That is zero one, two and so on.
OK, so suppose I want to calculate five to the power three.
So this will be five to five and to five which is 125.
OK, so I want to calculate power.
OK, so what I want to do, I want to, I want to write a power function and I want to find X to the
power and OK so X is any number and N is a whole number.
OK, so how we can solve this problem.
So first we have to think of the recursive case.
OK, so.
What is extra the power and so can we write it like this x multiply the power and minus one.
OK, so we can write it like this, extra the power and is calculate extra power and minus one and then
multiply X.
OK, so we have to.
So I want to calculate the bigger problem than I have to calculate the smaller problem.
So this will be our recursive case.
OK, so.
If I want to find extra power in what I will do, first of all, I will find extra power and minus one
and then I will multiply.
OK, so this is our recursive case.
This will be our recursive case.
OK, so what will be our base case?
So base case is the smallest problem.
Whose solution we already know.
So suppose if the value of any zero, if the value of any is also that if the power is eroding the output
will be one.
So this will be the smallest.
This is the best case.
You can also take one as one.
Also be asked if xda Power-One will be X only.
OK, so it is our choice.
You can take this one and you can also take this one, OK.
Or you can take both our choice.
OK, so let's write the code for it.
So what I want to do, I want to calculate, so I will be under the name of the function is powered.
It will take 20 years.
I want to find extra power in.
Now, what is the best case, so first of all.
Bakkies, so.
Best case will be the smallest problem or solution we already know, so the smallest problem will be
if the value of any zero because it is a whole number.
OK, so the smallest often will visit only.
So if the value of any zero, what I have to do, I have to return one.
OK, and now our recursive case.
So recursive case, we already decided what we will do.
I will go alone and minus one.
OK, so I have a small output.
OK, so a small.
Output, it will be.
I want to find extra power in my istván, so at this line we have extra power and minus one now after
we have extra power and minus one, we have to do our calculation part.
So what is our calculation, but basically I will return X, multiply small output.
OK, and let's call let's test our function.
Suppose I want to find five to the power three.
OK, so five cube, so five cube will be 125.
OK, so let's turn our file.
So our output is 125, so our goal is working fine.
OK, now we will try to our goal after writing the code.
So we think we think only in terms of PMI and then after writing the code what we do.
We looked at another quote.
We will make the diagram.
OK, so I want to find five to about three.
So what will happen?
This is five and this is three.
OK, so the value of X is not changing, only the value of it is changing.
So I am writing a letter here.
OK, so this is three.
So three is not close to zero, so I will come at this lane so and minus when we are calling one and
minus one if you want.
You can also write five also Kaso five commentary.
Now this is five Camarda.
Again, we will call on five Gormogon.
Now we will call on five zero, OK, if the value of an asset over time returning, I'm returning one,
so this will return one.
OK, so our small output decision then I am returning X multiplier, small output.
So the value of X is five.
So five multiply one.
So this will be five.
So our small output is five.
Then I am returning X multiplier.
Small output.
So five multiply five.
So I will return twenty five.
So our small output is 25 then I am returning X multiplier small output.
So five multiplied.
Twenty five.
So it will return one twenty five and five cube is 125.
So I will call this working fine.
OK, so this will be the diagram.
OK, so I hope by this time we know the procedure, first we have to write the code and after writing
the code and when and while we are writing the code, will think only in terms of PMI.
After writing the code, we will draw this diagram OK, too, so that we can understand it better.
OK, so this is our code.
So best case of a small output, which be the recursive case and then our calculation part.
So this is how this code is working.
This is how we calculate power function.
This is how we can read about using recursion.
OK, thank you.