Which sorting algorithm is used by .NET's Array.Sort() method?

Array.Sort() chooses one of three sorting algorithm, depending on the size of the input:

  1. If the size is fewer than 16 elements, it uses an insertion sort algorithm.
  2. If the size exceeds 2 * log^N, where N is the range of the input array, it uses a Heap Sort algorithm.
  3. Otherwise, it uses a Quicksort algorithm

Source: Array.Sort(Array) Method on MSDN.


Actually, It's not that easy as it's seems. It looks like .NET is implementing a set of different sorting algorithms depending on the input and his size. I used to decompile Array.Sort() from CLR and it seems that they are using both Heap, Insertion and Quicksort. enter image description here


It uses the QuickSort algorithm.

Source:

  • Array.Sort Method (MSDN, Remarks section)