Vineeth
Vineeth

Reputation: 131

Linux Sort command

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

Upvotes: 8

Views: 6554

Answers (2)

DigitalRoss
DigitalRoss

Reputation: 146221

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.

Upvotes: 11

Jonathan
Jonathan

Reputation: 1731

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

Upvotes: 7

Related Questions