Question: Program specification Write a c program that sorts an array of integers using the Bubble Sort, Selection Sort, and Insertion Sort. We will be sorting

Program specification 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 | ? Extra credit While this program can be implemented procedurally, earn up to 10 extra points by implementing a solution using OOP techniques. Supplemental information measuring elapsed system time The best way to measure elapsed system time for programs of this sort is to use the clock function, which is exported by the ctime interface. The clock function takes no arguments and returns the amount of time the CPU used in the execution of the program. The unit of measurement and even the type used to store the result of clock differ depending on the machine, but you can always convert the system dependent clock units into seconds by using the following expression: static_cast( clock() ) / CLOCKS_PER_SEC If you record the starting and finishing times in the variables start and finish, you can use the following code to compute the time required by a calculation: double start, finish, elapsed; start = static_cast( clock() ) / CLOCKS_PER_SEC; // perform some calculation finish = static_cast( clock() ) / CLOCKS_PER_SEC; elapsed = finish - start; Unfortunately, calculating the time requirements for a program that runs quickly requires some subtlety, because there is no guarantee that the system clock unit is precise enough to measure the elapsed time. For example, if you used this strategy to time the process of sorting 10 integers, the odds are good that the time value of elapsed at the end of the code fragment would be 0. The reason is that the CPU on most machines can execute many instructions in the space of a single clock tickalmost certainly enough to get the entire sorting process done for an array of 10 elements. Because the systems internal clock may not tick in the interim, the values recorded for start and finish may be the same. The best way to get around this problem is to repeat the calculation many times between the two calls to the clock function. For example, if you want to determine how long it takes to sort 10 numbers, you can perform the sort-10-numbers experiment 1000 times in a row and then divide the total elapsed time by 1000. This strategy gives you a timing measurement that is much more accurate

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!