Tuesday, May 24, 2016

Selection of algorithm for sorting


Sorting is the fundamental operation in computer science .

Choice of sorting algorithm depends on

  1. Number of items to be sorted
  2. Number of items already somewhat sorted
  3. Possible restrictions on item values like comparing operation
  4. Computer architecture like number of CPUs , IO speed , main memory , disk space
  5. Nature of computing multi-threaded or parallel distributed
  6. Stability of sort
  7. Is there need for extra space or  in-place sort ?
  8. 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 .
  9. 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: