Details You've been given a scattered list of small monsters present in the Knightrola region. You need to evaluate six
Posted: Fri Jul 08, 2022 6:40 am
The Sorts Merge Sort In merge sort, you repeatedly sort and merge the smallest sublists of a list, working your way up to sorting and merging the entire list. You'll implement the basic recursive version, which works as follows: Merge sort: Recursive merge sort the entire list. Recursive merge sort: • If the size of the list is one, it's already sorted. • Otherwise: o Recursive merge sort the front half of the list and the back half of the list. o Merge the now-sorted front and back halves of the list. Merge adjacent sub-lists: • • Create a temporary list large enough to hold all the elements in both lists. Set a pointer to the first element in both lists, and to the first space in the temporary list. Iterate until you run out of elements in both lists: o Look at the current element in both lists. o Copy the smaller one into the temporary list. (If you're out of elements in one list, use the other.) o Increment the temporary list pointer, and the list pointer for the list you copied from. • Copy the temporary list back into the lists you were merging, writing over both. (If the lists you were merging were not adjacent, this will cause bad things to happen.) Insertion Sort In insertion sort, you divide the list into the elements you've already sorted and the elements you haven't yet, iterate over the elements you haven't yet, and insert them into the sorted sub-list. The basic array version, which you'll implement, works as follows: • Iterate i from the second to the last element of the list. i is always the first element you have not yet sorted. o Grab elementi. o Iterate j from the front of the list, until you either reach i or find an element with a value higher than element i. You are using / to look through your already-sorted list. o If you reached i, do nothing. Otherwise: • Move every element to the right (inclusive) of your final element j and to the left (exclusive) of element i right by one, "squashing" element i and creating an empty space before element j. Put your copied element i in the empty space. o Increment i and keep going.
Cleanup Specific Requirements • You do not need to comment line by line, but comment every function and every "paragraph" of code. • You don't have to hold to any particular indentation standard, but you must indent and you must do so consistently within your own code. You may not use global variables. Analysis, Reflection and Submission The only file I want is the template.c from monster-sorts-project. Rename it to cop3502-as3-<yourlname>- <yourfname>.c. For example, mine will be named cop3502-as3-gerber-matthew.c. Along with your C file, submit a short report in PDF format answering: • Did the results of your program confirm what you already knew or suspected about these sorting algorithms? How? • What differences did you see between and among the slow (bubble, selection, insertion) and fast (quick, merge, merge-insertion) algorithms?