Knowledge (XXG)

Merge algorithm

Source 📝

51: 214:. This can be done by copying the sub-arrays into a temporary array, then applying the merge algorithm above. The allocation of a temporary array can be avoided, but at the expense of speed and programming ease. Various in-place merge algorithms have been devised, sometimes sacrificing the linear-time bound to produce an 91:
An example merge sort is given in the illustration. It starts with an unsorted array of 7 integers. The array is divided into 7 partitions; each partition contains 1 element and is sorted. The sorted partitions are then merged to produce larger, sorted, partitions, until 1 partition, the sorted
1062:. In 2018, Saitoh M. et al. introduced MMS for FPGAs, which focused on removing a multi-cycle feedback datapath that prevented efficient pipelining in hardware. Also in 2018, Papaphilippou P. et al. introduced FLiMS that improved the hardware utilization and performance by only requiring 922: 194:
When the inputs are linked lists, this algorithm can be implemented to use only a constant amount of working space; the pointers in the lists' nodes can be reused for bookkeeping and for constructing the final merged list.
1003: 692:, and since the recursive calls are independent of each other, they can be done in parallel. Hybrid approach, where serial algorithm is used for recursion base case has been shown to perform well in practice 814: 54:
A graph exemplifying merge sort. Two red arrows starting from the same node indicates subdivision, while two green arrows ending in the same node corresponds to an execution of the merge algorithm.
662:, whichever is larger, into (nearly) equal halves. It then splits the other array into a part with values smaller than the midpoint of the first, and a part with larger or equal values. (The 807: 1540:
Saitoh, Makoto; Elsayed, Elsayed A.; Chu, Thiem Van; Mashimo, Susumu; Kise, Kenji (April 2018). "A High-Performance and Cost-Effective Hardware Merge Sorter without Feedback Datapath".
73:
divide the list into sublists of (roughly) equal length, until each sublist contains only one element, or in the case of iterative (bottom up) merge sort, consider a list of
1105: 762: 734:
are in parallel, only the costlier of the two calls needs to be considered. In the worst case, the maximum number of elements in one of the recursive calls is at most
1043:
There are also algorithms that introduce parallelism within a single instance of merging of two sorted lists. These can be used in field-programmable gate arrays (
1035:
will destroy the order, if equal items are spread among both input arrays. As a result, when used for sorting, this algorithm produces a sort that is not stable.
541:
comparisons, i.e., less than half the number used by the heap-based algorithm; in practice, it may be about as fast or slow as the heap-based algorithm.
929: 30:
lists as input and produce a single list as output, containing all the elements of the inputs lists in sorted order. These algorithms are used as
1557: 1375: 1303: 1264: 132:
yields the first element of a list; "dropping" an element means removing it from its list, typically by incrementing a pointer or index.
84:
Repeatedly merge sublists to create a new sorted sublist until the single list contains all elements. The single list is the sorted list.
1289: 1692: 1637: 1462: 1256: 917:{\displaystyle T_{\infty }^{\text{merge}}(n)=T_{\infty }^{\text{merge}}\left({\frac {3}{4}}n\right)+\Theta \left(\log(n)\right)} 1715: 1624: 1132: 723: 696: 2023: 1654: 1190: 689: 477: 327: 70: 2056: 2156: 1414: 1452: 1640:. Pages 158–160 of section 5.2.4: Sorting by Merging. Section 5.3.2: Minimum-Comparison Merging, pp. 197–207. 1499:
Papaphilippou, Philippos; Luk, Wayne; Brooks, Chris (2022). "FLiMS: a Fast Lightweight 2-way Merger for Sorting".
1730: 1215: 1148: 767: 2028: 1210: 427:
Searching for the next smallest element to be output (find-min) and restoring heap order can now be done in
1936: 1816: 1770: 1353: 1328: 1175:
method which merges another list into itself. The type of the elements merged must support the less-than (
2097: 1685: 1047:), specialized sorting circuits, as well as in modern processors with single-instruction multiple-data ( 369: 242: 1182:
C++17 allows for differing execution policies, namely sequential, parallel, and parallel-unsequenced.
2076: 1941: 1796: 1440: 530:
When the input lists to this algorithm are ordered by length, shortest first, it requires fewer than
113: 1542:
2018 IEEE 26th Annual International Symposium on Field-Programmable Custom Computing Machines (FCCM)
1358: 1065: 558: 2092: 1831: 1333: 1005:, meaning that it takes that much time on an ideal machine with an unbounded number of processors. 727: 1352:. European Symp. Algorithms. Lecture Notes in Computer Science. Vol. 3221. pp. 714–723. 1982: 1957: 1931: 1735: 1563: 1522: 1059: 737: 298:
lists to pick off the minimum element each time, and repeat this loop until all lists are empty:
1801: 50: 1740: 1701: 1650: 1633: 1553: 1458: 1371: 1299: 1260: 1128: 1012: 35: 27: 2043: 1910: 1678: 1545: 1512: 1504: 1436: 1363: 550: 263: 259: 1479: 2104: 1987: 1859: 1760: 1755: 1745: 63: 1602: 1319:
Katajainen, Jyrki; Pasanen, Tomi; Teuhola, Jukka (1996). "Practical in-place mergesort".
1765: 1054:
Existing parallel algorithms are based on modifications of the merge part of either the
2109: 2018: 1885: 1854: 1839: 1720: 1448: 1055: 365: 1293: 1201:
module, that takes multiple sorted iterables, and merges them into a single iterator.
2150: 1977: 1750: 1526: 1285: 1248: 663: 1567: 1992: 1905: 1775: 1665: 1619: 1581: 294:
Several solutions to this problem exist. A naive solution is to do a loop over the
81:
sub-lists of size 1. A list containing a single element is, by definition, sorted.
1367: 104:
and linear or constant space (depending on the data access model). The following
2125: 1967: 1791: 1725: 1225: 109: 101: 2071: 2051: 2033: 1997: 1926: 1864: 1849: 1811: 1444: 1220: 554: 230: 199: 105: 59: 39: 31: 998:{\displaystyle T_{\infty }^{\text{merge}}(n)=\Theta \left(\log(n)^{2}\right)} 291:
blocks that fit in memory, sorts these one by one, then merges these blocks.
2066: 2002: 1972: 1962: 1900: 1895: 1890: 1869: 1821: 1806: 1549: 1508: 170:// By now, either A or B is empty. It remains to empty the other input list. 23: 1517: 1658: 764:
since the array with more elements is perfectly split in half. Adding the
2135: 2130: 1844: 1156: 553:
version of the binary merge algorithm can serve as a building block of a
809:
cost of the Binary Search, we obtain this recurrence as an upper bound:
2061: 620:// ensure that A is the larger array: i, j still belong to A; k, ℓ to B 1670: 1393:
Patience is a Virtue: Revisiting Merge and Sort on Modern Processors
606:
A, B, C : array i, j, k, ℓ, p, q : indices
364:
elements in the lists. It can be improved by storing the lists in a
88:
The merge algorithm is used repeatedly in the merge sort algorithm.
1662: 1144: 315:
Loop over the lists to find the one with the minimum first element.
49: 1048: 1044: 360:
element comparisons to perform its work if there are a total of
66:. Conceptually, the merge sort algorithm consists of two steps: 1674: 703:
elements, i.e., the running time of a serial version of it, is
250:-way merging generalizes binary merging to an arbitrary number 1179:) operator, or it must be provided with a custom comparator. 699:
performed by the algorithm for two arrays holding a total of
1603:"heapq — Heap queue algorithm — Python 3.10.1 documentation" 557:. The following pseudocode demonstrates this algorithm in a 258:-way merging arise in various sorting algorithms, including 164:append head(A) to C drop the head of A 1422:. Proc. 31-st Annual ACM Southeast Conf. pp. 127–135. 108:
demonstrates an algorithm that merges input lists (either
1350:
Stable Minimum Storage Merging by Symmetric Comparisons
1131:
provide built-in or library support for merging sorted
318:
Output the minimum element and remove it from its list.
168:append head(B) to C drop the head of B 1113:
compare-and-swap units to merge with a parallelism of
740: 16:
Algorithm that combines multiple sorted lists into one
1068: 932: 817: 770: 480:
solution that builds on the binary merge algorithm:
446:
comparisons), and the full problem can be solved in
2118: 2085: 2042: 2011: 1950: 1919: 1878: 1830: 1784: 1708: 1391:Chandramouli, Badrish; Goldstein, Jonathan (2014). 187:append head(B) to C drop the head of B 179:append head(A) to C drop the head of A 1099: 997: 916: 801: 756: 1295:Algorithms and Data Structures: The Basic Toolbox 100:Merging two sorted lists into one can be done in 58:The merge algorithm plays a critical role in the 726:of the algorithm, it is necessary to derive a 1686: 1163:, which merges two consecutive sorted ranges 8: 1015:: if equal items are separated by splitting 1457:(3rd ed.). MIT Press and McGraw-Hill. 1193:'s standard library (since 2.6) also has a 802:{\displaystyle \Theta \left(\log(n)\right)} 654:The algorithm operates by splitting either 1693: 1679: 1671: 688:.) Finally, each pair of halves is merged 387:lists, using the first element as the key. 202:is typically used to merge two sub-arrays 1516: 1357: 1332: 1280: 1278: 1276: 1073: 1067: 984: 942: 937: 931: 865: 854: 849: 827: 822: 816: 769: 741: 739: 1494: 1492: 1408: 1406: 1404: 1402: 1243: 1241: 647:t = p + (r - i) + (s - k) C = A 1632:, Third Edition. Addison-Wesley, 1997. 1237: 476:A third algorithm for the problem is a 254:of sorted input lists. Applications of 1431: 1429: 651:merge(A, B, C) merge(A, B, C) 573:and writes the sorted output to array 266:algorithm that divides its input into 149:list C := new empty list 390:While any of the lists is non-empty: 312:While any of the lists is non-empty: 7: 1348:Kim, Pok-Son; Kutzner, Arne (2004). 1155:, which merges two sorted ranges of 680:; that this always a number between 565:). It operates on two sorted arrays 730:. Since the two recursive calls of 1023:, they will become interleaved in 960: 938: 886: 850: 823: 771: 507:Else, recursively merge the first 198:In the merge sort algorithm, this 153:A is not empty and B is not empty 64:comparison-based sorting algorithm 14: 610:m = j - i, n = ℓ - k 407:Output the first element of list 1653:of Parallel and Serial Merge in 1171:(linked list) class has its own 718:elements need to be copied into 666:subroutine returns the index in 372:) keyed by their first element: 1716:Computational complexity theory 1651:High Performance Implementation 1625:The Art of Computer Programming 1257:Springer Science+Business Media 523:lists, then binary merge these. 494:, output the single input list. 1584:. cppreference.com. 2018-01-08 1501:IEEE Transactions on Computers 1100:{\displaystyle \log _{2}(P)+1} 1088: 1082: 981: 974: 954: 948: 906: 900: 839: 833: 791: 785: 634:// base case, nothing to merge 1: 1416:k-way Merging and k-ary Sorts 1478:Victor J. Duvanenko (2011), 1368:10.1007/978-3-540-30140-0_63 757:{\textstyle {\frac {3}{4}}n} 643:s = binary-search(A, B) 411:and remove it from its list. 1413:Greene, William A. (1993). 1253:The Algorithm Design Manual 1039:Parallel merge of two lists 561:style (adapted from Cormen 559:parallel divide-and-conquer 2173: 2024:Batcher odd–even mergesort 1454:Introduction to Algorithms 330:, this algorithm performs 240: 231:Merge sort § Variants 1216:Join (relational algebra) 1149:Standard Template Library 1119:elements per FPGA cycle. 504:, perform a binary merge. 438:time (more specifically, 2029:Pairwise sorting network 1211:Merge (revision control) 714:. This is optimal since 676:would be, if it were in 2057:Kirkpatrick–Reisch sort 1550:10.1109/FCCM.2018.00038 1509:10.1109/TC.2022.3146509 1937:Oscillating merge sort 1817:Proportion extend sort 1771:Transdichotomous model 1101: 999: 918: 803: 758: 55: 2098:Pre-topological order 1630:Sorting and Searching 1441:Leiserson, Charles E. 1102: 1000: 919: 804: 759: 243:K-way merge algorithm 145:A, B : list 53: 2077:Merge-insertion sort 1942:Polyphase merge sort 1797:Cocktail shaker sort 1544:. pp. 197–204. 1066: 930: 815: 768: 738: 639:r = ⌊(i + j)/2⌋ 581:denotes the part of 515:lists and the final 461:time (approximately 2093:Topological sorting 1855:Cartesian tree sort 1321:Nordic J. Computing 1167:. In addition, the 1107:pipeline stages of 1011:The routine is not 947: 859: 832: 728:Recurrence relation 722:. To calculate the 555:parallel merge sort 26:that take multiple 2157:Sorting algorithms 1983:Interpolation sort 1958:American flag sort 1951:Distribution sorts 1932:Cascade merge sort 1702:Sorting algorithms 1484:Dr. Dobb's Journal 1161:std::inplace_merge 1129:computer languages 1097: 1060:odd-even mergesort 995: 933: 914: 845: 818: 799: 754: 478:divide and conquer 210:of a single array 160:head(A) ≤ head(B) 56: 36:sorting algorithms 2144: 2143: 2119:Impractical sorts 1559:978-1-5386-5522-1 1445:Rivest, Ronald L. 1437:Cormen, Thomas H. 1377:978-3-540-23025-0 1305:978-3-540-77978-0 1266:978-1-849-96720-4 1151:has the function 1051:) instructions. 945: 873: 857: 830: 749: 622:swap m and n 379:Build a min-heap 328:In the worst case 305:Input: a list of 96:Merging two lists 2164: 2052:Block merge sort 2012:Concurrent sorts 1911:Patience sorting 1695: 1688: 1681: 1672: 1607: 1606: 1599: 1593: 1592: 1590: 1589: 1578: 1572: 1571: 1537: 1531: 1530: 1520: 1496: 1487: 1486: 1480:"Parallel Merge" 1475: 1469: 1468: 1433: 1424: 1423: 1421: 1410: 1397: 1396: 1388: 1382: 1381: 1361: 1345: 1339: 1338: 1336: 1316: 1310: 1309: 1282: 1271: 1270: 1255:(2nd ed.). 1245: 1200: 1197:function in the 1196: 1178: 1174: 1170: 1162: 1154: 1123:Language support 1118: 1112: 1106: 1104: 1103: 1098: 1078: 1077: 1034: 1030: 1027:; also swapping 1026: 1022: 1018: 1004: 1002: 1001: 996: 994: 990: 989: 988: 946: 943: 941: 926:The solution is 923: 921: 920: 915: 913: 909: 882: 878: 874: 866: 858: 855: 853: 831: 828: 826: 808: 806: 805: 800: 798: 794: 763: 761: 760: 755: 750: 742: 721: 717: 713: 702: 687: 683: 679: 675: 669: 661: 657: 592: 588: 584: 580: 576: 572: 568: 540: 522: 514: 503: 493: 472: 460: 445: 437: 417: 410: 403: 386: 382: 363: 359: 357: 355: 354: 351: 348: 308: 297: 290: 288: 286: 285: 280: 277: 264:external sorting 260:patience sorting 257: 253: 249: 233:for discussion. 228: 213: 209: 205: 131: 127: 124:into a new list 123: 119: 92:array, is left. 38:, most famously 22:are a family of 20:Merge algorithms 2172: 2171: 2167: 2166: 2165: 2163: 2162: 2161: 2147: 2146: 2145: 2140: 2114: 2105:Pancake sorting 2081: 2038: 2007: 1988:Pigeonhole sort 1946: 1915: 1879:Insertion sorts 1874: 1860:Tournament sort 1832:Selection sorts 1826: 1780: 1761:Integer sorting 1756:Sorting network 1746:Comparison sort 1704: 1699: 1657:with source in 1647: 1616: 1614:Further reading 1611: 1610: 1601: 1600: 1596: 1587: 1585: 1580: 1579: 1575: 1560: 1539: 1538: 1534: 1498: 1497: 1490: 1477: 1476: 1472: 1465: 1449:Stein, Clifford 1435: 1434: 1427: 1419: 1412: 1411: 1400: 1390: 1389: 1385: 1378: 1359:10.1.1.102.4612 1347: 1346: 1342: 1318: 1317: 1313: 1306: 1284: 1283: 1274: 1267: 1259:. p. 123. 1247: 1246: 1239: 1234: 1207: 1198: 1194: 1188: 1176: 1172: 1168: 1160: 1152: 1141: 1125: 1114: 1108: 1069: 1064: 1063: 1041: 1032: 1028: 1024: 1020: 1016: 980: 967: 963: 928: 927: 893: 889: 864: 860: 813: 812: 778: 774: 766: 765: 736: 735: 719: 715: 704: 700: 685: 681: 677: 671: 667: 659: 655: 652: 599:merge(A, B, C) 590: 586: 582: 578: 577:. The notation 574: 570: 566: 547: 531: 528: 527: 526: 516: 508: 498: 488: 462: 447: 439: 428: 425: 424: 423: 415: 408: 394: 384: 380: 361: 352: 349: 344: 343: 341: 331: 325: 324: 323: 306: 295: 281: 278: 275: 274: 272: 267: 255: 251: 247: 245: 239: 229:algorithm; see 215: 211: 207: 203: 192: 183:B is not empty 175:A is not empty 129: 128:. The function 125: 121: 117: 98: 48: 17: 12: 11: 5: 2170: 2168: 2160: 2159: 2149: 2148: 2142: 2141: 2139: 2138: 2133: 2128: 2122: 2120: 2116: 2115: 2113: 2112: 2110:Spaghetti sort 2107: 2102: 2101: 2100: 2089: 2087: 2083: 2082: 2080: 2079: 2074: 2069: 2064: 2059: 2054: 2048: 2046: 2040: 2039: 2037: 2036: 2031: 2026: 2021: 2019:Bitonic sorter 2015: 2013: 2009: 2008: 2006: 2005: 2000: 1995: 1990: 1985: 1980: 1975: 1970: 1965: 1960: 1954: 1952: 1948: 1947: 1945: 1944: 1939: 1934: 1929: 1923: 1921: 1917: 1916: 1914: 1913: 1908: 1903: 1898: 1893: 1888: 1886:Insertion sort 1882: 1880: 1876: 1875: 1873: 1872: 1870:Weak-heap sort 1867: 1862: 1857: 1852: 1847: 1842: 1840:Selection sort 1836: 1834: 1828: 1827: 1825: 1824: 1819: 1814: 1809: 1804: 1799: 1794: 1788: 1786: 1785:Exchange sorts 1782: 1781: 1779: 1778: 1773: 1768: 1763: 1758: 1753: 1748: 1743: 1738: 1733: 1728: 1723: 1721:Big O notation 1718: 1712: 1710: 1706: 1705: 1700: 1698: 1697: 1690: 1683: 1675: 1669: 1668: 1646: 1645:External links 1643: 1642: 1641: 1615: 1612: 1609: 1608: 1594: 1573: 1558: 1532: 1488: 1470: 1463: 1425: 1398: 1395:. SIGMOD/PODS. 1383: 1376: 1340: 1334:10.1.1.22.8523 1311: 1304: 1272: 1265: 1249:Skiena, Steven 1236: 1235: 1233: 1230: 1229: 1228: 1223: 1218: 1213: 1206: 1203: 1187: 1184: 1140: 1137: 1124: 1121: 1096: 1093: 1090: 1087: 1084: 1081: 1076: 1072: 1056:bitonic sorter 1040: 1037: 993: 987: 983: 979: 976: 973: 970: 966: 962: 959: 956: 953: 950: 940: 936: 912: 908: 905: 902: 899: 896: 892: 888: 885: 881: 877: 872: 869: 863: 852: 848: 844: 841: 838: 835: 825: 821: 797: 793: 790: 787: 784: 781: 777: 773: 753: 748: 745: 649:in parallel do 618:swap A and B 595: 546: 545:Parallel merge 543: 525: 524: 505: 495: 484: 483: 482: 473:comparisons). 422: 421: 420: 419: 412: 405: 388: 376: 375: 374: 366:priority queue 322: 321: 320: 319: 316: 310: 302: 301: 300: 241:Main article: 238: 235: 134: 97: 94: 86: 85: 82: 47: 44: 15: 13: 10: 9: 6: 4: 3: 2: 2169: 2158: 2155: 2154: 2152: 2137: 2134: 2132: 2129: 2127: 2124: 2123: 2121: 2117: 2111: 2108: 2106: 2103: 2099: 2096: 2095: 2094: 2091: 2090: 2088: 2084: 2078: 2075: 2073: 2070: 2068: 2065: 2063: 2060: 2058: 2055: 2053: 2050: 2049: 2047: 2045: 2041: 2035: 2032: 2030: 2027: 2025: 2022: 2020: 2017: 2016: 2014: 2010: 2004: 2001: 1999: 1996: 1994: 1991: 1989: 1986: 1984: 1981: 1979: 1978:Counting sort 1976: 1974: 1971: 1969: 1966: 1964: 1961: 1959: 1956: 1955: 1953: 1949: 1943: 1940: 1938: 1935: 1933: 1930: 1928: 1925: 1924: 1922: 1918: 1912: 1909: 1907: 1904: 1902: 1899: 1897: 1894: 1892: 1889: 1887: 1884: 1883: 1881: 1877: 1871: 1868: 1866: 1863: 1861: 1858: 1856: 1853: 1851: 1848: 1846: 1843: 1841: 1838: 1837: 1835: 1833: 1829: 1823: 1820: 1818: 1815: 1813: 1810: 1808: 1805: 1803: 1802:Odd–even sort 1800: 1798: 1795: 1793: 1790: 1789: 1787: 1783: 1777: 1774: 1772: 1769: 1767: 1766:X + Y sorting 1764: 1762: 1759: 1757: 1754: 1752: 1751:Adaptive sort 1749: 1747: 1744: 1742: 1739: 1737: 1734: 1732: 1729: 1727: 1724: 1722: 1719: 1717: 1714: 1713: 1711: 1707: 1703: 1696: 1691: 1689: 1684: 1682: 1677: 1676: 1673: 1667: 1664: 1660: 1656: 1652: 1649: 1648: 1644: 1639: 1638:0-201-89685-0 1635: 1631: 1627: 1626: 1621: 1618: 1617: 1613: 1604: 1598: 1595: 1583: 1577: 1574: 1569: 1565: 1561: 1555: 1551: 1547: 1543: 1536: 1533: 1528: 1524: 1519: 1518:10044/1/95271 1514: 1510: 1506: 1502: 1495: 1493: 1489: 1485: 1481: 1474: 1471: 1466: 1464:0-262-03384-4 1460: 1456: 1455: 1450: 1446: 1442: 1438: 1432: 1430: 1426: 1418: 1417: 1409: 1407: 1405: 1403: 1399: 1394: 1387: 1384: 1379: 1373: 1369: 1365: 1360: 1355: 1351: 1344: 1341: 1335: 1330: 1326: 1322: 1315: 1312: 1307: 1301: 1297: 1296: 1291: 1290:Peter Sanders 1287: 1286:Kurt Mehlhorn 1281: 1279: 1277: 1273: 1268: 1262: 1258: 1254: 1250: 1244: 1242: 1238: 1231: 1227: 1224: 1222: 1219: 1217: 1214: 1212: 1209: 1208: 1204: 1202: 1192: 1185: 1183: 1180: 1166: 1158: 1150: 1146: 1138: 1136: 1134: 1130: 1122: 1120: 1117: 1111: 1094: 1091: 1085: 1079: 1074: 1070: 1061: 1057: 1052: 1050: 1046: 1038: 1036: 1014: 1010: 1006: 991: 985: 977: 971: 968: 964: 957: 951: 934: 924: 910: 903: 897: 894: 890: 883: 879: 875: 870: 867: 861: 846: 842: 836: 819: 810: 795: 788: 782: 779: 775: 751: 746: 743: 733: 729: 725: 711: 707: 698: 693: 691: 674: 665: 664:binary search 650: 646: 642: 638: 635: 632: 629: 625: 621: 617: 613: 609: 605: 602: 598: 594: 593:, exclusive. 564: 560: 556: 552: 544: 542: 538: 534: 520: 512: 506: 501: 496: 491: 486: 485: 481: 479: 474: 470: 466: 458: 454: 450: 443: 435: 431: 413: 406: 401: 397: 392: 391: 389: 378: 377: 373: 371: 367: 347: 339: 335: 329: 317: 314: 313: 311: 304: 303: 299: 292: 284: 270: 265: 261: 244: 237:K-way merging 236: 234: 232: 226: 222: 218: 201: 196: 190: 186: 182: 178: 174: 171: 167: 163: 159: 156: 152: 148: 144: 141: 137: 133: 115: 111: 107: 103: 95: 93: 89: 83: 80: 76: 72: 69: 68: 67: 65: 62:algorithm, a 61: 52: 45: 43: 41: 37: 33: 29: 25: 21: 2044:Hybrid sorts 1993:Proxmap sort 1906:Library sort 1776:Quantum sort 1629: 1628:, Volume 3: 1623: 1620:Donald Knuth 1597: 1586:. Retrieved 1576: 1541: 1535: 1500: 1483: 1473: 1453: 1415: 1392: 1386: 1349: 1343: 1327:(1): 27–40. 1324: 1320: 1314: 1298:. Springer. 1294: 1252: 1189: 1181: 1164: 1142: 1126: 1115: 1109: 1053: 1042: 1008: 1007: 925: 811: 731: 709: 705: 694: 672: 653: 648: 644: 640: 636: 633: 630: 627: 623: 619: 615: 611: 607: 603: 600: 596: 562: 548: 536: 532: 529: 518: 510: 499: 489: 475: 468: 464: 456: 452: 448: 441: 433: 429: 426: 399: 395: 345: 337: 333: 326: 293: 282: 268: 246: 224: 220: 216: 197: 193: 188: 184: 180: 176: 172: 169: 165: 161: 157: 154: 150: 146: 142: 139: 138:merge(A, B) 135: 110:linked lists 99: 90: 87: 78: 77:elements as 74: 57: 19: 18: 2126:Stooge sort 1968:Bucket sort 1920:Merge sorts 1792:Bubble sort 1736:Inplacement 1726:Total order 1582:"std:merge" 1226:Join (Unix) 1133:collections 690:recursively 585:from index 414:Re-heapify 398:= find-min( 102:linear time 71:Recursively 46:Application 34:in various 32:subroutines 2072:Spreadsort 2034:Samplesort 1998:Radix sort 1927:Merge sort 1865:Cycle sort 1850:Smoothsort 1812:Gnome sort 1588:2018-04-28 1232:References 1221:Join (SQL) 1153:std::merge 200:subroutine 106:pseudocode 60:merge sort 40:merge sort 24:algorithms 2067:Introsort 2003:Flashsort 1973:Burstsort 1963:Bead sort 1901:Tree sort 1896:Splaysort 1891:Shellsort 1822:Quicksort 1807:Comb sort 1741:Stability 1527:245669103 1451:(2009) . 1354:CiteSeerX 1329:CiteSeerX 1169:std::list 1157:iterators 1080:⁡ 972:⁡ 961:Θ 939:∞ 898:⁡ 887:Θ 851:∞ 824:∞ 783:⁡ 772:Θ 614:m < n 597:algorithm 136:algorithm 2151:Category 2136:Bogosort 2131:Slowsort 1845:Heapsort 1568:52195866 1503:: 1–12. 1292:(2008). 1251:(2010). 1205:See also 1165:in-place 589:through 551:parallel 370:min-heap 2062:Timsort 1661:and in 383:of the 356:⁠ 342:⁠ 287:⁠ 273:⁠ 262:and an 147:returns 1709:Theory 1666:GitHub 1659:GitHub 1636:  1566:  1556:  1525:  1461:  1374:  1356:  1331:  1302:  1263:  1191:Python 1186:Python 1159:, and 1013:stable 670:where 631:return 626:m ≤ 0 604:inputs 563:et al. 440:2⌊log 309:lists. 189:return 143:inputs 114:arrays 28:sorted 2086:Other 1731:Lists 1564:S2CID 1523:S2CID 1420:(PDF) 1199:heapq 1195:merge 1173:merge 1143:The 1127:Some 1045:FPGAs 1009:Note: 944:merge 856:merge 829:merge 732:merge 535:⌈log 467:⌊log 432:(log 181:while 173:while 151:while 1634:ISBN 1554:ISBN 1459:ISBN 1372:ISBN 1300:ISBN 1261:ISBN 1177:< 1049:SIMD 1031:and 1019:and 724:span 697:work 695:The 684:and 628:then 616:then 569:and 455:log 393:Let 336:−1)( 223:log 166:else 162:then 130:head 120:and 1663:C++ 1546:doi 1513:hdl 1505:doi 1364:doi 1147:'s 1145:C++ 1139:C++ 1110:P/2 1071:log 1058:or 969:log 895:log 780:log 658:or 645:let 641:let 637:let 608:let 521:/2⌉ 513:/2⌋ 502:= 2 497:If 492:= 1 487:If 289:− 1 112:or 2153:: 1655:C# 1622:. 1562:. 1552:. 1521:. 1511:. 1491:^ 1482:, 1447:; 1443:; 1439:; 1428:^ 1401:^ 1370:. 1362:. 1323:. 1288:; 1275:^ 1240:^ 1135:. 624:if 612:if 601:is 549:A 271:= 206:, 191:C 185:do 177:do 158:if 155:do 140:is 116:) 42:. 1694:e 1687:t 1680:v 1605:. 1591:. 1570:. 1548:: 1529:. 1515:: 1507:: 1467:. 1380:. 1366:: 1337:. 1325:3 1308:. 1269:. 1116:P 1095:1 1092:+ 1089:) 1086:P 1083:( 1075:2 1033:B 1029:A 1025:C 1021:B 1017:A 992:) 986:2 982:) 978:n 975:( 965:( 958:= 955:) 952:n 949:( 935:T 911:) 907:) 904:n 901:( 891:( 884:+ 880:) 876:n 871:4 868:3 862:( 847:T 843:= 840:) 837:n 834:( 820:T 796:) 792:) 789:n 786:( 776:( 752:n 747:4 744:3 720:C 716:n 712:) 710:n 708:( 706:O 701:n 686:ℓ 682:k 678:B 673:A 668:B 660:B 656:A 591:j 587:i 583:A 579:A 575:C 571:B 567:A 539:⌉ 537:k 533:n 519:k 517:⌈ 511:k 509:⌊ 500:k 490:k 471:⌋ 469:k 465:n 463:2 459:) 457:k 453:n 451:( 449:O 444:⌋ 442:k 436:) 434:k 430:O 418:. 416:h 409:i 404:. 402:) 400:h 396:i 385:k 381:h 368:( 362:n 358:) 353:2 350:/ 346:k 340:− 338:n 334:k 332:( 307:k 296:k 283:M 279:/ 276:1 269:k 256:k 252:k 248:k 227:) 225:n 221:n 219:( 217:O 212:A 208:A 204:A 126:C 122:B 118:A 79:n 75:n

Index

algorithms
sorted
subroutines
sorting algorithms
merge sort

merge sort
comparison-based sorting algorithm
Recursively
linear time
pseudocode
linked lists
arrays
subroutine
Merge sort § Variants
K-way merge algorithm
patience sorting
external sorting
In the worst case
priority queue
min-heap
divide and conquer
parallel
parallel merge sort
parallel divide-and-conquer
binary search
recursively
work
span
Recurrence relation

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.