when the input is nearly ordered to start with.ġ - For example, without making assumptions about the initial order of the input list.Ģ - A counting sort is O(n) but it doesn't rely on comparisons. How the algorithms perform in common use-cases e.g.Other overheads in the algorithms that are hidden if you just count comparisons.The other things to consider when predicting actual performance (as distinct from complexity) are: Note that these are not precise measures!īut the question of whether a "better than merge sort" algorithm exists boils down to how close "slightly smaller than (n lg n - n + 1)" is to lg (n!). In the worst case, the number of comparisons merge sort makes is equal to or slightly smaller than (n ⌈lg n⌉ - 2⌈lg n⌉ + 1), which is between (n lg n - n + 1) and (n lg n + n + O(lg n)) Adaptive, i.e., efficient for data sets that are already substantially sorted: the time complexity is O(kn) when each element in the input is no more than k. It depends on the precise implementation of merge-sort and the number of comparisons that it needs to do in the worst-case. There may be an algorithm that uses fewer comparisons than merge sort but still fits inside the theoretical bound. The theoretical lower bound is lg(n!) on the number of comparisons. Is it really true that there is no algorithms that uses half as many compares as does mergesort, in the worst case? It is certainly true that you cannot do general 1 compare-based 2 sorting in better than O(nlogn).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |