Interpolation sort

Interpolation sort is a sorting algorithm that 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[i] - min) / (max - min)) * (ArraySize - 1))

Algorithm

Interpolation Sort
ClassSorting Algorithm
Data structureArray
Worst-case performance
Best-case performance
Average performance
Worst-case space complexity
Optimal

Interpolation sort (or histogram sort).[1] It is a sorting algorithm that uses the interpolation formula to disperse data divide and conquer. Interpolation sort is also a variant of bucket sort algorithm.[2] 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 algorithm can be prevented from changing the space complexity to 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 .[3] Array of dynamically allocated memory can be implemented by linked list, stack, queue, associative array, tree structure, etc. An array object such as JavaScript is applicable. The difference in data structure is related to the speed of data access and thus the time required for sorting.When the values in the ordered array are uniformly distributed approximately the arithmetic progression, the linear time of interpolation sort ordering is .[4]

Interpolation sort algorithm

  1. Set a bucket length array to record the length of the unsorted bucket. Initialize into the original array length.
  2. [Main Sort] If the bucket length array is cleared and sorted is completed. Execute [Divide function] if it is not cleared.
  3. [Divide function] Execute 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.
  4. Set up a two-dimensional array as all empty buckets. Divide into the bucket according to the interpolation number.
  5. 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.
  6. Return to [Main Sort].

Histogram sort algorithm

The NIST definition: An efficient 3-pass refinement of a bucket sort algorithm.[5]

  1. 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.
  2. The second pass puts each item in its proper bucket according to the auxiliary entry for the key of that item.
  3. 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 < end; i++) {
      if (A[i] < min) { min = A[i]; }
      else { if (A[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 < size; i++) { bucket[i] = new Array(); }
      for (var i = start; i < end; i++) {
        p = Math.floor(((A[i] - min ) / (max - min ) ) * (size - 1 ));
        bucket[p].push(A[i]);
      }
      for (var i = 0; i < size; i++) {
        if (bucket[i].length > 0) {
          for (var j = 0; j < bucket[i].length; j++) { A[start++] = bucket[i][j]; }
          divideSize.push(bucket[i].length);
        }
      }
    }
  }
};

Interpolation sort recursive method

Worst-case space complexity :

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 < size; i++) {
    if (this[i] < min) { min = this[i]; }
    else {if (this[i] > max) { max = this[i];} }
  }
  if (min != max) {
    var bucket = new Array(size);
    for (var i = 0; i < size; i++) { bucket[i] = new Array(); }
    var interpolation = 0;
    for (var i = 0; i < size; i++) {
      interpolation = Math.floor(((this[i] - min) / (max - min)) * (size - 1));
      bucket[interpolation].push(this[i]);
    }
    for (var i = 0; i < size; i++) {
      if (bucket[i].length > 1) { bucket[i].interpolationSort(); } // Recursion
      for (var j = 0; j < bucket[i].length; j++) { this[start++] = bucket[i][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 < end; i++) {
      if (A[i] < min) { min = A[i]; }
      else { if (A[i] > max) { max = A[i]; } }
    }
    if (min == max) { end = end - size; }
    else {
      for (var i = start; i < end; i++) { hitCount[i] = 0; }
      for (var i = start; i < end; i++) {
        interpolation[i] = start + Math.floor(((A[i] - min ) / (max - min ) ) * (size - 1 ));
        hitCount[interpolation[i]]++;
      }
      for (var i = start; i < end; i++) {
        if (hitCount[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 < end; i++) {
        sortedArray[hitCount[interpolation[i]]] = A[i];
        hitCount[interpolation[i]]++;
      }
      for (var i = start; i < end; i++) { A[i] = sortedArray[i]; }
    }
  }
};

Variant

Interpolation tag sort

Interpolation Tag Sort
ClassSorting Algorithm
Data structureArray
Worst-case performance
Best-case performance
Average performance
Worst-case space complexity
Optimal

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 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 . 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 . Interpolation tag sort average performance complexity is .[3]

Interpolation tag sort algorithm

  1. Set a tag array equal to the original array size and initialize to a false value.
  2. [Main Sort] Determines whether all buckets of the original array have been sorted. If the sorting is not completed, the [Divide function] is executed.
  3. [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.
  4. Set up a two-dimensional array as all the empty buckets. Divide into the bucket according to the interpolation number.
  5. 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.
  6. 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 < end; i++) { Tag[i] = false; } 
    Divide(this); 
  } 
  while (end > 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 < end; i++) { 
      if (A[i] < min) { min = A[i]; } 
      else { if (A[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 < size; i++) { Bucket[i] = new Array(); }  
      for (var i = start; i < end; i++) {  
         interpolation = Math.floor (((A[i] - min) / (max - min)) * (size - 1));
         Bucket[interpolation].push(A[i]); 
      } 
      for (var i = 0; i < size; i++) {
        if (Bucket[i].length > 0) {    // Algorithm step-5      
          Tag[start] = true; 
          for (var j = 0; j < Bucket[i].length; j++) { A[start++] = Bucket[i][j]; } 
        } 
      }  
    }
  } // Algorithm step-6 
};

In-place Interpolation Tag Sort

In-Place Interpolation Tag Sort
ClassSorting Algorithm
Data structureArray
Worst-case performance
Best-case performance
Average performance
Worst-case space complexity
Optimal

The in-place interpolation tag sort is an in-place algorithm 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.

The factor column data must not be repeated. For example, sorting 0~100 can be sorted in one step. The number of exchanges is: , the calculation time complexity is: , and the worst space complexity is . If the characteristics of the series meet the conditional requirements of this sorting method: "The array 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:

  1. Set an equal number of tag arrays to initialize to false values.
  2. Visit the array when tag[i] is false, calculate the position corresponding to the interpolation=p.
  3. Swap a[i] and a[p], let tag[p] = true.
  4. 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 < n; i++) { Tag[i] = false; }
  var min = this[0];
  var max = this[0];
  for (i = 1; i < n; i++) { if (this[i] < min) { min = this[i]; }
  else { if (this[i] > max) { max = this[i]; } } } 
  var p = 0;
  var temp = 0;
  for (i = 0; i < n; i++) {
    while (Tag[i] == false) { 
      p = Math.floor(((this[i] - min) / (max - min)) * (n - 1));
      temp = this[i];
      this[i] = this[p]; 
      this[p] = temp;
      Tag[p] = true; 
    } 
  } 
};
needSortArray.InPlaceTagSort();

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

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."[6]

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."[6]

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".

Similar sorting method

  1. Flashsort
  2. Proxmap sort
  3. American flag sort

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 . 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 , 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.

References

  1. ^ NIST Algorithm. "interpolation sort". Definition: See histogram sort.
  2. ^ Histogram sort[circular reference]
  3. ^ a b 桶排序(Bucket sort)[circular reference]
  4. ^ Bucket sort Average-case analysis[circular reference]
  5. ^ NIST Algorithm. "histogramSort sort". Definition: An efficient 3-pass refinement of a bucket sort algorithm.
  6. ^ a b Karl-Dietrich Neubert (1998). "The FlashSort Algorithm". Retrieved 2007-11-06.

Read other articles:

Relik salib berbahan gading anjing laut dari abad ke-11 (Victoria & Albert Museum) Seni rupa Anglo-Saxon meliputi seni rupa yang dibuat pada zaman Anglo-Saxon dari sejarah Inggris, bermula dari gaya periode Migrasi dimana Anglo-Saxon membawa mereka dari daratan utama Eropa pada abad ke-5, dan berakhir pada 1066 dengan Penaklukan Norman terhadap negara Anglo-Saxon besar yang seni rupanya mempengaruhi sebagian besar utara Eropa. Dua periode dari pengabdian terbaik adalah abad ke-7 dan ke-8,...

 

 

يفتقر محتوى هذه المقالة إلى الاستشهاد بمصادر. فضلاً، ساهم في تطوير هذه المقالة من خلال إضافة مصادر موثوق بها. أي معلومات غير موثقة يمكن التشكيك بها وإزالتها. (ديسمبر 2018) البحرين معلومات عامة بلد الرياضة البحرين  الفئة كرة قدم تحت 23 سنة للرجال  [لغات أخرى]‏  رمز ا�...

 

 

Gahwié got’iné, a Sahtú (North Slavey) people of Canada Indigenous people in northern Canada PeopleDeneCountryDenendeh For the Diné people native to the Southwestern US, see Navajo. For other uses, see Dene (disambiguation). Indigenous peoplesin Canada First Nations Inuit Métis History Timeline Paleo-Indians Pre-colonization Genetics Residential schools gravesites Indian hospitals Conflicts First Nations Inuit Truth and Reconciliation Commission Politics Indigenous law British Columbia...

Questa voce o sezione sull'argomento politici cinesi non cita le fonti necessarie o quelle presenti sono insufficienti. Puoi migliorare questa voce aggiungendo citazioni da fonti attendibili secondo le linee guida sull'uso delle fonti. «Comprendo fin troppo bene quello che avete detto. Quello che state facendo è gettare fango su di me, sul presidente Mao Zedong e sulla Grande rivoluzione culturale proletaria, a cui hanno partecipato centinaia di migliaia di persone... Nasconderete anc...

 

 

Bagian dari sebuah seri tentang Muhakkimah Kepercayaan dan praktek Monoteisme Kitman Takfir Teologi Sejarah Awal Fitnah Pertama Pertempuran Siffin Pertempuran Nahrawan Dinasti Rustamiyah Nabhaniyah Ya'rubiyah Zanzibar Oman Kumpulan hadis Jami' ash-Shahih Tartib al-Musnad Tokoh terkenal Abdurrahman bin Muljam Nafi bin al-Azraq Najdah bin Amir al-Hanafi Abu Bilal Mirdas Abu Qurra Abdullah bin Ibadh Jabir bin Zayd Abu Yazid Abd Allah bin Yazid al-Fazari Cabang dan sekte Khawarij Ajardi Azariqah ...

 

 

Bupati Aceh SingkilPetahanaMarthunis, S.T. D.E.Asejak 21 Juli 2022Masa jabatan5 tahunPejabat pertamaMakmur Syahputra BancinSitus webSitus Resmi Kabupaten Aceh Singkil Berikut nama-nama Bupati Aceh Singkil dari masa ke masa No Bupati Mulai menjabat Akhir menjabat Prd. Ket. Wakil Bupati 1 Makmur Syahputra Bancin 2000 2005 1 Muadz Vohry Ir. M. Azmy (Penjabat) 2005 2006 Hasdaruddin(Penjabat) 2006 2007 (1) Makmur Syahputra Bancin 2007 15 Oktober 2011 2 [ket. 1] Khazali 2 Khazali 2011 ...

この項目には、一部のコンピュータや閲覧ソフトで表示できない文字が含まれています(詳細)。 数字の大字(だいじ)は、漢数字の一種。通常用いる単純な字形の漢数字(小字)の代わりに同じ音の別の漢字を用いるものである。 概要 壱万円日本銀行券(「壱」が大字) 弐千円日本銀行券(「弐」が大字) 漢数字には「一」「二」「三」と続く小字と、「壱」「�...

 

 

This article may require copy editing for grammar, style, cohesion, tone, or spelling. You can assist by editing it. (December 2023) (Learn how and when to remove this message) American HindusHoli celebration at Sri Sri Radha Krishna Temple in Spanish Fork, UtahTotal population3,369,976 (2021) [1][2]1% of U.S. Population[3](2016 Public Religion Research Institute data) 0.7% of the U.S. Population (2015 Pew Research Center data)[4]Regions with significant popul...

 

 

См. также: Присоединение Прибалтики к СССР Присоединение Литвы к СССР — политический процесс в истории Литвы, приведший Литовскую Республику к включению её в состав СССР. Период нахождения республики в составе СССР самой Литвой, странами Балтии и многими другими стра...

Disambiguazione – Se stai cercando altri significati, vedi Meo Patacca (disambigua). Meo PataccaTitolo originaleIl Meo Patacca o vero Roma in feste nei trionfi di Vienna Immagine tratta dalla Tavola 52: Nuccia accetta Meo Patacca come sposo AutoreGiuseppe Berneri 1ª ed. originale1695 Generepoema Sottogenereeroicomico Lingua originaleromanesco Ambientazionela Roma papalina del XVII secolo ProtagonistiMeo Patacca Altri personaggiNuccia, Calfurnia, Marco Pepe Modifica dati su Wikidata �...

 

 

Balkanabat БалканабатNegara TurkmenistanProvinsiProvinsi BalkanKetinggian17 m (56 ft)Populasi (2006) • Total87,822Zona waktuUTC+5 (Waktu Turkmenistan) • Musim panas (DST)UTC+5 (Tidak ada)Kode area telepon(00993) 222 X XX XX Balkanabat (Балканабат) yang sebelumnya dikenal dengan nama Nebit Dag merupakan sebuah kota di bagian barat Turkmenistan dan juga merupakan ibu kota Provinsi Balkan. Berdasarkan sensus tahun 2006, kota ini berpendu...

 

 

Der Titel dieses Artikels ist mehrdeutig. Weitere Bedeutungen sind unter Gerechtigkeit (Begriffsklärung) aufgeführt. Der Kuss von Gerechtigkeit und Friede. Unbekannter Künstler, Antwerpen um 1580 Die im westlichen Kulturkreis häufige allegorische Darstellung der Gerechtigkeit als Justitia. Sie hat gewöhnlich drei Attribute: die Waage (abwägend, schlichtend, Privatrecht), Schwert (verurteilend, Strafrecht), und eine Binde vor den Augen (ohne Ansehen der Person). Der Begriff der Gerechti...

American liberal fake news website This article is about the American political blog. For the UN Report on Israel's naval blockade of Gaza, see Geoffrey Palmer (politician) § UN Inquiry. Palmer ReportHomepage on July 4, 2021Type of sitePolitical blogAvailable inEnglishPredecessor(s)Daily News BinOwnerBill PalmerFounder(s)Bill PalmerURLwww.palmerreport.com RegistrationNoneLaunched2016; 8 years ago (2016)[1]Current statusActive The Palmer Report is an A...

 

 

Total eclipse Solar eclipse of November 14, 2031MapType of eclipseNatureHybridGamma0.3078Magnitude1.0106Maximum eclipseDuration68 s (1 min 8 s)Coordinates0°36′S 137°36′W / 0.6°S 137.6°W / -0.6; -137.6Max. width of band38 km (24 mi)Times (UTC)Greatest eclipse21:07:31ReferencesSaros143 (24 of 72)Catalog # (SE5000)9578 A total solar eclipse will occur at the Moon's ascending node of orbit on Friday, November 14, 2031, with a magn...

 

 

Hungarian professional footballer Roland Baracskai Personal informationDate of birth (1992-04-11) 11 April 1992 (age 32)Place of birth Budapest, HungaryHeight 1.82 m (6 ft 0 in)Position(s) ForwardTeam informationCurrent team CsákvárNumber 33Youth career2003–2008 FelcsútSenior career*Years Team Apps (Gls)2007–2008 Felcsút 1 (0)2008–2012 Videoton 0 (0)2008–2012 → Videoton II 39 (5)2012–2014 Puskás 32 (5)2014–2019 Mezőkövesd 40 (7)2015–2016 → Sopron (...

أحمد ولد داداه ولد داداه أواخر عام 2021 معلومات شخصية الميلاد 7 أغسطس 1942 (العمر 81 سنة)بوتلميت  مواطنة موريتانيا  الحياة العملية المدرسة الأم جامعة باريس  المهنة سياسي،  واقتصادي  الحزب تكتل القوى الديمقراطية (موريتانيا)  اللغات العربية  تعديل مصدري - تعديل ...

 

 

Mathematical operation that combines three elements to produce another element In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. In computer science, a ternary operator is an operator that takes three arguments as input and returns one output.[1] Examples Given A, B and point P, geometric construction yields V, the projective harmonic conjugate of P w...

 

 

この記事には複数の問題があります。改善やノートページでの議論にご協力ください。 出典が不足しています。存命人物の記事は特に、検証可能性を満たしている必要があります。(2022年4月) 独自研究が含まれているおそれがあります。(2024年4月) マークアップをスタイルマニュアルに沿った形に修正する必要があります。(2022年4月) あまり重要でない事項が過�...

Một cảnh khiêu dâm từ một bức bích họa của Pompeii, -50 sau Công nguyên, Bảo tàng bí mật, Napoli Hoạt động Mại dâm đã tồn tại trong các nền văn hóa từ thời kỳ cổ đại đến hiện đại.[1][2] Mại dâm được xem là nghề cổ nhất thế giới, nhưng sự thật là nghề nông, săn bắn hoặc chăn nuôi có thể là những nghề cổ nhất thực sự.[3][4][5] Cận Đông cổ...

 

 

This article includes a list of general references, but it lacks sufficient corresponding inline citations. Please help to improve this article by introducing more precise citations. (January 2020) (Learn how and when to remove this message) Edward CowlesBorn1836 or 1837Peacham, VermontDiedJuly 25, 1919 (aged 82)Plymouth, MassachusettsEducation Dartmouth College College of Physicians and Surgeons OccupationPsychiatristEmployers Boston City Hospital McLean Hospital Edward Cowles ...