Question: Part 1 : O ( n 2 ) sort Pick a ) sorting algorithm ( bubble , insertion, or selection ) and implement it in
Part : sort
Pick a sorting algorithm bubble insertion, or selection and implement it in a C program to sort an array
of integers. There is C code in the textbook and online for these algorithms, but I encourage you to resist the
temptation to simply copy it Add a counter to the sort function to track the number of times that the function
accesses elements from the array you are sorting. For example, if your function has the line arrayi max that
counts as one array access. If your function has the line if arrayi array that counts as two array
accesses.
Part : sort
Do the same thing as part but with a On log n algorithm merge sort or quick sort
Part : Counting sort
Do the same thing as part but with the counting sort, as described here.
The counting sort can sort an array of integers that are known to be in a given range of integers by using a
second array count to count the number of occurrences of each integer in the array.
As an example, let's say we have an array called scores containing the following ten integers in the range
between and inclusive:
scores :
In this case, the count array would have five elements, one for each possible value through We initialize
count to all zeros. We then make one pass through scores each time we see a given value in scores, we
increment the value in count When we are done, count will tell us how many instances of the value we
have in scores. In this example, count would be:
because there are zeros, one, twos, threes, fours in scores.
Once you have this array count, it is straightforward to determine the sorted scores array:
sc
and store it back into the original array.
Write a function that implements the counting sort, assuming an array of integers that are in the range to
inclusive.
In big O notation, what is the expected efficiency? Why is counting sort impractical as a general sorting
algorithm?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
