As per MSDN doc for Array.Sort
,
If the number of partitions exceeds 2 * logN, where N is the range of the input array, it uses a Heapsort algorithm.
What I don't know is what are the "number of partitions" and the "range" of an array. What are they?
You have a large, potentially huge array of objects, in a random order. You want to split the array in two parts: the lower half with objects matching the condition, the upper half with objects not matching the condition. This operation is called the partitioning of an array.
There are two ways to partition the array: - For pivot = 1, we have the partition [0 | 0,0]: 0 == 0 + 0. - For pivot = 2, we have the partition [0,0 | 0]: 0 + 0 == 0.
An array is a collection of similar data elements stored at contiguous memory locations. It is the simplest data structure where each data element can be accessed directly by only using its index number.
A partition in a sort is basically a section of the list based upon a pivot point. For example, using the quick sort algorithm to sort the following:
First Pass Second Pass
3 3 1
8 1 3
5 <- Pivot 5--------- 5
1 8 7
7 7 8
In the first pass, there are two partitions based off numbers that are less than or greater than 5
The range is the difference between the largest and smallest values, so in this example that is 7 (8 - 1)
So the line you are questioning works as
(2 * log(7)) > 2 == Use HeapSort
1.691 > 2 false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With