This is our last slog entry and we are assigned to the topic of sorting algorithms and its efficiency. In our lecture, we were taught about 3 main sorts and they are the quick sort, merge sort and selection sort. I remember that lecture was particularly special, recalling that our professor Danny brought a stack of coffee cups and demonstrated the quick sort, merge sort and selection sort ideas. It was really interesting and the ideas behind were clearly demonstrated.
In terms of efficiency, quick sort is the fastest, and merge sort the second and finally selection sort is the worst. I found selection sort to be the sort that can be understand the easiest, it is to selection the smallest or largest one and put it into a new list, and then compare each and once again move it into the new created list and until the original list becomes empty. However, its procedure is way too slow and typically, our professor don't really recommend us using it.
Quick sort is to randomly pick a value (we call it pivot) from the list and take rest of the other values and compare them against with the pivot. Values that are greater than the pivot are put on the left and values that are less than the pivot are put on the right. Then we recursively sort the left and right (we call it divide and conquer). The idea of divide and conquer are used by merge sort as well.
Finally, the merge sort is that we pick a middle value, and divide lists into two equal length sublist and then to compare the first index of the left sublist with the first index of right sublist. If first index of left sublist is smaller than the first index of right sublist, then we move that value to a new list, if it isn't, then we move on to comparing the first index of left sublist with the first index of right sublist, and the smaller one is then append into the new list and this process goes on until we get a sorted new list.
没有评论:
发表评论