Interpolation sort (or histogram sort) is a sorting algorithm that uses an interpolation formula to divide and conquer. It is a variant of bucket sort. Data is assigned to buckets using an interpolation function:where and are the minimum and maximum values within the array, and the floor function is used. This function returns an array index to where element can be repositioned.
Interpolation sort uses an array of record bucket lengths corresponding to the original number column. The array prevents the space complexity from becoming due to memory stacking. The segmentation record of the length array can using secondary function dynamically declare and delete the memory space of the array. The space complexity required to control the recursive program is . Contains a two-dimensional array of dynamically allocated memories and an array of record lengths. However the execution complexity can still be maintained as an efficient sorting method of .
The array of dynamically allocated memory can be implemented using an array object (such as in JavaScript) or more basically via a linked list, stack, queue, associative array, or tree structure. The type of data structure affects the speed of data access and thus the sorting time. When the values in the ordered array are uniformly distributed in an arithmetic progression, the order of interpolation sort is linear time, .
NIST describes the histogram sort as an efficient 3-pass refinement of a bucket sort algorithm.
JavaScript code:
Worst-case space complexity:
Interpolation tag sort is a recursive variant of interpolation sort. After the array data is distributed into buckets via an interpolation function, each bucket recursively runs the original algorithm until the sorting is completed.
To avoid stack overflow caused by recursion, use a Boolean data type tag array to operate the recursive function to release the memory. The extra memory space required is close to bits. Contains a two-dimensional array of dynamically allocated memory and a Boolean data type tag array. Buckets can be implemented using a stack, queue, associative array, or tree structure.
Like interpolation sort, interpolation tag sort runs in linear time when the values in the array to be sorted are evenly distributed. The bucket sort algorithm does not limit the sorting to the lower limit of . Interpolation tag sort average performance complexity is .
JavaScript code:
In-place interpolation tag sort is an in-place algorithm variant of interpolation sort. It sorts non-repeating consecutive integer series. It can achieve sorting by only N times of swapping by maintaining N bit tags, saving time and memory space. However, the array to be sorted must be either a continuous integer sequence or a non-repeating arithmetical progression.
The factor column data must not be repeated. For example, sorting 0~100 can be sorted in one pass. The number of exchanges is: , the calculation time complexity is: , and the worst space complexity is bits.
This algorithm only uses one additional tag array. This tag array has the same length as the original array and is of Boolean data type. For each unswapped element, the algorithm calculates a new interpolated position p and swaps the two elements in the array. The tag array is marked true at position p, and the algorithm is incremented until it reaches the last element, at which point the array is sorted.
Algorithm process:
JavaScript code:
In "Mathematical Analysis of Algorithms", Donald Knuth remarked "... that research on computational complexity is an interesting way to sharpen our tools for more routine problems we face from day to day."
Knuth further pointed out that, with respect to the sorting problem, time effective in-situ permutation is inherently connected with the problem of finding the cycle leaders, and in-situ permutations could easily be performed in time if we would be allowed to manipulate extra "tag" bits specifying how much of the permutation has been carried out at any time. Without such tag bits, he concludes "it seems reasonable to conjecture that every algorithm will require for in-situ permutation at least steps on the average."
The in-place interpolation tag sort is one of the sorting algorithms that prof. Donald Knuth said: "manipulate extra "tag" bits...finding the cycle leaders, and in-situ permutations could easily be performed in time".
Bucket sort is limited in some situations. For example, consider a case where the maximum data value is greater than N times the next largest value. After processing, all elements except the maximum value fall into the same bucket; a poor distribution. The second sorting pass using e.g. insert sort may cause execution complexity to fall into . This loses the benefits and high-speed performance of using bucket sort.
Interpolation sort is a way of recursively using bucket sort. After performing recursion, still use bucket sort to disperse the series. This can avoid the above situation. If you want to make the recursive interpolation sort execution complexity fall into , it is necessary to present a factorial amplification in the entire series. In fact, there is very little chance that a series of special distributions will occur.