8

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

2
  • 3
    Here is the source code for it - I think. csourcesearch.net/c/… Commented Nov 19, 2009 at 3:19
  • When you looked at the source, what did you learn? Commented Nov 19, 2009 at 3:51

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answers to all guys. Will check the merge sort now.
7

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.