This is an old revision of the document!
Corning Community College
CSCS2330 Discrete Structures
Using the TIC-80 fantasy console simulator on your pi, implement a program that performs a sorting of a randomized list of values, both displaying an animation of the sort, along with timing and keeping track of the approximate number of steps needed to accomplish the task for variable numbers of non-animated runtimes.
The sorting algorithms I'd like for you to produce is that of:
You may want to look up the specifics on these algorithms to understand what their approach is, then to implement it.
Additionally, the entire class will be participating in documenting and filling out this project page. It is the responsibility of EACH class member to:
The Process of the Cocktail Sort is similar to that of the Bubble Sort, but with a bit of added efficiency and fun. The first passthrough is identical to that of a Bubble Sort, comparing adjacent numbers and pushing the greater one up in the list.
Once we get to the second passthrough, things change a bit from the Bubble Sort's process. This time we descend the list, disregarding the last element, seeing as the greatest list element should be in this position already. This passthrough will compare adjacent values and move the lesser value towards the start of the list, until the least value is placed at the beginning.
Once again, we ascend the list, disregarding the sorted element(s) and repeat this process until the sorted portions of the top and bottom of the list meet in the middle, resulting in a fully sorted list.
A morbidly memory inefficient algorithm, the index sort was a sudden idea that popped into my head as I was about to implement a different sort of my choice, but then this custom one quickly won me over. The use case of this sort is one where the desired output represents the full range of represented values ordered, but not repeats. This way, only the appearing numbers are sorted, but the full wealth of dataset information is more easily compartmentalized (that makes it sound like a feature, right?).
This sort accepts a dataset as input, and creates a secondary array with a size equal to that of the largest value in the dataset minus one. Then, it loops over the original dataset, placing each value at its own index minus one. Next, it will remove any “holes” in the secondary array, meaning it will be narrowed down to only values - no empty indices. To finish sorting, it simply writes over the original array with the secondary array.
Here is a modified implementation example:
index(int[] dataset) { // Allocate subset subArr[dataset.getLargest()-1]; // Populate subset for (i=0;i<dataset.size;i++) { val = dataset.get(i); subArr[val-1] = val; } // Rewrite original array dataset.clear(); for (i=0;subset.size > 0;i++) { num = subArr[0]; if (num != NULL) { dataset[i] = num; } else { i--; } subArr.removeFirst(); } }
And an output example:
Dataset IN: { 1, 5, 6, 8, 3, 3, 0, 1, 9 } Subarray: { 0, 1, , 3, , 5, 6, , 8, 9 } Dataset OUT: { 0, 1, 3, 5, 6, 8, 9 }
As can be seen based on the fact that the subarray outsizes the ingoing dataset in the example, as dataset values become larger, this approach becomes infinitely less useful, but is actually very, very fast in smaller, more controlled applications like mine, where the dataset simply contains a no-repeat set of values from 1-datasetSize, as it only needs to perform 1 read and 2 write operations per datapoint regardless of position or value.
I'll be looking for the following:
78:saf2:final tally of results (78/78) *:saf2:no errors, program runs without issue in TIC-80 [13/13] *:saf2:specified algorithms are implemented and functional [39/39] *:saf2:metrics, timing of process is implemented, functional, shown [13/13] *:saf2:project page contributions as per project specifications [13/13]
Additionally: