Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the missing code to complete the implementations for two sorting algorithm

ID: 664671 • Letter: W

Question

Write the missing code to complete the implementations for two sorting algorithms – Specifically Merge Sort and QuickSort.

void bubbleSort(int[] arr) {

int size = arr.length;

boolean swapped = true;

while (____________________)

{

swapped = __________;

for (int i = 0; i < size - 1; i++)

{

if (arr[i] > arr[i + 1])

{

// swap int temp = arr[__________];

arr[__________] = arr[__________];

int temp = arr[__________];

swapped = __________;

}

}

}

}

void selectionSort(int[] arr)

{

for (int i = 0; i < arr.length - 1; i++)

{

int minIndex = i;

int minVlaue = ____________________;

for (int j = i + 1; j < arr.length; j++)

{

if (arr[j] < minVlaue)

{

______________________________;

______________________________;

}

}

int temp = arr[i];

arr[i] = arr[minIndex];

arr[minIndex] = temp;

}

}

Explanation / Answer

void bubbleSort(int[] arr) {
   int size = arr.length;
   boolean swapped = true;
   while(swapped == true){
       swapped = false;
       for(int i = 0; i < size - 1; i++){
           if(arr[i] > arr[i + 1]){
               int temp = arr[i];
               arr[i] = arr[i + 1];
               arr[i + 1] = temp;
               swapped = true;
           }
       }
   }
}

void selectionSort(int[] arr){
   for (int i = 0; i < arr.length - 1; i++){
       int minIndex = i;
       int minVlaue = arr[i];
       for (int j = i + 1; j < arr.length; j++){
           if (arr[j] < minVlaue){
               minIndex = j;
               minVlaue = arr[j];
           }
       }
       int temp = arr[i];
       arr[i] = arr[minIndex];
       arr[minIndex] = temp;
   }
}