The Space Complexity of Sets
In discussing time or space complexity, we typically use the variable N to represent how many pieces of data we’re dealing with. In the context of sets, N would represent the number of elements our set contains.
A hash table set has a space complexity of O(N) since the hash table’s space is (constants aside) tailored to hold the set’s N elements in N cells.
However, with Boolean arrays and bit vectors, the number of values they represent corresponds not to the number of values in our set, but rather the range of possible set values. So, even if a set has five values, if those values fall in a range from 0 to 1000, our Boolean array has to hold 1,000 integers. To signify this, I’m going to use the variable R to represent ...
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