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:

Citizenship of Zimbabwe ActNational Assembly of ZimbabweEnacted byGovernment of ZimbabweStatus: Current legislation Zimbabwean nationality law is regulated by the Constitution of Zimbabwe, as amended; the Citizenship of Zimbabwe Act, and its revisions; and various international agreements to which the country is a signatory.[1][2] These laws determine who is, or is eligible to be, a Zimbabwean national.[3][4] The legal means to acquire nationality, formal ...

 

Este artículo o sección necesita referencias que aparezcan en una publicación acreditada.Este aviso fue puesto el 20 de junio de 2011. Nokia 5233 InformaciónTipo modelo de teléfono inteligenteFabricante NokiaPantalla 3,2 640 x 360 pixeles (nHD), 16 millones de coloresDatos técnicosDimensiones 111 x 51,7 x 14,5 mmPeso 113 gramosMemoria 70 MB, memoria flash interna, memoria interna expandible a 16 GBConectividad Bluetooth v2.0, USB 2.0 via Micro-USBBandas GSM, EDGESoftwareSistema operativ...

 

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article's lead section may be too short to adequately summarize the key points. Please consider expanding the lead to provide an accessible overview of all important aspects of the article. (December 2015) This article's plot summary may be too long or excessively detailed. Please help improve it by removing unnecessary details and maki...

この記事は検証可能な参考文献や出典が全く示されていないか、不十分です。出典を追加して記事の信頼性向上にご協力ください。(このテンプレートの使い方)出典検索?: W-3 航空機 – ニュース · 書籍 · スカラー · CiNii · J-STAGE · NDL · dlib.jp · ジャパンサーチ · TWL(2022年12月) W-3ソクウ/W-3 Sokół ポーランド陸軍のW-3Wソ...

 

Moroccan climate scientist, entrepreneur and politician (born 1963) Hakima El Haiteحكيمة الحيطيHakima El Haite in May 2016Born (1963-05-13) 13 May 1963 (age 60)Fez, MoroccoNationalityMoroccanAlma materMoulay Ismail UniversityOccupation(s)Climate scientist, politician Hakima El Haite (born 13 May 1963) is a Moroccan climate scientist, entrepreneur and politician. In 1994 she founded EauGlobe, the first environmental engineering firm in the MENA region. She served as Minist...

 

Iris ApfelApfel pada MIFFLahir29 Agustus 1921 (umur 102)Astoria, Queens, New York, Amerika SerikatPendidikanNew York University, New York CityAlmamaterUniversity of WisconsinDikenal atasDesainer interior, Perancang busanaSuami/istriCarl Apfel ​ ​(m. 1948; meninggal 2015)​ Iris Apfel (lahir 29 Agustus 1921) adalah seorang pengusaha, desainer interior, dan ikon mode asal Amerika Serikat. Terlahir dengan nama Iris Barrel di Astoria, Queens, Ne...

Planned ISS component For the company behind this project, see Axiom Space. Axiom StationArtist's rendering of concept design for Axiom Station berthed at the forward port of HarmonyStation statisticsLaunch2025 (planned)Carrier rocketUndecidedLaunch padUndecidedMission statusUnder Construction[1] Axiom Orbital Segment or Axiom Segment (or AxS) are the planned modular components of the International Space Station (ISS) designed by Axiom Space for commercial space activities. Axiom Spac...

 

Artikel biografi ini ditulis menyerupai resume atau daftar riwayat hidup (Curriculum Vitae). Tolong bantu perbaiki agar netral dan ensiklopedis. SyakirPj. Bupati Aceh TenggaraPetahanaMulai menjabat 11 Oktober 2022[1]GubernurAchmad MarzukiPendahuluRaidin Pinim Informasi pribadiLahir12 Juli 1973 (umur 50)Lhokseumawe, AcehAlma materInstitut Pemerintahan Dalam NegeriPoliteknik STIA LAN JakartaUniversitas Gadjah MadaProfesiPegawai Negeri SipilPangkat / GolonganPembina Utama Muda (...

 

Etli makarnaTypePastaPlace of originTurkeyAssociated cuisineTurkish cuisine Etli makarna is a traditional pasta dish made in Turkey. They are made from meat and paste. It is prepared in Ottoman cuisine.[1][2] Varieties in Ottoman cuisine In the first Ottoman printed cookbook, Melceü't-Tabbâhîn, there is a recipe as İstofato kum makaronya (Meat pasta).[3][4] References ^ Kut, A. Turgut (1985). Açıklamalı yemek kitapları bibliyografyası: eski harfli yazm...

Rak błony śluzowej trzonu macicy carcinoma endometrium Endometrialny gruczolakorak naciekający mięsień macicy Klasyfikacje ICD-10 C54.1 {{Choroba infobox}} Przestarzałe pola: MeshYear. Rak błony śluzowej trzonu macicy, rak endometrium (łac. carcinoma endometrii, ang. endometrial cancer) – najczęstszy nowotwór złośliwy trzonu macicy. Epidemiologia Rak endometrium jest 4. pod względem zachorowalności nowotworem złośliwym u kobiet. Największa zac...

 

Book of Proverbs, chapter 7 Proverbs 7← chapter 6chapter 8 →The whole Book of Proverbs in the Leningrad Codex (1008 C.E.) from an old fascimile edition.BookBook of ProverbsCategoryKetuvimChristian Bible partOld TestamentOrder in the Christian part21 Proverbs 7 is the seventh chapter of the Book of Proverbs in the Hebrew Bible or the Old Testament of the Christian Bible.[1][2] The book is a compilation of several wisdom literature collections; the heading in 1:1 m...

 

Tabletop role-playing game The Mistborn Adventure Game is a pen-and-paper role-playing game published in 2011 by Crafty Games. It is a licensed release based on American author Brandon Sanderson's Mistborn novel series.[1]: 107 [2] Sanderson was involved in the game's creation. The game's setting, Scadrial, is the same as that of the Mistborn series.[3] The initial Mistborn Adventure Game book was released on December 16, 2011. Since 2011, four suppleme...

Office of the Communications Authority通訊事務管理局辦公室Agency overviewFormed1 April 2012Preceding agencyOffice of the Telecommunications AuthorityHeadquartersWan Chai,  Hong KongEmployees320Annual budgetHK$320.9 million revenue, HK$92.6 million profitAgency executivesMarion Lai Chan Chi-kuen, Director-GeneralHa Yung-kuen, Deputy Director-GeneralWebsiteofca.gov.hk Office of the Communications AuthorityTraditional Chinese通訊事務管理局辦公室TranscriptionsYue: Ca...

 

1998 film by Vincent Selva PriyamudanPosterDirected byVincent SelvaWritten byVincent SelvaPattukkottai Prabakar (dialogues)Produced byK. MuralidharanV. SwaminathanG. VenugopalStarringVijayKausalyaCinematographyVijay MiltonEdited byB. S. Vasu-SaleemMusic byDevaProductioncompanyLakshmi Movie MakersRelease date 12 June 1998 (1998-06-12) Running time156 minutesCountryIndiaLanguageTamil Priyamudan (transl. With love) is a 1998 Indian Tamil-language romantic thriller film direc...

 

Société de transport de LavalFoundedJune 1971Headquarters2250 Francis-Hughes Av.LocaleLaval, QuebecService areaLavalService typeBus service, paratransitRoutes97Stops2,724[1]HubsLe Carrefour Terminus, Cartier Terminus, Montmorency Terminus, Henri-Bourassa Terminus (North), Côte-Vertu TerminusStations535 (shelters)[1]Fleet309 buses[1]Daily ridership85,360 (or 22.05 million per year[1]Fuel typeB5 Biodesel[2]Chief executiveÉric MorasseWebsiteEnglish lan...

This article does not cite any sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Buona domenica – news · newspapers · books · scholar · JSTOR (June 2021) (Learn how and when to remove this template message) 1979 studio album by Antonello VendittiBuona domenicaStudio album by Antonello VendittiReleased1979Recorded1978-1979StudioTrafalgar Recordings, S...

 

Untuk film Thailand dengan judul yang hampir sama, lihat Tom-Yum-Goong. Artikel ini bukan mengenai The Protector (film 1985). Tom-Yum-Goong-2Poster Tom-Yum-Goong-2Sutradara [[ en:Prachya Pinkaew]][[Kategori:Film yang disutradarai en:Prachya Pinkaew]] Produser Prachya Pinkaew Pana Rittikrai Sukanya Vongsthapat Ditulis oleh Eakisit Thairaat Pemeran Tony Jaa RZA Petchtai Wongkamlao Yanin Jeeja Vismitananda Penata musikTerdsak JanpanSinematograferTearawat RusenathamPenyunting Manussas Woras...

 

KapoODKapo at the Hills Galleries in Kingston, Jamaica, 1957BornMallica Reynolds(1911-02-10)10 February 1911Saint Catherine Parish, JamaicaDied24 February 1989(1989-02-24) (aged 78)Resting placeNational Heroes ParkNationalityJamaicanKnown forPainting, sculptureMovementIntuitives Mallica Reynolds, OD (10 February 1911 – 24 February 1989), better known by the adopted name Kapo, was a Jamaican artist and religious leader. Considered one of the greatest artists in Jamaica's Intuitives...

Persian form of footwear For the village in Iran, see Galesh-e Bala. A traditional galesh A kalash' or galesh (گالش) is a traditional footwear of Iran. Unlike most galoshes, the galesh are always handwoven and with specific fabrics.[1] It is what people in Persia used to wear before the proliferation of the modern shoe, especially in the provinces of northern Iran. Galesh are still made today, but in the category of handicrafts and cultural produce. Galesh are also called khussa o...

 

Pahonia redirects here. For other uses, see Pahonia (disambiguation). Coat of arms of Lithuania Lietuvos herbas Vytis (Pogonia, Pahonia)ArmigerGrand Duchy of Lithuania, Republic of LithuaniaAdoptedFirst documented in 1366.Current version official since 1991.BlazonGules, an armoured knight armed cap-à-pie mounted on a horse salient holding in his dexter hand a sword Argent above his head. A shield Azure hangs on the sinister shoulder charged with a double cross (Cross of Lorraine) Or. The hor...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!