Last week, we analyzed different sorting methods
including quicksort, merge sort and the built-in sort called tim-sort compare
to selection sort and bubble sort learned in CSC108. In general, the best run
time is constant, followed by logarithmic and linear. Quadratic is faster at
the beginning than the best algorithm nlogn, but getting worse after a certain
number. The cases get worse when the power of n increase in the algorithm. In
all the runtime algorithm, O(nlogn) is the best algorithm which is mostly
applied in binary search tree, gives the least runtime except for constant.
After doing analysis with excel during the lab, I find out Tim-sort is the fastest one which always choose the optimal logarithm during calculation. Bubble sort is the least efficient one which grows in quadratic. The sorting methods rank as bubble, insertion, quicksort, merge sort and timsort from the slowest to the fastest.
Selection sort sorts the list starting from the beginning of the list and exchange the item with the smallest one in the list, that is to say, the algorithm has to loop over again and again to look for the smallest item each time of iteration, thus the worst case algorithm is O(n2); bubble sort bubbles the largest item to the end of the list during each loop, thus the worst case algorithm is O(n2) as well; quick sort chooses pivots to divide the looping into half, similar as the merge sort that recursively rank the two half of looping jobs, thus their worst case algorithms are O(nlogn).
The worst case and the average logarithm for both bubble sort and insertion sort are n2, thus they are worst sorting methods since n2 grows fastest; for quick sort, the average runtime is nlogn yet the worst case is n2 as well. Thus it grows slower at first, yet faster than n2, as the number of cases increase, it uses longer runtime and it grows faster. All the other cases have nlogn for both average and worst cases, thus they have a shorter run time by cutting all the running process into half. Even though Timsort has nlogn as worst algorithm as well, it will automatically choose the optimal algorithm to use, thus it is always the fastest one. Apart from that, Timsort applies n as memory, thus it is a stable and fastest way for sorting.
After doing analysis with excel during the lab, I find out Tim-sort is the fastest one which always choose the optimal logarithm during calculation. Bubble sort is the least efficient one which grows in quadratic. The sorting methods rank as bubble, insertion, quicksort, merge sort and timsort from the slowest to the fastest.
Selection sort sorts the list starting from the beginning of the list and exchange the item with the smallest one in the list, that is to say, the algorithm has to loop over again and again to look for the smallest item each time of iteration, thus the worst case algorithm is O(n2); bubble sort bubbles the largest item to the end of the list during each loop, thus the worst case algorithm is O(n2) as well; quick sort chooses pivots to divide the looping into half, similar as the merge sort that recursively rank the two half of looping jobs, thus their worst case algorithms are O(nlogn).
The worst case and the average logarithm for both bubble sort and insertion sort are n2, thus they are worst sorting methods since n2 grows fastest; for quick sort, the average runtime is nlogn yet the worst case is n2 as well. Thus it grows slower at first, yet faster than n2, as the number of cases increase, it uses longer runtime and it grows faster. All the other cases have nlogn for both average and worst cases, thus they have a shorter run time by cutting all the running process into half. Even though Timsort has nlogn as worst algorithm as well, it will automatically choose the optimal algorithm to use, thus it is always the fastest one. Apart from that, Timsort applies n as memory, thus it is a stable and fastest way for sorting.