Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "number of partitions" and "range" of an array?

Tags:

arrays

sorting

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?

like image 733
Ron5504 Avatar asked Aug 12 '13 07:08

Ron5504


People also ask

What is an array partition?

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.

How many ways can you partition 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.

What is array in simple language?

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.


1 Answers

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
like image 153
Sayse Avatar answered Oct 07 '22 18:10

Sayse