Efficiency does not only streamline the process that the code is running under, it also encourages efficient thinking and planning before the actual implementation of the code. Efficiency may seem like an unnecessary concern at the moment in lower level courses with short functions, but when those functions are part of a much greater whole later on, it will become important to optimize everything. Sorting is a step towards efficient code, as like other concepts covered in CSC148 such as object oriented programming serving as a template for further development in code, sorting is a process to serve as preparation for other functions such as searching within the sorted object.
Bubble sort runs through the entire list in pairs and exchanges the position of the elements if the first element is greater than the second in the pair. It is inefficient as resources will need to be allotted for the exchange process. Selection sort is more efficient as it does not make any changes to the existing list during its run through and one exchange is made per run, making the runtime of the process predictable instead of dependent on the variables in the list. Insertion sort seems more complicated, but due to nothing being swapped, only shifted, the process runs well. Shell sort is strange, using insertion (once again as a template) to sort the elements in between specified gaps, pre-sorting to make the final sorting easier. Initially, I thought that merge sort required swapping during the combination, but it seems that the elements in both lists are combined and sorted into a new list and is more efficient as nothing is moving around. I feel that quicksort is similar to bubble sort in that its efficiency depends too much on the list and is thus unreliable while also being a little more complex to understand than merge sort. Timsort, while also dependent on the chance of order in the data itself, makes up for it by being adaptive in being able to make itself easier to sort using sorting methods and finding efficient merges instead of forcing the sort regardless of circumstance.
No comments:
Post a Comment