[Code in C] Help me with this. Not sure what to do.
![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 quicksort assume tha time, which one is larger and which one is smaller. They make no assumption on the values of the elements t 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] mes 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.](http://img.homeworklib.com/questions/49bb6a10-ffa8-11eb-9329-f7511e14ea59.png?x-oss-process=image/resize,w_560)

#include <stdio.h>
#include <stdlib.h>
void cntSort ( unsigned m , unsigned n, unsigned data[]){
unsigned *count = (unsigned *)malloc(m*sizeof(unsigned));
for(int i=0 ; i<n; ++i){
count[data[i]]++;
}
int p = 0;
for(int i=0 ; i<m; ++i){
for(int j=0 ; j<count[i]; ++j){
data[p++] = i;
}
}
free(count);
}
int main() {
unsigned data[10] = { 0,2,1,1,0,2,2,0,1,1};
int m = 3;
printf("UnSorted before Counting Sort: \n");
for(int i=0 ; i<10; ++i)
printf("%d ", data[i]);
cntSort(3, 10,data);
printf("\n\nSorted after Counting Sort: \n");
for(int i=0 ; i<10; ++i)
printf("%d ", data[i]);
return 0;
}
=========================
SEE OUTPUT
![main.c E saved #include <stdio.h> #include <stdlib.h> void cntSort ( unsigned m, unsigned n, unsigned data[]) { unsigned *cou](http://img.homeworklib.com/questions/6dc37ab0-ffa8-11eb-a69a-8b06c2e41bce.png?x-oss-process=image/resize,w_560)
Thanks, PLEASE COMMENT if there is any concern.
[Code in C] Help me with this. Not sure what to do. 1 Couting Sort You...
Exercise #2: Design and implement a program (name it SimpleSort) to implement and test the three sort algorithms (Bubble, Insertion, Selection) discussed in the lecture slides. Define method BubbleSort() to implement Bubble sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array. Define method InsertionSort() to implement insertion sort of an array of integers. Modify the algorithm implementation to count number of swaps it takes to sort the array. Define...
Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...
Implement quicksort and bucket sort. Use the code in your book to help; the partition in quicksort is tricky. Make sure your implementations are correct — it is easy to gain some confidence in the correctness of your code by writing a program which creates arrays filled with random numbers, sorts them, and then checks that they are sorted. Then time your code (using clock() or similar methods) on both methods for arrays filled with random integers of the following...
TO DO: IMPLEMENT SELECTION SORT, BUBBLE SORT, MERGE SORT INSTRUCTIONS: GENERATE AN ARRAY arr AND FILL IT WITH 100 RANDOM INTEGERS, HAVING VALUES 0-99. PRINT THE UNSORTED ARRAY IMPLEMENT EACH SORTING ALGORITHM (DO NOT USE THE BUILT-IN LIBRARIES) FOR EACH ALGORITHM, INCLUDE PSEUDOCODE WITH NUMBERED STEPS. IN YOUR CODE, CLEARLY COMMENT WHICH STEP IS BEING PERFORMED BY THE LINE OR BLOCK OF CODE. USE A TIMER TO CHECK HOW LONG EACH ALGORITHM TAKES TO SORT THE ARRAY. THIS SHOULD BE...
Java Question:
Code the Merge Sort in such a way that it outputs the number of
comparisons and the number of swaps performed when sorting a random
set of items. Then use it to sort 1000, 5000, 10,000, and 100,000
integers. Tabulate the results and compare it to the number of
comparisons and swaps calculated using the formulas given in Table
8.6.
Table 8.6 Performance of the Quicksort Algorithm Speed Memory Overhead Range Bytes lgorithm Range Effort Comments Binary Tree...
The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also please explain why the seg fault is happening. Thank you #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size;...
Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template of the solution, if you need Write a program that asks users to input 10 integers into an array, write a function that takes the array as its argument, use bubble sort to sort the array and output the sorted array in increasing order. #include <iostream> using namespace std; C:IWINDOWSSystems2cmd.exe lease input 10 integers: void bubblesort(int a[10]) int help; int b[10]; for (int i...
Please indicate whether the following statements are true or false by circling the correct answer: Every complete binary tree with n nodes has a height O(lg n). True False The array [19, 14, 17, 6, 8, 4, 11, 2, 5] forms a max-heap. True False O(3n + lg n) ≠ O(n) True False A comparison-based sorting algorithms cannot have an asymptotic run time of O(lg n) True False The recurrence relation that indicates the asymptotic running time...
sample bubble sort code:
;----------------------------------------------------------
BubbleSort PROC USES eax ecx esi,
pArray:PTR DWORD, ; pointer to array
Count:DWORD ; array size
;
; Sort an array of 32-bit signed integers in ascending
; order, using the bubble sort algorithm.
; Receives: pointer to array, array size
; Returns: nothing
;-----------------------------------------------------------
mov ecx,Count
dec ecx ; decrement count by 1
L1: push ecx ; save outer loop count
mov esi,pArray ; point to first value
L2: mov eax,[esi] ; get array...
In C++ language, implement a class that can sort an array of numbers using all three algorithms we have seen in this course, but each method updates a “counter” value every time it accesses the array. Have it print this at the end of the sorting process. Store the array values in an “original” array so you don’t have to re-type it for different sorts (since each sort alters the array), and have the sort modify a copy. Note: IF...