00:01
Hello and welcome.
00:03
We are looking at chapter 5, section 4, problem 23.
00:11
We want to devise a recursive algorithm for computing n squared.
00:15
So we'll call it procedure square.
00:27
It's going to take some non -negative integer as a parameter.
00:41
We want to start with the end in mind, so kind of the bottom of this, a non -negative integer would include zero.
00:52
So in the case that we reach kind of the end, the bottom, if n equals zero, then we're going to output zero.
01:05
And we're going to return zero.
01:07
Otherwise, we need to use this fact they gave us to kind of figure out how we're going to break this down.
01:20
N plus 1 squared equals n squared plus 2n plus 1.
01:31
So if this is true, what does it mean for n squared? it means that n squared equals n minus 1 squared plus 2 times n minus 1 plus 1 plus 1.
01:55
So if i just, so this is n plus 1 here.
01:59
So if i subtract n plus 1 by 1, i get to n.
02:03
And if i subtract all my ends by 1, this is how it shakes out.
02:06
So else n minus 1 squared plus, we can at least simplify this last part.
02:15
We can simplify the whole thing if we wanted to, but this is 2n minus 2 plus 1.
02:20
So that's 2n minus 1.
02:22
All right.
02:24
So this is my procedure.
02:26
You could work it out a little bit cleaner by multiplying that and combining like terms, but we don't need to, i don't think.
02:33
Now we want to prove this using induction.
02:39
So first step, we want to prove that square 0 equals 0 squared.
02:55
So square to 0 equals 0 squared.
02:59
By definition, i don't think i have to show too much there.
03:02
That's true.
03:03
Zero squared is zero.
03:05
This if statement right here guarantees that square 0 is 0.
03:08
Now for the more interesting step.
03:11
The inductive step...