Question: This question looks very long, but I only need question 7 done (first 2 paragraphs) the rest of this stuff is information that might help

This question looks very long, but I only need question 7 done (first 2 paragraphs) the rest of this stuff is information that might help to complete it.

This question looks very long, but I only need question 7 done

Here is the two questions this one is referring to:

(first 2 paragraphs) the rest of this stuff is information that might

And here is the code and results for 1 and 2.

CPP Code:

#include

#include #include #include using namespace std;

void maxHeapify(vector&, int, int); void buildMaxHeap(vector&, int); void heapSort(vector&, int); vector insertSort(vector);

int main(int argc, char * argv[]) {

vector list1; vector list2; int size; cout > size; srand((unsigned)time(NULL));

for (int i =0; i

// print unsorted list cout

//Heap sort clock_t begin = clock();

heapSort(list1, int(list1.size() - 1));

clock_t end = clock(); double elapsed_secs = double(end - begin);

cout

// Insertion sort. begin = clock();

list2 = insertSort(list2);

end = clock(); elapsed_secs = double(end - begin) ; //only reports in seconds, need to replace.

cout

// print sorted list cout

cout

return(0); }

/* Heap Sort from Textbook using Vectors ***********************************/ void maxHeapify(vector& A, int i, int n) { int largest; int l = 2 * i; int r = (2 * i) + 1;

if ((l A[i - 1])) largest = l; else largest = i;

if ((r A[largest - 1])) largest = r;

if (largest != i) { swap(A[i - 1], A[largest - 1]); maxHeapify(A, largest, n); } }

void buildMaxHeap(vector& A, int n) { for (int i = n / 2; i >= 1; i--) { maxHeapify(A, i, n); } }

void heapSort(vector& A, int n) {

buildMaxHeap(A, n); for (int i = n; i >= 1; i--) // Remove last element from heap { swap(A[0], A[i]); maxHeapify(A, 1, i); // Heapify reduced heap } }

vector insertSort(const vector arr){

unsigned int i, j;

vector sortedArray(arr.size()); sortedArray = arr;

int max;

for(i = 0; i

for(j = i; j sortedArray[j]){ int tmp; tmp = sortedArray[i]; sortedArray[i] = sortedArray[j]; sortedArray[j] = tmp; }

}

//sortedArray[i] = max; }

return sortedArray; }

-----------------------------------------------------------------------------------------------------------------------

output screenshot:

./a.out Enter the size of array : 500 Unsorted List: 10 5 7 4 9 2 15 12 15 15 9 9 20 7 15 3 2 6 11 20 19 3 2 2 2 10 19 2 2 12 10 11 8 9 14 8 2 20 19 8 14 19 16 13 6 2 15 19 7 17 18 18 11 11 19 12 20 10 5 1 1 7 3 1 7 8 8 8 7 19 7 12 17 14 17 14 15 3 12 2 20 1 11 10 4 9 14 3 18 18 16 11 16 18 11 2 6 10 1 4 8 7 16 17 12 12 2 7 14 14 20 5 6 10 15 1 18 8 4 8 17 11 10 13 20 12 14 17 1 15 1 9 13 8 17 5 11 18 3 16 3 2 1 1 11 15 1 20 14 16 19 10 6 8 2 18 19 8 14 20 14 6 20 18 5 16 2 15 5 16 11 8 17 11 8 19 17 8 19 2 4 9 11 1 17 5 18 15 4 4 6 17 1 17 14 6 12 8 20 9 3 2 16 12 4 15 10 20 14 20 13 17 9 16 10 5 12 19 11 15 14 9 11 15 5 16 20 9 3 11 17 18 13 12 1 16 18 10 8 11 2 20 20 10 7 9 6 18 19 8 12 13 16 14 7 13 10 18 1 4 8 9 13 12 20 13 20 9 3 7 19 16 18 18 5 5 18 2 14 17 9 6 9 17 19 7 9 20 4 1 4 3 9 16 7 20 9 6 8 3 4 6 18 13 16 14 9 13 15 3 9 15 8 9 11 18 15 11 18 10 11 13 13 11 8 19 2 8 16 9 10 19 7 19 3 2 12 12 6 6 14 15 1 13 3 3 2 10 14 19 19 16 11 11 19 11 1 20 18 8 1 20 18 7 18 1 20 2 12 17 19 17 3 11 9 18 14 10 7 19 1 5 6 3 8 4 13 20 16 3 8 16 2 17 14 11 17 5 12 20 1 11 16 4 13 16 1 6 6 19 16 18 3 2 20 2 17 13 2 12 7 1 19 8 17 12 10 6 16 14 5 17 16 1 12 8 16 4 6 13 2 1 10 16 14 10 18 11 14 19 2 20 11 1 19 7 4 8 12 20 13 17 8 8 9 11 16 16 14 1 9 7 1 18 2 15 19 19 17 12 9 10 3 19 2 1 18 6 1 9 17 13 17 16 1 5 6 8 1 11 Heap Sort Elasped time is 0 Insertion Sort Elasped time is 0 heap Sorted List: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 insetion Sorted List: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20

./a.out Enter the size of array : 1000 Unsorted List: 7 14 4 3 3 8 13 3 11 4 16 16 16 17 12 17 8 13 14 4 11 10 18 14 19 6 6 20 18 1 18 4 15 14 18 17 1 10 12 11 13 7 18 9 15 1 17 15 14 2 18 16 11 7 1 1 4 7 13 1 7 10 16 1 3 13 10 15 15 13 17 19 11 15 7 5 15 16 19 20 17 8 16 20 15 16 20 18 2 12 11 1 14 18 13 8 3 14 15 17 6 11 15 16 17 14 13 4 9 3 3 5 11 18 16 17 14 16 6 7 19 16 7 4 14 12 12 16 5 6 4 3 8 18 18 5 3 2 8 11 5 10 8 7 20 3 3 5 10 8 11 1 16 10 4 1 1 7 8 17 4 11 19 12 20 9 8 3 10 15 5 6 16 4 12 15 7 14 19 8 14 2 8 9 3 4 9 3 10 8 11 14 18 10 17 17 10 4 11 19 10 16 5 5 19 16 12 17 2 2 5 15 3 4 15 17 7 15 11 17 2 2 2 19 3 18 7 12 13 18 2 2 5 6 18 15 14 9 12 15 11 8 1 5 11 15 2 10 9 4 18 10 5 19 8 7 8 6 18 20 3 20 13 19 17 10 14 2 19 17 8 1 4 8 17 6 2 10 7 10 14 4 11 18 2 10 17 1 16 6 20 10 17 4 9 6 14 2 7 4 18 15 4 13 14 12 10 16 2 17 17 15 20 20 4 14 9 12 14 4 18 6 14 6 9 2 11 14 15 10 17 4 16 12 8 9 4 17 16 5 5 5 11 17 4 6 10 12 10 15 16 7 12 1 4 13 14 15 6 8 4 3 11 11 6 10 19 9 18 15 5 3 19 7 19 2 5 20 5 14 6 12 12 18 12 15 10 5 1 15 12 16 9 14 6 15 3 5 15 13 11 20 15 9 6 5 2 10 16 6 3 1 18 6 10 1 1 19 6 1 6 9 17 6 15 14 12 9 18 7 1 8 18 7 8 3 11 9 5 18 7 19 19 16 5 20 16 17 11 13 17 8 2 5 13 16 11 17 16 8 15 17 8 12 3 7 6 6 16 2 3 14 1 13 9 17 13 4 13 15 17 1 2 10 18 6 17 8 14 12 7 8 20 14 19 15 1 17 12 8 18 14 13 10 19 1 6 3 16 10 17 4 11 10 5 20 15 1 7 9 5 5 8 16 11 7 2 3 15 13 10 12 19 14 2 17 14 19 19 1 9 7 17 11 16 1 2 2 14 20 2 10 4 10 17 14 8 19 16 2 11 17 5 9 10 18 17 15 9 7 16 9 5 4 11 20 16 12 14 9 11 7 10 14 16 7 20 15 17 15 16 7 12 13 8 13 2 16 8 10 3 15 18 7 18 8 19 13 19 4 14 1 10 3 7 6 1 6 20 17 12 8 16 15 12 15 8 13 10 15 3 4 1 12 11 18 20 1 10 10 4 15 3 13 18 9 10 10 14 10 7 17 9 14 12 20 8 19 4 9 5 6 13 5 10 3 14 1 3 3 10 18 10 12 10 7 12 20 16 17 1 14 14 1 7 5 20 6 15 15 15 19 13 7 15 2 1 8 2 15 2 11 12 11 15 1 9 18 12 17 15 4 10 8 4 17 12 15 14 18 10 8 16 2 14 2 3 14 1 4 8 2 6 11 5 12 4 5 10 15 1 4 19 11 3 14 19 6 9 12 3 18 12 10 19 5 3 13 11 3 16 10 16 13 1 20 5 4 5 6 10 17 1 20 7 3 14 17 8 14 1 2 11 12 11 1 16 13 13 18 7 20 8 2 12 20 14 8 15 10 13 4 6 13 16 5 7 1 1 6 14 1 7 4 12 9 16 20 1 8 17 7 19 16 1 10 15 14 10 1 3 2 17 20 7 12 4 13 12 5 19 17 17 5 12 1 14 7 20 6 6 8 5 4 16 17 5 2 10 14 3 4 8 19 3 14 10 7 18 13 3 16 9 11 13 20 11 18 18 2 15 3 2 11 18 9 7 2 10 8 8 12 11 15 2 6 20 3 4 9 15 18 17 15 8 9 6 11 18 3 4 4 17 17 7 6 5 13 20 15 1 7 18 3 13 20 8 4 2 11 12 9 8 8 3 8 8 1 18 17 3 13 1 12 10 19 9 14 11 8 20 3 6 18 18 10 17 17 13 18 20 17 6 19 4 1 6 4 1 15 12 15 8 4 18 9 2 7 14 13 14 14 7 20 11 16 9 7 13 14 16 12 10 14 10 5 14 8 20 6 Heap Sort Elasped time is 0 Insertion Sort Elasped time is 0 heap Sorted List: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 insetion Sorted List: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20

7. If you look closely at the implementations for the sorting algorithms, you will note that there are two different manners in which the algorithms access the vector: comparisons and swaps. For example, insertion sort repeatedly traverses the vector, comparing eaclh data value with the smallest so far, and then swaps the smallest value into the correct position. When dealing with integer values, the cost of comparing and swapping are somewhat comparable. If the data to be compared/assigned is complex, however, the time required to swap values can far exceed the time required for comparisons. For example, if the vector contained long strings, you would expect the time required for swaps to be more significant Write a second main program that is similar to the first except that it sorts vectors of random strings. After prompting the user for the size of the vector, the program should generate random letter sequences of length 20 (although this length should be easily changeable) and sort them using Insertion sort and Heap sort. Perform repeated executions of your program to complete a table similar to the one in part 2. Which of the algorithms is most affected by increasing the size of the objects being sorted? Does this make sense when you consider the number of comparisons vs. swaps for each algorithm? Justify your answer. (20 points) 7. If you look closely at the implementations for the sorting algorithms, you will note that there are two different manners in which the algorithms access the vector: comparisons and swaps. For example, insertion sort repeatedly traverses the vector, comparing eaclh data value with the smallest so far, and then swaps the smallest value into the correct position. When dealing with integer values, the cost of comparing and swapping are somewhat comparable. If the data to be compared/assigned is complex, however, the time required to swap values can far exceed the time required for comparisons. For example, if the vector contained long strings, you would expect the time required for swaps to be more significant Write a second main program that is similar to the first except that it sorts vectors of random strings. After prompting the user for the size of the vector, the program should generate random letter sequences of length 20 (although this length should be easily changeable) and sort them using Insertion sort and Heap sort. Perform repeated executions of your program to complete a table similar to the one in part 2. Which of the algorithms is most affected by increasing the size of the objects being sorted? Does this make sense when you consider the number of comparisons vs. swaps for each algorithm? Justify your answer. (20 points)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!