Sort ratings without comparing.
transcript
A hundred thousand plays, each rated one to five. Merge sort made over a million comparisons. Can you sort without comparing at all?
Take eight plays with these ratings. Count how many plays have each rating. The counters read zero, two, one, two, two, one. Eight plays, six counters, no comparison yet.
Rating one has two plays, so it takes two places. Add the counters up as you go. The first places are zero, zero, two, three, five, seven.
Read the plays from the left. Put each at the free place of its block. Then move that free place up by one.
Each rating owns a block of places. A play goes straight to its final place. No play is ever compared with another one.
Merge sort made about one point four million comparisons. Counting took two hundred thousand and six steps. It is two n plus k, with k keys.
Count first, then place. Full breakdown in the lecture.