Merge-insertion sort

In computer science, merge-insertion sort or the Ford–Johnson algorithm is a comparison sorting algorithm published in 1959 by L. R. Ford Jr. and Selmer M. Johnson.[1][2][3][4] It uses fewer comparisons in the worst case than the best previously known algorithms, binary insertion sort and merge sort,[1] and for 20 years it was the sorting algorithm with the fewest known comparisons.[5] Although not of practical significance, it remains of theoretical interest in connection with the problem of sorting with a minimum number of comparisons.[3] The same algorithm may have also been independently discovered by Stanisław Trybuła and Czen Ping.[4]

An animation of the merge-algorithm sorting an array of randomized values.

Algorithm

Merge-insertion sort performs the following steps, on an input of elements:[6]

  1. Group the elements of into pairs of elements, arbitrarily, leaving one element unpaired if there is an odd number of elements.
  2. Perform comparisons, one per pair, to determine the larger of the two elements in each pair.
  3. Recursively sort the larger elements from each pair, creating a sorted sequence of of the input elements, in ascending order, using the merge-insertion sort.
  4. Insert at the start of the element that was paired with the first and smallest element of .
  5. Insert the remaining elements of into , one at a time, with a specially chosen insertion ordering described below. Use binary search in subsequences of (as described below) to determine the position at which each element should be inserted.

The algorithm is designed to take advantage of the fact that the binary searches used to insert elements into are most efficient (from the point of view of worst case analysis) when the length of the subsequence that is searched is one less than a power of two. This is because, for those lengths, all outcomes of the search use the same number of comparisons as each other.[1] To choose an insertion ordering that produces these lengths, consider the sorted sequence after step 4 of the outline above (before inserting the remaining elements), and let denote the th element of this sorted sequence. Thus,

where each element with is paired with an element that has not yet been inserted. (There are no elements or because and were paired with each other.) If is odd, the remaining unpaired element should also be numbered as with larger than the indexes of the paired elements. Then, the final step of the outline above can be expanded into the following steps:[1][2][3][4]

  • Partition the uninserted elements into groups with contiguous indexes. There are two elements and in the first group, and the sums of sizes of every two adjacent groups form a sequence of powers of two. Thus, the sizes of groups are: 2, 2, 6, 10, 22, 42, ...
  • Order the uninserted elements by their groups (smaller indexes to larger indexes), but within each group order them from larger indexes to smaller indexes. Thus, the ordering becomes
  • Use this ordering to insert the elements into . For each element , use a binary search from the start of up to but not including to determine where to insert .

Analysis

Let denote the number of comparisons that merge-insertion sort makes, in the worst case, when sorting elements. This number of comparisons can be broken down as the sum of three terms:

  • comparisons among the pairs of items,
  • comparisons for the recursive call, and
  • some number of comparisons for the binary insertions used to insert the remaining elements.

In the third term, the worst-case number of comparisons for the elements in the first group is two, because each is inserted into a subsequence of of length at most three. First, is inserted into the three-element subsequence . Then, is inserted into some permutation of the three-element subsequence , or in some cases into the two-element subsequence . Similarly, the elements and of the second group are each inserted into a subsequence of length at most seven, using three comparisons. More generally, the worst-case number of comparisons for the elements in the th group is , because each is inserted into a subsequence of length at most .[1][2][3][4] By summing the number of comparisons used for all the elements and solving the resulting recurrence relation, this analysis can be used to compute the values of , giving the formula[7]

or, in closed form,[8]

For the numbers of comparisons are[1]

0, 1, 3, 5, 7, 10, 13, 16, 19, 22, 26, 30, 34, ... (sequence A001768 in the OEIS)

Relation to other comparison sorts

The algorithm is called merge-insertion sort because the initial comparisons that it performs before its recursive call (pairing up arbitrary items and comparing each pair) are the same as the initial comparisons of merge sort, while the comparisons that it performs after the recursive call (using binary search to insert elements one by one into a sorted list) follow the same principle as insertion sort. In this sense, it is a hybrid algorithm that combines both merge sort and insertion sort.[9]

For small inputs (up to ) its numbers of comparisons equal the lower bound on comparison sorting of . However, for larger inputs the number of comparisons made by the merge-insertion algorithm is bigger than this lower bound. Merge-insertion sort also performs fewer comparisons than the sorting numbers, which count the comparisons made by binary insertion sort or merge sort in the worst case. The sorting numbers fluctuate between and , with the same leading term but a worse constant factor in the lower-order linear term.[1]

Merge-insertion sort is the sorting algorithm with the minimum possible comparisons for items whenever , and it has the fewest comparisons known for .[10][11] For 20 years, merge-insertion sort was the sorting algorithm with the fewest comparisons known for all input lengths. However, in 1979 Glenn Manacher published another sorting algorithm that used even fewer comparisons, for large enough inputs.[3][5] It remains unknown exactly how many comparisons are needed for sorting, for all , but Manacher's algorithm and later record-breaking sorting algorithms have all used modifications of the merge-insertion sort ideas.[3]

References

  1. ^ a b c d e f g Ford, Lester R. Jr.; Johnson, Selmer M. (1959), "A tournament problem", American Mathematical Monthly, 66: 387–389, doi:10.2307/2308750, MR 0103159
  2. ^ a b c Williamson, Stanley Gill (2002), "2.31 Merge insertion (Ford–Johnson)", Combinatorics for Computer Science, Dover books on mathematics, Courier Corporation, pp. 66–68, ISBN 9780486420769
  3. ^ a b c d e f Mahmoud, Hosam M. (2011), "12.3.1 The Ford–Johnson algorithm", Sorting: A Distribution Theory, Wiley Series in Discrete Mathematics and Optimization, vol. 54, John Wiley & Sons, pp. 286–288, ISBN 9781118031131
  4. ^ a b c d Knuth, Donald E. (1998), "Merge insertion", The Art of Computer Programming, Vol. 3: Sorting and Searching (2nd ed.), pp. 184–186
  5. ^ a b Manacher, Glenn K. (July 1979), "The Ford-Johnson Sorting Algorithm Is Not Optimal", Journal of the ACM, 26 (3): 441–456, doi:10.1145/322139.322145
  6. ^ The original description by Ford & Johnson (1959) sorted the elements in descending order. The steps listed here reverse the output, following the description in Knuth (1998). The resulting algorithm makes the same comparisons but produces ascending order instead.
  7. ^ Knuth (1998) credits the summation formula to the 1960 Ph.D. thesis of A. Hadian. The approximation formula was already given by Ford & Johnson (1959).
  8. ^ Guy, Richard K.; Nowakowski, Richard J. (December 1995), "Monthly Unsolved Problems, 1969-1995", American Mathematical Monthly, 102 (10): 921–926, doi:10.2307/2975272
  9. ^ Knuth (1998), p. 184: "Since it involves some aspects of merging and some aspects of insertion, we call it merge insertion."
  10. ^ Peczarski, Marcin (2004), "New results in minimum-comparison sorting", Algorithmica, 40 (2): 133–145, doi:10.1007/s00453-004-1100-7, MR 2072769
  11. ^ Peczarski, Marcin (2007), "The Ford-Johnson algorithm still unbeaten for less than 47 elements", Information Processing Letters, 101 (3): 126–128, doi:10.1016/j.ipl.2006.09.001, MR 2287331

Read other articles:

Eva KrisnaLahir16 Juli 1967 (umur 56)Kota Payakumbuh, Sumatera Barat IndonesiaKebangsaanIndonesiaAlmamaterUniversitas Andalas Universitas Indonesia Universitas UdayanaPekerjaanDosenDikenal atasPeneliti dan penyuluh bahasa Indonesia Dr. Eva Krisna, M.Hum. (lahir 16 Juli 1967) adalah seorang peneliti sastra lisan, dosen, dan penyuluh bahasa Indonesia. Saat ini, ia menjabat Kepala Balai Bahasa Provinsi Sumatera Barat sejak 2022.[1] Sebelumnya, ia menjabat sebagai Kepala Kantor Baha...

 

American punk rock band This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: The Falcon band – news · newspapers · books · scholar · JSTOR (April 2020) (Learn how and when to remove this template message) The FalconBackground informationOriginChicago, Illinois, United StatesGenresPunk rockYears active2004...

 

СМК (СССР). Пятибашенный тяжёлый танк Т-35, мощнейший танк РККА в межвоенный период.Советский тяжёлый танк ИС-3.Советский тяжёлый танк Т-10М. Тяжёлый танк — согласно классификации танков по массе: основной и специальный танк, превосходящий лёгкий и средний танки по массе, за�...

artikel ini perlu dirapikan agar memenuhi standar Wikipedia. Tidak ada alasan yang diberikan. Silakan kembangkan artikel ini semampu Anda. Merapikan artikel dapat dilakukan dengan wikifikasi atau membagi artikel ke paragraf-paragraf. Jika sudah dirapikan, silakan hapus templat ini. (Pelajari cara dan kapan saatnya untuk menghapus pesan templat ini) Artikel ini terlalu bergantung pada referensi dari sumber primer. Mohon perbaiki artikel ini dengan menambahkan sumber sekunder atau tersier. (Pel...

 

George Washington's horse Washington riding Nelson (left); Washington and Lafayette at Valley Forge, John Ward Dunsmore Washington at the Battle of Trenton, shown on Nelson; engraving after a painting by Edward Lamson Henry Nelson or Old Nelson was one of several horses owned by George Washington. He was a chestnut with a white blaze and white feet. The horse was acquired by Washington in 1779 and died in 1790 at about the age of 27, quite old for a horse in that era.[1] As Washington...

 

Piala Raja Spanyol 1903Negara SpanyolJumlah peserta3JuaraAthletic Bilbao(gelar ke-1)Tempat keduaMadrid FCJumlah pertandingan3Jumlah gol14 (4.67 per pertandingan)Pencetak gol terbanyak Juan Astorquia Armando Giralt Alejandro de la Sota(2 gol)1904 → Piala Raja Spanyol 1903 adalah edisi pertama dari penyelenggaraan Piala Raja Spanyol, turnamen sepak bola di Spanyol dengan sistem piala. Edisi ini dimenangkan oleh Athletic Bilbao setelah mengalahkan Madrid FC pada pertandingan final dengan ...

العلاقات السودانية الناميبية السودان ناميبيا   السودان   ناميبيا تعديل مصدري - تعديل   العلاقات السودانية الناميبية هي العلاقات الثنائية التي تجمع بين السودان وناميبيا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه ال...

 

Majko II Government61st Government of AlbaniaDate formed22 February 2002 (2002-02-22)Date dissolved31 July 2002 (2002-07-31)People and organisationsPresidentRexhep MeidaniAlfred MoisiuChairpersonNamik DoklePrime MinisterPandeli MajkoDeputy Prime MinisterSkënder GjinushiTotal no. of members140Member partiesPSStatus in legislatureCoalitionOpposition partiesPD, PROpposition leaderSali BerishaHistoryElection(s)2001 electionPredecessorMeta II GovernmentSuccessorNano ...

 

بومبادور تأخذ اسمها من مدام دو بومبادور بومبادور مصطلح يشير إلى تسريحة شعر قديمة تعود إلى القرن الثامن عشر نسبة إلى الأرستقراطية مدام دو بومبادور (1721-1764)، عشيقة الملك لويس الخامس عشر[1] على الرغم من أن هناك اختلافات نمط بين النساء والرجال، المفهوم الأساسي لها يرفع فيها �...

Hospital in Edinburgh, ScotlandLeith Community Treatment CentreNHS LothianLeith Community Treatment CentreShown in EdinburghGeographyLocationEdinburgh, ScotlandCoordinates55°58′17″N 3°10′34″W / 55.97139°N 3.17611°W / 55.97139; -3.17611OrganisationCare systemNHSTypeSpecialistServicesSpecialityCommunity hospitalHistoryOpened2004LinksOther linksList of hospitals in Scotland The Leith Community Treatment Centre is a community hospital in Junction Place, Leith,...

 

UGM-96 Trident I, atau Trident C4 adalah sebuah peluru kendali / rudal balistik Amerika yang diluncurkan Submarine, dibangun oleh Lockheed Martin Space Systems di Sunnyvale, California. Pertama digunakan pada tahun 1979, Trident I menggantikan rudal Poseidon. Ini sudah pensiun pada tahun 2005, [2] yang telah digantikan oleh Trident II. Trident I adalah tiga tahap, rudal berbahan bakar padat. Referensi Wikimedia Commons memiliki media mengenai Trident missile. lbsSistem penggolongan peluru ke...

 

This article needs to be updated. Please help update this article to reflect recent events or newly available information. (April 2022)Part of a series onCreationism History Types Young Earth Time dilation creationism Old Earth day-age gap progressive Neo-creationism Biblical cosmology Book of Genesis creation narrative framework interpretation as an allegory Omphalos hypothesis Creation science Created kind Flood geology Creationist cosmologies Intelligent design Rejection of evolution by re...

The Family PlanPoster resmiSutradaraSimon Cellan JonesProduser David Ellison Dana Goldberg Don Granger Mark Wahlberg Stephen Levinson Ditulis olehDavid CoggeshallPemeran Mark Wahlberg Michelle Monaghan Zoe Colletti Van Crosby Saïd Taghmaoui Maggie Q Ciarán Hinds Penata musikKevin MatleySinematograferMichael BurgessPenyuntingTim PorterPerusahaanproduksi Apple Original Films Skydance Municipal Pictures DistributorApple TV+Tanggal rilis 15 Desember 2023 (2023-12-15) Durasi119 menit&...

 

Long-distance hiking trail in the United States Bigfoot TrailThe Bigfoot Trail passes Russian Lake in the Russian WildernessLengthapprox 360 miles (600 km)LocationKlamath Mountains, California, United StatesUseHikingDifficultyStrenuous Map all coordinates using OpenStreetMap Download coordinates as: KML GPX (all coordinates) GPX (primary coordinates) GPX (secondary coordinates) The Bigfoot Trail is an unofficial U.S. long-distance hiking trail in northern California.[1] The Bigfo...

 

متلازمة XXXX معلومات عامة الاختصاص علم الوراثة الطبية  تعديل مصدري - تعديل   رباعي X ويعرف أيضًا باسم XXXX ‏,48، هو اضطراب صبغي حيث يكون لدى الأنثى أربعة صبغيات X بدلاً من الاثنين النموذجيين. ترتبط هذه الحالة بدرجات متفاوتة من الإعاقة الذهنية، وملامح الوجه المميزة التي تتمي...

Disambiguazione – Se stai cercando l'omonimo film del 2004, vedi Starsky & Hutch (film). Questa voce o sezione sull'argomento fiction televisive statunitensi 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. Segui i suggerimenti del progetto di riferimento. Starsky & HutchTitolo originaleStarsky & Hutch PaeseStati Uniti d'America Anno1975-197...

 

Хип-хоп Направление популярная музыка Истоки фанкдискоэлектронная музыкадабритм-энд-блюзреггидэнсхоллджаз[1]чтение нараспев[англ.]исполнение поэзииустная поэзияозначиваниедюжины[англ.]гриотыскэтразговорный блюз Время и место возникновения Начало 1970-х, Бронкс, Н...

 

KFC

Kentucky Fried Chicken (KFC)Logo KFC sejak 2018JenisAnak perusahaanIndustriRestoranGenreRestoran cepat sajiDidirikanSanders Court & Café:20 Maret 1930; 94 tahun lalu (1930-03-20)North Corbin, KentuckyWarabala pertama:24 September 1952; 71 tahun lalu (1952-09-24)Salt Lake City, UtahPendiriHarland SandersPete HarmanKantorpusat1441 Gardiner LaneLouisville, Kentucky, U.S.Dallas, Texas, U.S. (Dunia)Cabang24,104[1][2] (2015)TokohkunciTony Lowings CEO[3] a...

LadybeardPegulat Rick Magarey dengan pesona Ladybeard-nyaNama lahirRichard MagareyLahir3 Agustus 1983 (umur 40)Adelaide, South Australia, AustraliaSitus webhttp://www.ladybeard.com/Karier gulat profesionalNama ringLadybeard[1]Richard Burn[1]Tinggi6 ft 0 in (183 cm)[1]Berat194 pon (88 kg)[1]Asal dariAdelaide, South AustraliaDebut2009 Richard Magarey adalah seorang pemeran pengganti Australia, dan dengan pesona lintas busana berjengg...

 

American actor (born 1956) Timothy Daly redirects here. For the playwright, see Timothy Daly (playwright). Tim DalyDaly in 2015BornJames Timothy Daly (1956-03-01) March 1, 1956 (age 68)Suffern, New York, U.S.Other namesTimothy DalyAlma materBennington College, B.A. 1979Occupation(s)Actor, producerYears active1963–presentSpouse Amy Van Nostrand ​ ​(m. 1982; div. 2010)​PartnerTéa Leoni (2014–2023)Children2, including Sam D...