Thursday, 27 March 2014

Sorting and Efficiency

    In week 9, lectrues were about sorting algorithm. In lab 10 , different sorting method run for sorting already sorted list, random list and sorted but reversed list.
    The method includes: selection sort, insertion sort, bubble sort, merge sort, quick sort and bulit_in sort.
    After running sort.py, the result for speed of each sort was clear to be seem from time they used. Built_in sort, which is also called tim_sort, is the fastest. Contradictory, three former sorts that learnt from csc108 are slowest.
    By viewing the code, three slowest sorts have common strategies, they go over the list during each single element sorting. It obviously decreases the speed of finishing sorting the whole list. However, some other sorts use some method like cut the list into two parts and sort in just one part, after all the times of sorting will only be lgn, where n is the length of list.
    There is also a way to improve the efficiency of tranditional sorting method like selection sorts or bubble sorts. It is adding a swap step between sorting each element.
    Still, I don't know the principle of bulit_in sort algorithm.

No comments:

Post a Comment