Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

// Insertion Sort public static void intInsertionSort (int [] a) { for (int i = 1; i int temp = a [i]; int j; for

image text in transcribed

// Insertion Sort

public static void intInsertionSort (int [] a) {

for (int i = 1; i

int temp = a [i];

int j;

for (j = i - 1; j >= 0 && temp

a[j +1] = a[j];

a[j + 1] = temp;

}

}

// Selection Sort

public static int[] doSelectionSort(int[] arr) {

for (int i = 0; i

int index = i;

for (int j = i + 1; j

if(arr[j]

index = j;

int smallerNumber = arr[index];

arr[index] = arr[i];

arr[i] = smallerNumber;

}

return arr;

}

//Heap Sort

public static void heapSort(int[] array)

{

heapSize = array.length;

BuildMaxHeap(array);

for(int i = array.length - 1; i > 0; i--)

{

int temp = array[0];

array[0] = array[i];

array[i] = temp;

heapSize--;

MaxHeapify(arr, 0);

}

}

// Merge Sort

public void sort(int inputArr[]) {

this.array = inputArr;

this.length = inputArr.length;

this.tempMergArr = new int[length];

doMergeSort(0, length - 1);

}

private void doMergeSort(int lowerIndex, int higherIndex) {

if (lowerIndex

int middle = lowerIndex + (higherIndex - lowerIndex) / 2;

// Below step sorts the left side of the array

doMergeSort(lowerIndex, middle);

// Below step sorts the right side of the array

doMergeSort(middle + 1, higherIndex);

// Now merge both sides

mergeParts(lowerIndex, middle, higherIndex);

}

}

private void mergeParts(int lowerIndex, int middle, int higherIndex) {

for (int i = lowerIndex; i

tempMergeArr[i] = array[i];

}

int i = lowerIndex;

int j = middle + 1;

int k = lowerIndex;

while (i

if(tempMergArr[i]

array[k] = tempMergArr[i];

i++;

} else {

array[k] = tempMergArr[j];

j++;

}

k++;

}

while(i

array[k] = tempMergArr[i];

k++;

i++;

}

}

// Quick Sort

public void quickSort(int lowerIndex, int higherIndex) {

int i = lowerIndex;

int j = higherIndex;

//calculate pivot number, I am taking pivot as middle index number

int pivot = array[lowerIndex + (higherIndex - lowerIndex) / 2];

//Divide into two arrays

while (i

while (array[i]

i++;

}

while (array[j]

j--;

}

if (i

exchangeNumbers(i, j);

//move the index to the next position on both sides

i++;

j--;

}

}

//call quickSort() method recursively

if (lowerIndex

quickSort(lowerIndex, j);

if (i

quickSort(i, higherIndex);

}

private void exchangeNumbers(int i, int j) {

int temp = array[i];

array[i] = array[j];

array[j] = temp;

}

The purpose of this assignment is to implement various data structures and algorithms described in class. Overview One of the most important ADTs is the Dictionary and one of the most studied problems is sorting. In this assignment, you will write multiple implementations of sorting algorithms Are there techniques you can create or tweaks you can make to introduce a Winning Algorithm for this assignment outside of the techniques listed in the GUI? Write program GUI to perform analysis on various sorting algorithms from the Sorting Algorithm Slides. Winning Algorithm Insertion Sort Insertion Sort List Properties InOrder AlmostOrder ReverseOrder Selection Sort Random 15286 Quick Sort Create The List Experimental Results MergeSort N: 15286 DataType: Random Sort: Insertion Heap Sont Comparisons: 116823255 Movements: 45855 Total time: 230 Radix Sort The purpose of this assignment is to implement various data structures and algorithms described in class. Overview One of the most important ADTs is the Dictionary and one of the most studied problems is sorting. In this assignment, you will write multiple implementations of sorting algorithms Are there techniques you can create or tweaks you can make to introduce a Winning Algorithm for this assignment outside of the techniques listed in the GUI? Write program GUI to perform analysis on various sorting algorithms from the Sorting Algorithm Slides. Winning Algorithm Insertion Sort Insertion Sort List Properties InOrder AlmostOrder ReverseOrder Selection Sort Random 15286 Quick Sort Create The List Experimental Results MergeSort N: 15286 DataType: Random Sort: Insertion Heap Sont Comparisons: 116823255 Movements: 45855 Total time: 230 Radix Sort

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions