Biton supports recursion.
So how to write the recursive code in Python we shall be discussing here.
What is recursion?
So let me explain that one at first, the process in which a function calls itself directly or indirectly
will be known as the recursion, and the corresponding function will be known as the recursive function.
So that means what within the function body, the function will be called itself.
So that is a direct calling and whatever the intended calling from the function and that function will
be called.
But that function in turn will be calling the the calling function.
So that is known as the indirect recursion.
So whatever the case, the recursion is there and the respective function is called recursive function.
Using recursive algorithm, certain problems can be solved quite easily, and with the fewer number
of calls in recursion, there will be a best guess.
So what does a biscuit's that means in businesses for certain inputs?
Outputs are known to us, and that is known as a business just considered in case of fact.
Well, calculation.
The best guess is that if the input number is zero or if the input number is one, then the factorial
value will be one.
So that is a Becka's say in the subject calculation of two numbers that Becka's is that if the two numbers
are equal, then the city is any one of the number itself.
So that is known as a best guess.
That means for certain inputs, outputs unknown to us.
So Python supports recursion.
So advantages of recursion, recursive functions make the code look clean and elegant.
We know that in our data structure we had two algorithms for your two hours of problem, and we know
that in case of recursive algorithm, we we wrote only four to five statements that are putting some
non recursive algorithm.
We had to write one page full of codes.
So that means that recursive algorithms are very easy to write.
The future course are there.
So obviously that programmers will feel comfortable environment to write a function in a recursive version.
So a complex task can be broken down into simpler problems using recursion here.
So second generation is easier with recursion than using some nested iterations.
So now what are the disadvantages of recursion?
Sometimes the logic behind recursion is hard to follow through.
So that is a very important one.
So while writing the recursive algorithm must be having a good grip over the programming logic, other
than sometimes the recursive algorithm will become too much tricky for you to understand the logic.
Recursive calls are expensive, Insaaf inefficient as they take up a loss of memory and time with the
depth of recursion is too big.
In that case, obviously it will go on keeping the instances of the previous coding.
So that's why the use memory recommended will be there.
And that's why there is a one of the disadvantages of using a one recursive algorithm and recursive
functions are hard to debug.
So these are the different advantages and disadvantages of recursion.
So let us go for one practical demonstration where we'll be showing you that how this recursion can
be implemented using python coding.
So here is the demonstration for you.
In this particular demonstration, we are going to discuss recursion, how to implement recursion here
to a defined one method.
The name of the method is fact, which is taking this in as input parameter, if any, is less than
equal to one return one.
We know that in case of recursion, there will be some Becka's that is for certain inputs outputs to
be known to us.
We know that if the value of any digital or the value of any one, then factorial of N will be one here.
Other is what will happen, return and start factoring in minus one.
So let us suppose we have this value five here so n will be assigned to five.
Five is less than equal to one is false.
So it will go for five in two factorial.
For now, factorial force of four will be assigned to and four is less than equal to one.
The condition is false.
So to go for four in two factorial three.
So again, in this case we'll be having three and two factorial.
Two again.
Two is less than equal to one condition is false.
So it will go for two in two factorial.
One and N is less than equal to one will be true.
So it will be returning the value one here.
So that is my factorial, one that will get multiplied with two.
So I'll be getting two here so that will get multiplied with three.
So now this particular recursive call will retries back to the through the columns.
And ultimately I'm going to get this one that is five two factorial four.
So Factorial four will be obtained as 14 to three to two into one.
So that that will be our twenty four into five.
So 128 will be the outcome.
So let us go for the execution.
You can find that the factor of five is 120.
So in this way, the recursive function can be written in Python.
Thanks for watching this video.