Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Code in C] Counting Sort. First 2 image is about main.c and the last image is the code I have to work on. Please try

[Code in C] Counting Sort.

First 2 image is about main.c

and the last image is the code I have to work on.

Please try not to change the whole format.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

icc -ansi -Wall main.c cntSort.c -o cntSort /cntSort -m 64 -n 1048576 -s 2018 The m, n, and s are optional command line arg Make sure your C code follows the style guidelines. In the "notes" and "pseudo code" section of the comment at the top of your files, you should write pseudo code and discuss what you found difficult about this assignment, completing it how you planned your approach to it, and what you learned 1 Couting Sort You may have learned some sorting algorithms - such as bubble sort ad quicksort in CS 110 and CS 210. This homework is about counting sort. Let n be the number of elements to be sorted Bubble sort and quicksor time, which one is larger and which one is smaller. They make no assumption on the values of the elements t assume that we can compare any pair of elements and find out, in constant Counting sort assumes the elements are integers between 0 and m, and m is much smaller than n. For example, let m be 3, and n be 10. Then the elements can be 0, 1. or 2, and we have ten of them. unsigned data[10]-0, 2, 1, 1, 0, 2, 2, 0, 1, 1}; unsigned count [3]; Counting sort uses an array unsigned count [m] and initializes all elements in count to zero. Then we scan the array data. When we see a number data[i], this number is used as the index to the array count, and the corresponding count is incremented. After we finish scanning the array data, we have count [0]-3. count [1]-4, and count [2] == 3. How do we construct the sorted array from these counts? We write 0 for count [0] times, 1 for count [1] times, and 2 for count [2] times Bubble sort takes O(n2) time in the worst case, and quicksort takes O(nlgn) time on average Loosely speaking, quicksort is faster than bubble sort. You will learn the big-O notation in CS 310 Counting sort takes O(m+n) time. We say it is a linear time algorithm, which is, loosely speaking faster than quicksort The code in main.c is the driver. You implement counting sort in cntSort.c. The driver runs your counting sort as well as qsort in the standard library. It verifies that your code works correctly, and reports the runtime of both sorting methods

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago