Question: To sort an array A [0.. N -1]: for (int last = N -1; last >= 1; last --) { // Move the largest entry
To sort an array A[0..N-1]:
for (int last = N -1; last >= 1; last --) {
// Move the largest entry in A[0last] to A[last]
for (int index = 0; index <= last-1; index++) {
//swap adjacent elements if necessary
if (A[index] > A[index+1]) {
int temp = A[index];
A[index] = A[index+1];
A[index + 1] = temp;
}
}
}
1. Compute the TOTAL primitive operations
2. Compute the Big O for the algorithm
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
