Question: int[] A = (1,2,3,4,5) public static void mySort(int[] A, int p ,int q){ int[] scratch = new int[q-p+1]; //5-1+1=5 for (int i = 0; i
int[] A = (1,2,3,4,5) public static void mySort(int[] A, int p ,int q){
int[] scratch = new int[q-p+1]; //5-1+1=5
for (int i = 0; i < A.length; i++) { //i i need to find the loop invariant and initialization, maintenance, and termination. is the loop invariant that scratch[i] position is equaled to the value within A[i] initialization would be scratch[i] =A[i]?? i dont think it is right but Im a little confused about invariants. scratch[A[i]-p] = A[i]; //s[A[i]-1]=A[i]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
