38/40
Part 7 of 7 · Follow-upsLearn and do
What's the complexity?
Say both cases. With ordinary keys, n lookups cost O(n) on average. If someone else can choose the keys, or a custom __hash__ is poor, the worst case is O(n) per lookup.
Then add the key's own cost, which people forget. Hashing a string or a file is O(length).
The duplicate finder costs O(n) to count n sizes, plus O(S) to hash the S bytes in files whose size is shared.
In the editor, write bytes_hashed(sizes): S, the total bytes of every file whose size at least one other file shares. For sizes 17, 17, 17, 10, 10, 10, 9000 and 0 that's 3 × 17 + 3 × 10 = 81. Count the sizes first.