When I first heard that we were doing sorting, my initial impression was: “sorting… again? Aww man”. However, my initial impression, like most things in this course, was soon proven very wrong. When Professor Heap started using words like big-Oh, sorting, and measuring times. Then all of a sudden there was recursion and playing cards using keys and I was quickly lost. So, as per usual, I started procrastinating until I had to write a slog about it. As such, I sat down and started to learn about sorting and efficiency. Sorting is done by algorithms. Each sorting algorithm can be compared based on its time performance in regards to the to the size of the input, usually called “n”. To determine the time performance, you compare the best time performance case versus the worst. If the algorithm is directly related to the size of the input it is called O(n). The most efficient algorithm is O(logn) since it’s time performance is based on half of the size of n. The largest and worst time performance is O(nn) because when n is increased it is proportional to n to the power of n, increasing the time required significantly which is higher than other sorting functions.
Of the algorithms we learned about, half were review and half were new. Bubble sort, selection sort, and insertion sort were all review from CSC108. Each of the 3 different algorithms had the time performance of O(n2). This is due to the fact that everytime it runs through, each algorithm has to make n-1 comparisons and then exchange and shift values to sort through each list. As a result, in the worst case scenario (and in the best) they run in a quadratic time performance.
Merge sort, quick sort and list.sort() were all new algorithms we learned his semester. Each of these algorithms had the time performance of O(nlogn). This is due to splitting the list into halves until the list is either made up of one item or none. Then each individual piece is put back together until the list becomes sorted. As such, it splits the list logn times. However since the list size is n the resulting time is O(nlogn).