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 rightplace
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,discard half310About 10 looksand you haveit

    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 middleare obvious

    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

Unsorted, a pile of 1,000 costs 500 checks on average; sorted, halving the problem each look gets you there in ten. Order also exposes patterns a jumble hides. But it only pays if you are going to look more than once.

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.

Tags