Saturday, March 29, 2014

Sort and efficiency

I think the most interesting for me is to find out how fast the python built-in sort is.I know that it may be unfair to compare it, which is written in c, with other sorts that written in python, but it actually runs ten time faster than the other sorts tested in this week's sort. So I did some wiki and find out that the built-in sort is actually Tim sort, which is used not only in python but also Java and Android platform.

Here is a good explain about Tim sort, and I found this 'sound of sorts' quite amazing:


Although in the worst case, the time would be O(nlogn), just like the other sorts, but because this sort can take advantage of the sorted part of the original list, in real world near-sorted cases it can be much better.

But compare to Quicksort, it occupies more memory space(O(logn) to O(n))and may be slower on average. What's more, Quicksort is really simple to write and understand, while Timsort, which is a hybrid sorting algorithm, is not that easy and clear.

No comments:

Post a Comment