Every year, I teach my students about using induction to prove that algorithms function as intended. My purpose, in instructing them, is to help them master the structure of the proof itself. I use simple algorithms for which we can do fairly easy inductive proofs. Here are a few examples:
Prove that arraySum
will correctly compute the sum of all of the elements in arr
.
public int arraySum(int[] arr){
int k = 0;
for (int g = 0; g < arr.length; g++)
k = k + arr[g];
return k;
}
Prove that this function will return $n^2$: Assume n is positive.
public int square(int n){
int sum = 0;
int count = 0;
while (count < n){
sum = sum + n;
count = count + 1;
}
return sum;
}
As you can see, I am not aiming for complicated algorithms. What my students need (and what I need) is a good source for practice problems. I'd absolutely love it if they were already carefully solved (so that my students could independently study with them and check their own answers), but I could work with any source that simply has a series of pre-made reasonable practice problems.
Is there any such resource out there?