Sorting Algorithms - Merge

Other algorithms: Bubble | Insertion | Selection | Merge | Quick

Description

Compare each adjacent pair, with the highest values bubbling to the top.

Detailed Instructions

  1. Split the boxes into 2 equal piles (of 3 boxes).
    Now split each pile into 2 piles (of 1 or 2 boxes).

  2. For each pile, compare the 2 boxes and put them in order (lightest first).

  3. Compare the lightest boxes from pile 1 and pile 2. Put that to one side.
    Repeat until you have merged the two piles fully.

  4. Repeat step 3 for piles 3 and 4.

  5. You should be back to 2 piles of 3 boxes. Repeat step 3 to merge these 2 piles.

  6. And finally, once you've completed the exercise, try to work out the maximum number of comparisons you would need to solve the problem with different numbers of boxes.
Number of boxes Maximum number of comparisons
2
1
3
4
5
6

Creative Commons License
Sorting Algorithms by Mark Clarkson is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.