Can someone explain mathematical induction to prove a recursive method? I am a freshmen computer science student and I have not yet taken Calculus (I have had up through Trig). I kind of understand it but I have trouble when asked to write out an induction proof for a recursive method.
Can someone explain mathematical induction to prove a recursive method? I am a freshmen
Share
Here is a explanation by example:
Let’s say you have the following formula that you want to prove:
This formula provides a closed form for the sum of all integers between
1andn.We will start by proving the formula for the simple base case of
n = 1. In this case, both sides of the formula reduce to1. This in turn means that the formula holds forn = 1.Next, we will prove that if the formula holds for a value
n, then it holds for the next value ofn(orn + 1). In other words, if the following is true:Then the following is also true:
To do so, let’s start with the first side of the last formula:
That is, the sum of all integers between
1andn + 1is equal to the sum of integers between1andn, plus the last termn + 1.Since we are basing this proof on the condition that the formula holds for
n, we can write:As you can see, we have arrived at the second side of the formula we are trying to prove, which means that the formula does indeed hold.
This finishes the inductive proof, but what does it actually mean?
n, then it is correct forn + 1.From 1 and 2, we can say: if the formula is correct for n = 0, then it is correct for
0 + 1 = 1. Since we proved the case ofn = 0, then the case ofn = 1is indeed correct.We can repeat this above process again. The case of
n = 1is correct, then the case ofn = 2is correct. This reasoning can go ad infinitum; the formula is correct for all integer values of n >= 1.