ArticleslgStudy

computer science

Merge-insertion sort

Merge-insertion sort is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Merge-insertion sort rather than just read about it. In short: In computer science, merge-insertion sort or the Ford–Johnson algorithm is a comparison sorting algorithm published in 1959 by L. R.

Merge-insertion sort — main illustration
Merge-insertion sort — illustration

Key takeaways

  • Merge-insertion sort belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Merge-insertion sort to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Merge-insertion sort from memory before moving on to harder problems.

Reference excerpt

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. It uses fewer comparisons in the worst case than the best previously known algorithms, binary insertion sort and merge sort, and for 20 years it was the sorting algorithm with the fewest known comparisons. Although not of practical significance, it remains of theoretical interest in connection with the problem of sorting with a minimum number of comparisons. The same algorithm may have also been independently discovered by Stanisław Trybuła and Czen Ping.

Algorithm Merge-insertion sort performs the following steps, on an input X {\displaystyle X} of n {\displaystyle n} elements:

Group the elements of X {\displaystyle X} into ⌊ n / 2 ⌋ {\displaystyle \lfloor n/2\rfloor } pairs of elements, arbitrarily, leaving one element unpaired if there is an odd number of elements. Perform ⌊ n / 2 ⌋ {\displaystyle \lfloor n/2\rfloor } comparisons, one per pair, to determine the larger of the two elements in each pair. Recursively sort the ⌊ n / 2 ⌋ {\displaystyle \lfloor n/2\rfloor } larger elements from each pair, creating a sorted sequence S {\displaystyle S} of ⌊ n / 2 ⌋ {\displaystyle \lfloor n/2\rfloor } of the input elements, in ascending order, using the merge-insertion sort. Insert at the start of S {\displaystyle S} the element that was paired with the first and smallest element of S {\displaystyle S} . Insert the remaining ⌈ n / 2 ⌉ − 1 {\displaystyle \lceil n/2\rceil -1} elements of X ∖ S {\displaystyle X\setminus S} into S {\displaystyle S} , one at a time, with a specially chosen insertion ordering described below. Use binary search in subsequences of S {\displaystyle S} (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 S {\displaystyle S} 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. To choose an insertion ordering that produces these lengths, consider the sorted sequence S {\displaystyle S} after step 4 of the outline above (before inserting the remaining elements), and let x i {\displaystyle x_{i}} denote the i {\displaystyle i} th element of this sorted sequence. Thus,

S = ( x 1 , x 2 , x 3 , … ) , {\displaystyle S=(x_{1},x_{2},x_{3},\dots ),}

where each element x i {\displaystyle x_{i}} with i ≥ 3 {\displaystyle i\geq 3} is paired with an element y i < x i {\displaystyle y_{i}<x_{i}} that has not yet been inserted. (There are no elements y 1 {\displaystyle y_{1}} or y 2 {\displaystyle y_{2}} because x 1 {\displaystyle x_{1}} and x 2 {\displaystyle x_{2}} were paired with each other.) If n {\displaystyle n} is odd, the remaining unpaired element should also be numbered as y i {\displaystyle y_{i}} with i {\displaystyle i} larger than the indexes of the paired elements. Then, the final step of the outline above can be expanded into the following steps:

Partition the uninserted elements y i {\displaystyle y_{i}} into groups with contiguous indexes. There are two elements y 3 {\displaystyle y_{3}} and y 4 {\displaystyle y_{4}} 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

… excerpt ends here. Continue reading the full article.

Illustrations

Merge-insertion sort: An animation of the merge-algorithm sorting an array of randomized values.
An animation of the merge-algorithm sorting an array of randomized values.

Worked examples

Example 1 — a first encounter with Merge-insertion sort

Start with the simplest possible case. Write down what Merge-insertion sort claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Merge-insertion sort before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Merge-insertion sort ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Merge-insertion sort

In research
Merge-insertion sort appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Merge-insertion sort in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Merge-insertion sort is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1959 in computing, Comparison sorts, so understanding it makes those chapters shorter.
In everyday life
Look for Merge-insertion sort outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Merge-insertion sort in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Merge-insertion sort means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Merge-insertion sort out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Merge-insertion sort in simple terms?

In computer science, merge-insertion sort or the Ford–Johnson algorithm is a comparison sorting algorithm published in 1959 by L. R.

Why does Merge-insertion sort matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Merge-insertion sort?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Merge-insertion sort.

Tags

  • 1959 in computing
  • Comparison sorts

Keep exploring