tags:

views:

195

answers:

2

Hello,

I would like to know which sorting algorithm the linux SORT command uses?

+5  A: 

mergesort

It1 uses mergesort rather than quicksort or heapsort for two reasons:

  • mergesort is a stable sort and typically the efficient quicksort implementations are not
  • while it may do more swaps or moves it does fewer comparisons and so tends to work better with text input


1. Linux distros are free to choose their own sort utility but I imagine virtually all use GNU sort so I have described that.

DigitalRoss
Thanks for the answers to all guys.Will check the merge sort now.
Vineeth
+3  A: 

An External R-Way merge sort according to Algorithm details of UNIX Sort Command. Found via this stackoverflow question.

Jonathan