Sorting Algorithms - Quick

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

Description

Choose a 'pivot' and compare to each box, putting it into a light pile or heavy pile. Repeat the sort for each pile.

Detailed Instructions

  1. Choose Box1 as the 'pivot'.
    Compare this box to Box2.
    If Box2 is heavier, put it on the right.
    Otherwise, if Box2 is lighter, put it on the left.

  2. Repeat for boxes 3, 4, 5 & 6.

  3. Repeat step 1 within each pile of boxes to sort that group.

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