encyclopegia.org

Interpolation sort

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: \text{Interpolation}(x) = \lfloor \frac{x - \text{min}}{\text{max} - \text{min}} \times (\text{ArraySize}-1)\rfloor where \text{min} and \text{max} are the minimum and maximum values within the array, and the floor function is used. This function returns an array index to where element x can be repositioned.

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: \text{Interpolation}(x) = \lfloor \frac{x - \text{min}}{\text{max} - \text{min}} \times (\text{ArraySize}-1)\rfloor where \text{min} and \text{max} are the minimum and maximum values within the array, and the floor function is used. This function returns an array index to where element x can be repositioned. ==Algorithm== Interpolation sort uses an array of record bucket lengths corresponding to the original number column. The array prevents the space complexity from becoming O(n^ 2) 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 O(3n) . 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 O(n + k) . 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, O(n) . ===Histogram sort algorithm=== NIST describes the histogram sort as an efficient 3-pass refinement of a bucket sort algorithm. The first pass counts the number of items for each bucket in an auxiliary array, and then makes a running total so each auxiliary entry is the number of preceding items. The second pass puts each item in its proper bucket according to the auxiliary entry for the key of that item. The last pass sorts each bucket. ==Practice== ===Interpolation sort implementation=== JavaScript code: Array.prototype.interpolationSort = function() { var divideSize = new Array(); var end = this.length; divideSize[0] = end; while (divideSize.length > 0) { divide(this); } // Repeat function divide to ArrayList function divide(A) { var size = divideSize.pop(); var start = end - size; var min = A[start]; var max = A[start]; for (var i = start + 1; i max) { max = A[i]; } } } if (min == max) { end = end - size; } else { var p = 0; var bucket = new Array(size); for (var i = 0; i 0) { for (var j = 0; j ===Interpolation sort recursive method=== Worst-case space complexity: O(n^2) Array.prototype.interpolationSort= function() {//-- Edit date:2019/08/31 --// var start = 0; var size = this.length; var min = this[0]; var max = this[0]; for (var i = 1; i max) { max = this[i];} } } if (min != max) { var bucket = new Array(size); for (var i = 0; i 1) { bucket[i].interpolationSort(); } // Recursion for (var j = 0; j ===Histogram sort implementation=== Array.prototype.histogramSort = function() {//-- Edit date:2019/11/14 --// var end = this.length; var sortedArray = new Array(end); var interpolation = new Array(end); var hitCount = new Array(end); var divideSize = new Array(); divideSize[0] = end; while (divideSize.length > 0) { distribute(this); } // Repeat function distribute to Array function distribute(A) { var size = divideSize.pop(); var start = end - size; var min = A[start]; var max = A[start]; for (var i = start + 1; i max) { max = A[i]; } } } if (min == max) { end = end - size; } else { for (var i = start; i 0) { divideSize.push(hitCount[i]); } } hitCount[end-1] = end - hitCount[end-1]; for (var i = end-1; i > start; i--) { hitCount[i-1] = hitCount[i] - hitCount[i-1]; } for (var i = start; i ==Variants== ===Interpolation tag sort=== 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 2n+(n) 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 O(n) 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 O(n \ log \ n) . Interpolation tag sort average performance complexity is O(n + k) . ====Interpolation tag sort algorithm==== Set a tag array equal to the original array size and initialize to a false value. [Main Sort] Determines whether all buckets of the original array have been sorted. If the sorting is not completed, the [Divide function] is executed. [Divide function] Find the maximum and minimum values in the bucket. If the maximum value is equal to the minimum value, the sorting is completed and the division is stopped. Set up a two-dimensional array as all the empty buckets. Divide into the bucket according to the interpolation number. After dividing into the bucket, mark the starting position of the bucket as a true value in the tag array. And put the items back into the original array one by one from all the buckets that are not empty. Return to [Main Sort]. ====Practice==== JavaScript code: Array.prototype.InterpolaionTagSort = function() {// Whale Chen agrees to "Wikipedia CC BY-SA 3.0 License". Sign date: 2019-06-21 // var end = this.length; if (end > 1) { var start = 0 ; var Tag = new Array(end); // Algorithm step-1 for (var i = 0; i 1) { // Algorithm step-2 while (Tag[--start] == false) { } // Find the next bucket's start Divide(this); } function Divide(A) { var min = A[start]; var max = A[start]; for (var i = start + 1; i max) { max = A[i]; } } } if ( min == max) { end = start; } // Algorithm step-3 Start to be the next bucket's end else { var interpolation = 0; var size = end - start; var Bucket = new Array( size ); // Algorithm step-4 for (var i = 0; i 0) { // Algorithm step-5 Tag[start] = true; for (var j = 0; j ===In-place interpolation tag sort=== 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: O(n) , the calculation time complexity is: O(n) , and the worst space complexity is O(n) 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: Set an equal number of tag arrays to initialize to false values. Visit the array when tag[i] is false, calculate the position corresponding to the interpolation=p. Swap a[i] and a[p], let tag[p] = true. The tour array is completed and the sorting is completed. ====Practice==== JavaScript code: Array.prototype.InPlaceTagSort = function() { // Edit Date: 2019-07-02 var n = this.length; var Tag = new Array(n); for (i = 0; i max) { max = this[i]; } } } var p = 0; var temp = 0; for (i = 0; i ====Performance==== 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 O(n) time if we would be allowed to manipulate n 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 n\log n steps on the average." The in-place interpolation tag sort is one of the sorting algorithms that prof. Donald Knuth said: "manipulate n extra "tag" bits...finding the cycle leaders, and in-situ permutations could easily be performed in O(n) time". ==Mixed sorting methods== 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 O(n^2) . 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 O(n^2) , 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. ==See also== Flashsort Proxmap sort American flag sort ==References== ==External links== interpolationSort.html histogramSort.html The FlashSort Algorithm Mathematical Analysis of Algorithms http://www.drdobbs.com/database/the-flashsort1-algorithm/184410496 桶排序遞迴方式演算法 Bucket sort Recursive method. Whale Chen 2012/09/16 插值標簽排序演算法 Interpolation Tag Sort Algorithm. Whale Chen 2013/03/24 interpolation sort (Pascal version available) w3schools JavaScript Array Sort testing platform

References

No reference rows published for this article.

Cite this article

MLA

"Interpolation sort." encyclopegia.org, 2026, https://encyclopegia.org/wiki/interpolation-sort. Accessed 24 November 2026.

Chicago

"Interpolation sort." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/interpolation-sort.

APA

encyclopegia.org. (2026). Interpolation sort. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/interpolation-sort

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Bessel interpolation formula

stub · references available

interpolation

stub · references available

Whittaker–Shannon interpolation formula

stub · references available

adaptive heap sort

stub · references available

Barnes interpolation

stub · references available

Interpolation theory

stub · references available

Interpolation theorem

stub · references available

Not That Sort of Girl

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1359732330 · 0.5 · snapshot enwiki-001359732330

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.