Merge-insertion sort - Biblioteka.sk

Upozornenie: Prezeranie týchto stránok je určené len pre návštevníkov nad 18 rokov!
Zásady ochrany osobných údajov.
Používaním tohto webu súhlasíte s uchovávaním cookies, ktoré slúžia na poskytovanie služieb, nastavenie reklám a analýzu návštevnosti. OK, súhlasím


Panta Rhei Doprava Zadarmo
...
...


A | B | C | D | E | F | G | H | CH | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

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]

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







Text je dostupný za podmienok Creative Commons Attribution/Share-Alike License 3.0 Unported; prípadne za ďalších podmienok.
Podrobnejšie informácie nájdete na stránke Podmienky použitia.

Your browser doesn’t support the object tag.

www.astronomia.sk | www.biologia.sk | www.botanika.sk | www.dejiny.sk | www.economy.sk | www.elektrotechnika.sk | www.estetika.sk | www.farmakologia.sk | www.filozofia.sk | Fyzika | www.futurologia.sk | www.genetika.sk | www.chemia.sk | www.lingvistika.sk | www.politologia.sk | www.psychologia.sk | www.sexuologia.sk | www.sociologia.sk | www.veda.sk I www.zoologia.sk