A collection of sorting functions.

Namespace: Imsl.Stat
Assembly: ImslCS (in ImslCS.dll) Version: 6.5.0.0

Syntax

C#
[SerializableAttribute]
public class Sort
Visual Basic (Declaration)
<SerializableAttribute> _
Public Class Sort
Visual C++
[SerializableAttribute]
public ref class Sort

Remarks

Class Sort contains ascending and descending methods for sorting elements of an array or a matrix.

The QuickSort algorithm is used, except for short sequences which are handled using an insertion sort.

The QuickSort algorithm is a randomized QuickSort with 3-way partitioning. Basic QuickSort is slow if the sequence to be sorted contains many duplicate keys. The 3-way partitioning algorithm elimiates this problem. The pivot is chosen as the middle element of three potential pivots chosen at random.

The matrix ascending method sorts the rows of real matrix x using a particular row in x as the keys. The sort is algebraic with the first key as the most significant, the second key as the next most significant, etc. When x is sorted in ascending order, the resulting sorted array is such that the following is true:

  • For i = 0, 1, \ldots, {\rm n\_observations} - 2, {\rm x} [i]
            [{\rm indices\_keys} \,\,[0]] \leq {\rm x}[i + 1] [{\rm indices\_keys}
            [0]]
  • For k = 1, \ldots, {\rm n\_keys - 1, if\,\, x [i]
            [{\rm indices\_keys} [j]] = x [i + 1] [{\rm indices\_keys} [j]]} for j = 0, 1, \ldots, k - 1, then {\rm x} [i] [{\rm indices\_keys} [k]] = {\rm x} [i + 1]
            [{\rm indices\_keys} [k]]

The observations also can be sorted in descending order. The rows of x containing the missing value code NaN in at least one of the specified columns are considered as an additional group. These rows are moved to the end of the sorted x.

If all of the sort keys in a pair of rows are equal then the rows keep their original relative order.

The sorting algorithm is based on a quicksort method given by Singleton (1969) with modifications, see Bentley and Sedgewick (1997).

Inheritance Hierarchy

System..::.Object
Imsl.Stat..::.Sort

See Also