Interpolation Sort
   HOME

TheInfoList



OR:

Interpolation sort is a kind of bucket sort. It uses an interpolation formula to assign data to the bucket. A general interpolation formula is: Interpolation = INT(((Array - min) / (max - min)) * (ArraySize - 1))


Algorithm

Interpolation sort (or histogram sort). It is a sorting algorithm that uses the
interpolation In the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing (finding) new data points based on the range of a discrete set of known data points. In engineering and science, one often has a n ...
formula to disperse data divide and conquer. Interpolation sort is also a variant of
bucket sort Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the b ...
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
. The interpolation sort method uses an array of record bucket lengths corresponding to the original number column. By operating the maintenance length array, the
recursive Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
algorithm can be prevented from changing the space complexity to 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 An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
. 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).
Array An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
of dynamically allocated memory can be implemented by
linked list In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes whic ...
,
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
,
queue __NOTOC__ Queue () may refer to: * Queue area, or queue, a line or area where people wait for goods or services Arts, entertainment, and media *''ACM Queue'', a computer magazine * The Queue (Sorokin novel), ''The Queue'' (Sorokin novel), a 198 ...
,
associative array In computer science, an associative array, map, symbol table, or dictionary is an abstract data type that stores a collection of (key, value) pairs, such that each possible key appears at most once in the collection. In mathematical terms an as ...
,
tree structure A tree structure, tree diagram, or tree model is a way of representing the hierarchical nature of a structure in a graphical form. It is named a "tree structure" because the classic representation resembles a tree, although the chart is gener ...
, etc. An array object such as
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
is applicable. The difference in
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, a ...
is related to the speed of data access and thus the time required for
sorting Sorting refers to ordering data in an increasing or decreasing manner according to some linear relationship among the data items. # ordering: arranging items in a sequence ordered by some criterion; # categorizing: grouping items with similar pro ...
.When the values in the ordered array are uniformly distributed approximately the
arithmetic progression An arithmetic progression or arithmetic sequence () is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression with a common differ ...
, the linear time of interpolation sort ordering is O(n).


Interpolation sort algorithm

#Set a bucket length array to record the length of the unsorted bucket. Initialize into the original array length. #
ain Sort Ain (, ; frp, En) is a department in the Auvergne-Rhône-Alpes region in Eastern France. Named after the Ain river, it is bordered by the Saône and Rhône rivers. Ain is located on the country's eastern edge, on the Swiss border, where i ...
If the bucket length array is cleared and sorted is completed. Execute ivide functionif it is not cleared. # ivide functionExecute Divide by pop a bucket length from the end of the bucket length array. Find the maximum and minimum values in the bucket. If the maximum value is equal to the minimum value, the sorting is completed to stop Divide. #Set up a two-dimensional array as all empty buckets. Divide into the bucket according to the interpolation number. #After dividing into the buckets, push the length of the buckets into the array of bucket length. And put the items back into the original array one by one from all the buckets that are not empty. #Return to
ain Sort Ain (, ; frp, En) is a department in the Auvergne-Rhône-Alpes region in Eastern France. Named after the Ain river, it is bordered by the Saône and Rhône rivers. Ain is located on the country's eastern edge, on the Swiss border, where i ...


Histogram sort algorithm

The NIST definition: 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() ;


Interpolation sort recursive method

Worst-case space complexity : O(n^2) Array.prototype.interpolationSort= function() ;


Histogram sort implementation

Array.prototype.histogramSort = function() ;


Variant


Interpolation tag sort

Interpolation Tag Sort is a variant of Interpolation Sort. Applying the bucket sorting and dividing method, the array data is distributed into a limited number of buckets by mathematical interpolation formula, and the bucket then
recursively Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
the original processing program until the sorting is completed. Interpolation tag sort is a recursive sorting method for interpolation sorting. To avoid stacking overflow caused by recursion, the memory crashes. Instead, 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. Stack, queue, associative array, and tree structure can be implemented as buckets. As the JavaScript array object is suitable for this sorting method, the difference in data structure is related to the speed of data access and thus the time required for sorting. The linear time Θ(n) is used 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. #
ain Sort Ain (, ; frp, En) is a department in the Auvergne-Rhône-Alpes region in Eastern France. Named after the Ain river, it is bordered by the Saône and Rhône rivers. Ain is located on the country's eastern edge, on the Swiss border, where i ...
Determines whether all buckets of the original array have been sorted. If the sorting is not completed, the ivide functionis executed. # ivide functionFind 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
ain Sort Ain (, ; frp, En) is a department in the Auvergne-Rhône-Alpes region in Eastern France. Named after the Ain river, it is bordered by the Saône and Rhône rivers. Ain is located on the country's eastern edge, on the Swiss border, where i ...


Practice

JavaScript code: Array.prototype.InterpolaionTagSort = function() ;


In-place Interpolation Tag Sort

The in-place interpolation tag sort is an
in-place algorithm In computer science, an in-place algorithm is an algorithm which transforms input using no auxiliary data structure. However, a small amount of extra storage space is allowed for auxiliary variables. The input is usually overwritten by the output ...
of interpolation sort. In-place Interpolation Tag Sort can achieve sorting by only N times of swapping by maintaining N bit tags; however, the array to be sorted must be a continuous integer sequence and not repeated, or the series is completely evenly distributed to approximate The number of
arithmetical progression An arithmetic progression or arithmetic sequence () is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression with a common differ ...
. The factor column data must not be repeated. For example, sorting 0~100 can be sorted in one step. The number of exchanges is: O(n), the calculation time complexity is: O(n), and the worst space complexity is O(n)bits. If the characteristics of the series meet the conditional requirements of this sorting method: "The
array An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
is a continuous integer or an arithmetical progression that does not repeat", the in-place interpolation tag sort will be an excellent sorting method that is extremely fast and saves memory space.


In-place Interpolation Tag Sort Algorithm

In-place Interpolation Tag Sort sorts non-repeating consecutive integer series, only one Boolean data type tag array with the same length as the original array, the array calculates the interpolation of the data from the beginning, and the interpolation points to a new position of the array. Position, the position that has been swapped is marked as true in the corresponding position of the tag array, and is incremented until the end of the array is sorted. Algorithm process: # Set an equal number of tag arrays to initialize to false values. # Visit the array when tag is false, calculate the position corresponding to the interpolation=p. # Swap a and a let tag = true. # The tour array is completed and the sorting is completed.


Practice

JavaScript code: Array.prototype.InPlaceTagSort = function() ; needSortArray.InPlaceTagSort();


The origin of In-place sorting performed in O(n) time

In "Mathematical Analysis of Algorithms", (Information Processing '71, North Holland Publ.'72) Donald Knuth remarked "... that research on computional complexity is an interesting way to sharpen our tools for more routine problems we face from day to day." The famous American computer scientist
Donald Knuth Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist, mathematician, and professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of computer sc ...
in the mathematical analysis of algorithms pointed out that:"With respect to the sorting problem, Knuth points out, that 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 O(n log n) steps on the average." The In-place Interpolation Tag Sort is one of the sorting algorithms that the
Donald Knuth Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist, mathematician, and professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of computer sc ...
professor said: "manipulate n extra "tag" bits...finding the cycle leaders, and in-situ permutations could easily be performed in O(n) time".


Similar sorting method

#
Flashsort Flashsort is a distribution sorting algorithm showing linear computational complexity for uniformly distributed data sets and relatively little additional memory requirement. The original work was published in 1998 by Karl-Dietrich Neubert. Co ...
#
Proxmap sort ProxmapSort, or Proxmap sort, is a sorting algorithm that works by partitioning an Array data structure, array of data items, or keys, into a number of "subarrays" (termed buckets, in similar sorts). The name is short for computing a "proximity m ...
#
American flag sort An American flag sort is an efficient, in-place variant of radix sort that distributes items into buckets. Non-comparative sorting algorithms such as radix sort and American flag sort are typically used to sort large objects such as strings, for w ...


Bucket sort mixing other sorting methods and recursive algorithm

Bucket sort can be mixed with other sorting methods to complete sorting. If it is sorted by bucket sort and insert sort, also is a fairly efficient sorting method. But when the series appears a large deviation from the value: For example, when the maximum value of the series is greater than N times the next largest value. After the series of columns are processed, the distribution is that all the elements except the maximum value fall into the same bucket. The second sorting method uses insert sort. May cause execution complexity to fall into O(n^2). This has lost the meaning 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 In mathematics, the factorial of a non-negative denoted is the product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial: \begin n! &= n \times (n-1) \times (n-2) \t ...
amplification in the entire series. In fact, there is very little chance that a series of special distributions will occur.


References


External links


interpolationSort.html





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



w3schools JavaScript Array Sort testing platform
{{Sorting Sorting algorithms Stable sorts