Skip to story
ELI5 Yahaaa

Order makes finding easy

Why Do We Sort Things?

Sorting costs effort once, then saves effort every single time you look for something.

Unsorted Check every item tofind oneSorted Jump straight toroughly the right place
Pay once, save forever.
  1. Step 1 of 5

    Sorting means putting things in an order.

    1 A jumble2 Pick a rule3 Everything inorder

    By size, by colour, by letter, by number. You pick a rule, and then every item has a definite place relative to the others.

  2. Step 2 of 5

    Finding things in a jumble is slow.

    Unsorted searchabout 500 checksSorted searchabout 10 checks

    In an unsorted pile of 1,000 items you may have to check all 1,000. On average you check 500.

  3. Step 3 of 5

    In sorted order you can halve the problem.

    1 1,000 items2 Look in themiddle, discardhalf310About 10 looksand you have it

    Open a dictionary in the middle. Your word is either before or after — so half the book is gone in one look. Repeat and 1,000 items take ten checks.

  4. Step 4 of 5

    Sorting also reveals things.

    Jumbled data Nothing stands outSorted data Extremes and middle areobvious

    Line up a class by height and the tallest, shortest and middle are instantly visible. Order exposes patterns invisible in a jumble.

  5. Step 5 of 5

    It is worth it when you look more than once.

    Should you sort?Cost: effortnowBenefit: everyfuture searchis fast

    Sorting takes effort up front. If you only ever need one item, do not bother. If you will search a hundred times, sort first.

    Sorting is one of the most studied problems in computing, precisely because so much depends on doing it well.

The short version

Sorting costs effort once and makes every future search dramatically faster.

Try it yourself

Time yourself finding a word in a dictionary, then in a shuffled list of the same words. The difference is the value of order.

Topics