Loading page…
A monitoring service scans a list of a thousand ids and stops at the first match, so its cost depends on the input. A lookup makes one comparison at best and a thousand at worst, and an average of five hundred and a half only if every present id is equally likely. Insertion sort made 999 comparisons on a sorted list, 499,500 on a reversed list and 258,975 on one shuffled list. The lesson shows how to name the case, state the distribution behind an average, and why an early exit helps the best case and leaves the worst case alone.
Your monitoring system keeps a list of one thousand registered device ids.