Sunday, November 10, 2013

Sorting

For a big amount of data we prefer to use the binary search technique instead of the linear search. However, the binary search requires the search pool to be sorted. The need of a sorted collection of objects led to the development of various sorting algorithms. Some of the sorting techniques (that I know) are: bubble sort, insertion sort, selection sort, merge sort, quicksort and heapsort. Among those, bubble, insertion and selection sorts are less efficient (on average) and perform with O(n2). The rest can sort the elements with the complexity of O(nlogn). However, when given particular types of inputs to be sorted or in the best case, some less efficient algorithms become more efficient (bubble sort and insertion sort have O(n)). The same refers to more efficient algorithms when given the worst case. For example, the quicksort for the worst input will do the job with O(n2). This is why Python developers for example use a combination of different sorts when implementing the built in sort() method.

No comments:

Post a Comment