Question: Write a C program that sorts an array of integers using the Bubble Sort, Selection Sort, and Insertion Sort. We will be sorting increasingly larger
Write a C program that sorts an array of integers using the Bubble Sort, Selection Sort, and Insertion Sort. We will be sorting increasingly larger sets of integers, e.g., N = 10, 100, 1000, 10000, and 100000. To do this efficiently, create a single integer array large enough to hold the largest N, e.g. const int MAX = 100000; int array[MAX]; We will first utilize 10 elements of this array, then 100, then 1000, and ultimately the entire array when testing our sorting algorithms. Using a function, initialize an array with random integers. It is important that your function fill the array with the same set of random numbers with each call so that you can correctly compare the various sorting algorithms. You can ensure this by reseeding the random number generator each time you fill the array by using a constant value, e.g, srand(0). Your function should accept as parameters the integer array and the number of elements using the following prototype: void random_array_fill( int array[], int size ); Sort the array using each of the sorting algorithms (Bubble, Selection, and Insertion). Report the time taken to sort the array using each of the sorting algorithms. You must remember to reinitialize the array between sorts using your random_array_fill function, otherwise you will be sorting an array that is already in order! Sample output Generate a report of sorting times as shown below for each sorting algorithm: Bubble Sort N | Time (sec) -------------------- 10 | 0.54 100 | 6.90 1000 | ? 10000 | ? 100000 | ?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
