In my opinion, sorting just is an algorithm that puts
items in a specified order. We saw a lot of sorting examples in
lecture, such as quick, select and merge.
And these sorting example can used in different place. I think sorting is very
useful because sometimes the sources is very mix up and sorting can help us to
sort the sources in order to manage these sources. Efficiency is kind of the
run-time about the algorithm, different sorting will have different efficiency.
Actually, there is always a question confused me, which is:
def merge_sort(L): """Produce copy of L in non-decreasing order >>> merge_sort([1, 5, 3, 4, 2]) [1, 2, 3, 4, 5] >>> L = list(range(20)) >>> shuffle(L) >>> merge_sort(L) == list(range(20)) True """ if len(L) < 2 : return L[:] else : return merge(merge_sort(L[:len(L)//2]), merge_sort(L[len(L)//2:]))
I always don't know how merge_sort works and in what situation we should use merge_sort in order to get the beet efficiency.