Sorting is the fundamental operation in computer science .
Choice of sorting algorithm depends on
- Number of items to be sorted
- Number of items already somewhat sorted
- Possible restrictions on item values like comparing operation
- Computer architecture like number of CPUs , IO speed , main memory , disk space
- Nature of computing multi-threaded or parallel distributed
- Stability of sort
- Is there need for extra space or in-place sort ?
- Is multi-algorithm sort optimization strategy needed ? example - if size of merge sort say below 30-40 then use insertion sort else use merge sort during divide phase of the algorithm .
- Ease of implementation. example - in-place merge sort implementation is theoretically possible but extremely difficult for practical purposes .
Comparison of algorithms
In practice best algorithm is heap sort because it is in-place and running time is on par with merge sort .
But biggest disadvantage of heap sort is it is not stable sort .
So when there is no requirement of stability use heap sort else use merge sort in combination with insertion sort (for size of 30-40 ) .
No comments:
Post a Comment