Sorting Algorithms

2017-02-09

three different algorithms used to sort the bars into ascending order. ‘Bubble Sort’ works by comparing two elements and if the second is larger than the first they swap places. However, this algorithm's average time complexity is O(n^2) meaning that it is pretty useless for sorting big datasets. A much betters choice is the ‘Quick Sort’ algorithm, which has an average time complexity of O(n log n) and works by partitioning an array around a pivot, moving bigger elements than the pivot to the right partition while moving smaller elements than the pivot to the left partition, repeating the process until sorted. Finally ‘Bozo Sort’ works by swapping two elements at random until the array is sorted. Unsurprisingly this is a terrible way to sort a list and Bozo Sort has an average time complexity of O(n!). If we are going to sort things using this method then we might as well put a monkey in front of a typewriter with hopes of the ape producing the two final game of thrones novels before George R. R. Martin. Then again, this might not be such a bad idea.