The key becomes an index
transcript
A sort compares items. For 100,000 values, that is 1,660,964 comparisons. Some keys can skip the comparing.
The bucket can be the key itself, or a count. It can be the key divided by a width. Or the key measured from the minimum.
Turn the key into a whole number. That number is the bucket. Buckets are already in order.
Five prices, and the width is twenty-four. One and seven are in bucket zero. Thirty is in one. Fifty-five is in two. A hundred is in four. Bucket three is empty.
A hundred thousand amounts, each at most ten thousand. Counting takes one hundred ten thousand steps. A sort takes one point six six million comparisons.
A range of a billion needs a billion and one cells. A sort is cheaper than that. So check the range before you build the table.
Turn the key into an index. Check the table size. Full breakdown in the lecture.