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

Programming: Programmatically generate three type of arrays (or vectors) of size

ID: 3836271 • Letter: P

Question

Programming: Programmatically generate three type of arrays (or vectors) of size 10,000: an array that is sorted in ascending order, a reversed array (an array that is sorted in descending order), and a random array.

·     Programmatically sort the three arrays using bubble sort, selection sort, insertion sort, shell sort, merge sort, and quick sort (the regular one and the improved one ) algorithms. For each sorting algorithm, calculate the number of exchanges (or shifts) and the number of comparisons for these sorting algorithms. Summarize the result in tables (see below).

·     Discuss whether your results match the big O of these algorithms.

Paragraph Comparing the number of comparisons Random Array Sorted Array Selection Sort Bubble Sort (improved Insertion Sort Shell Sort Merge Sort Quick Sort Quick Sort (Improved) Comparing the number of exchanges: Random Array Sorted Array Selection Sort Bubble Sort (improved) Insertion Sort (shifts) Shell Sort (shifts) Merge Sort (copies) Quick Sort Quick Sort (Improved) Styles Reversed Array Reversed Array Editin

Explanation / Answer

Bubble sort :

#include<stdio.h>

int main()

{

int arr1[10000] = {1,9,8,2,3,5,4,7,6,10,11,14,13,16,12,15,17,19,21,18,20},arr2[10000],i,j,k,count;

for(i = 0; i<10000 ; i++)

{

if(arr1[i] == '')

{

break;

}

count ++;

for(j = 0 ; j<i ; j++)

{

if(arr1[j] > arr1[j+1])

{

k = arr1[j+1];

arr1[j+1] = arr1[j];

arr1[j] = k;

}

}

}

printf("The sorted array using the bubble sort is : ===> ascending order <=== ");

for(i = 0; i<10000 ; i++)

{

if(arr1[i] == '')

{

break;

}

printf("%d ",arr1[i]);

}

printf(" The reversed array using the bubble sort is : ===> Descending order ");

for(i = 0; i<count ; i++)

{

if(arr1[i] == '')

{

break;

}

arr2[i] = arr1[count-1 - i];

printf("%d ",arr2[i]);

}

printf(" ");

return 0;

}

=============> Sample Output <=================

The sorted array using the bubble sort is : ===> ascending order <===
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

The reversed array using the bubble sort is : ===> Descending order
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1