int f(int m, int n) { // m >= 0 int i = m; int j = n; while (i > 0) { j = j + 2; i = i - 1; } return j; }
Assume that m >= 0 initially. Use the method from class with its four separate steps to prove that this function will always return the value
n + 2*mYou should use
j = n + 2*(m - i)as the loop invariant. (This is such a simple program that you can easily see what it does. But I'm testing your ability to follow a methodology. There will be little if any credit if you don't follow the 4-step method taught in class:
double[] A = new double[100]; // put 100 distinct doubles into A somehow double[] B = new double[75]; insert(A, B); void insert(double[] A, double[] B) { for (int i = 0; i < 75; i++) { // Random(a,b) returns random int between a and b inclusive B[i] = A[Random(0,99)]; } }
BuildMaxHeap2(A) a.heapsize = 1 for i = 2 to A.length MaxHeapInsert(A, A[i])