Finding Duplicates Revisited
Chapter 12, Saving Space: Every Bit Helps opened with the problem of how to find duplicates in an array of data. The problem was simple enough: write a function that, given an array, returns True if there are any duplicate elements, and False if there aren’t. Using the brute-force approach, we grind along in O(N2) time, but we discovered that if we use a set to track what elements we encounter along the way, we can solve our problem at a brisk O(N) pace.
We also explored various options in selecting the right data structure for our set. Hash tables and bit vectors both gave us the O(N) result we were looking for, but bit vectors took up a lot less space than hash tables. However, we also learned that bit vectors ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access