Hello everyone.
Welcome to this new recession.
So what do we do today.
So we will try to solve one more problem with the help of the occasion so so that our understanding
of religion can become better.
OK.
So the name of the problem that we are going to solve today is multiplication.
Okay.
So what do we do.
So given two numbers we have to merge to play them.
OK.
So there are two numbers m and n and we have to multiply these two numbers.
So that is M and doing OK so the one way to solve this problem is to simply use the multiply operator.
But we don't have to use multiply or break that.
We can only use additional played that.
OK.
We can only use plus operator or minus OPERATOR OK.
We cannot use the money to play operator.
Now I think we have hour to solve this problem but I'm not sure.
So if you are more dipping into numbers I mean when can I write it like this.
Basically I'm adding the same number and times.
OK.
I'm adding the same number and times.
So we're using one live plus operator here.
So the solution to the one solution for this problem is to just use a loop and that loop will run end
times and inside the loop we will add Eminem.
OK.
So I think you can solve it very easily with the help of for loop part of a loop.
But now we have to solve it using recursion.
OK.
So with that before loop how you will solve you will keep a variable sum equals zero.
You will run a loop and that group will run.
And times inside the loop what you will do.
You will write something like this simplistic was to him and then the loop will be all whether you will
have done some.
OK.
So with the help of recursion how we can solve this problem.
So we have to calculate M in doing okay.
Let's say the value of M is five and led to the value of minus three.
So our output will be 15 m in the end is 15.
Okay.
So m in doing so can I write M into N like M multiply and minus one bless em.
Can I add I did like this yes obviously we can write it like this.
This isn't a thing but if you multiply inside this is I mean minus M lesson and these two will cancel
out each other.
So it totally M N okay.
And so let's dry it and how we look.
So m in doing so I want to calculate five into three what I want to do here is multiply five with two
and then add plus five.
So the answer will be five into two.
That answer will be fifteen only.
Okay so basically what we're doing here is so five in total.
This simply means five plus five plus five.
So what we will do I will tell the equation to solve this smaller problem and then I will add five.
I will add m.
Okay.
This is m this is M and this is an okay so I'm building myself
let's take one more example let's say the value of M is three and the value of n is five.
Okay so I want to convert them into n.
So basically what we can do M Plus M Plus M How many times and times.
Okay.
So I want to multiply three into five so I will add three five times.
So three plus three plus three plus three plus three.
Okay.
So now what we will do we will use the help of the equation.
What we will use.
So what we will do we will break the problem into smaller problem.
I will tell recursion to solve this part for me.
And that equation will give me the answer and the answer will be.
And then I will add m.
Okay.
So this is M So the equation will give me the answer which is drill and then I will add M so if I have
a function multiply.
So how does multiplatform assembly look like it can take two input as outgoing M and then what I will
call I will call the same function multiply a function for the smaller input.
So I will tell occasion to give me down shut off.
So what it will give me it will give me the onset of M multiply and minus 1.
Okay.
And this is M in two n.
And finally what do we do.
We will add after equation we give me the answer I will add this m okay so this will be our formula
this will we this will be how that equation will look like.
Okay now first let us write the code and then we will died in the code.
Okay so what will be our base case.
So the base case will be very simple you want to calculate M in doing so base case will be the value
of any 0.
Then if you multiply with zero then now good will be Z only okay if you multiply any number with zero
that now it will be zero only.
So this will be our base case if any 0 return 0.
Okay.
Now first let us write the code and then we will drive.
Okay
so that it I will be in digit and let's say the name of the function is multiply what it will take it
will take two integer as argument M and then okay.
And what we have to conclude we have to calculate M in doing we have to calculate M in doing but without
using multiply or pretend without for loop or Y loop.
Okay now it's time for the base case.
So the base case is the smallest problem whose solution we already know save the value of any 0.
So any number multiplied with zero will be zero only.
So I will return 0.
Now it's time for the recursive case what we have to do we have to solve the problem for the smaller
input okay.
And where did this Malone put similar input is led to the value of and this and minus one to small and.
A small answer is you have to I'm calling the same function multiply
and I wanted to conclude M and do n minus one.
Okay so at this line I have done set off M and do and minus 1 and finally our calculation part of our
calculation part is very simple.
What we have to do I will return this small answer bless em and medicine.
Okay now let's call this function so let's call this function and let us give the value of a man an
so multiply and led to the values that three and 5.
Okay.
Now if we learn this code our output will reach 15.
Okay.
So let's send the file salad out for this coming out 215 basic level code is working fine.
Okay so this typing mistake here.
Okay now let's try to understand how output is coming out.
215 Okay so the values are 3 and 5.
Okay.
So we have three and we have five.
So these are the values of him and then.
Okay.
So 5 not articles 2 0.
So basically this function will wait at line number 10.
And I call the function for three comma food again.
This will wait at line number 10 and I will call for true commentary.
Similarly I wouldn't call for a on my 2 then I will call for three call my 1 and then I will call for
three comma zero so the value of any zero redundancy two.
Okay.
So basically this will be done zero.
So zero will be stored in this small answer.
So small answer becomes zero.
Okay.
My lines it become zero now I am returning a small answer.
Bless em.
What is the value of m m value of a mystery.
Okay so zero plus 3 it will be three so that's my leave small answer.
So this is small answer then I am returning small answer plus M and the value of a mystery only so three
plus three which is six so six is small answer so six plus three which is nine.
Okay so small answer becomes nine then nine plus three basically twelve.
So small answer is Twin and then twelve plus three which is fifteen.
Okay.
So fifteen is our answer.
Okay.
So that's how that equation is working.
Okay.
So but you do not have to take all of this.
Okay.
We will not think all of this.
What do we think we will think like first right the base case very simple.
Then write the recursive case we will.
We are calculating M2 the power in minus one you have to assume.
Okay.
You add line number 10.
What we are trying to do here is we are assuming that this multiplier function looks okay.
This multiplier function if it if you will give 2 input as argument it will give me m in 2 and minus
1.
Okay.
You have to assume this okay.
You have to assume that this function will work since this function is working it will give me the small
lines so I will add plus M to get to get our prop to get down to what the bigger problem.
Okay.
And then we add turning our answer.
Okay so first write the code then think about the diagram okay.
First write the code then thing go to the diagram to I hope this problem is cleared.
If you have any doubt you can ask me.
Okay thank you.