The selection sort method is dividing the list into two parts, a sorted part and a unsorted part. We choose the minimum of the unsorted part and added to the sorted part. The algorithm follows a O(n^2).
The quick sort method is choosing a pivot and place the items smaller than the pivot on the left side of the pivot and the items larger than the pivot on the right side of the pivot. This method belongs to O(nlgn).
The merge sort method is to use a function that merging two sorted list together into a single new sorted list in order to sort a list. This function belongs to O(nlogn)
By comparing their time complexity, merge sort is the most efficient sorting method and the selection sort method is the least efficient sorting method. In addition, both algorithms of selection sort and merge sort makes good sense to me but the I am having trouble understanding the algorithm for quick sort. To my understanding, in the recursed function, we make a list of the elements that are smaller than the pivot on the left side and a list of elements that are larger on the right, and we quick sort both lists until we get a sorted list.
No comments:
Post a Comment