Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 1
    Sorry, I know this is an old question/answer, but I've been trying to understand this last point you make. A hash table has O(1) time complexity. However, once you use a sparse array, aren't you left needing to do a binary search to find your value? At that point doesn't the time complexity become O(log n)? Commented Apr 28, 2016 at 14:50
  • @herbrandson: no... a sparse array simply means relatively few indices have been populated with values - you can still index directly to the specific array element for the hash value you've calculated from your key; still, the sparse array implementation Simon describes is only sane in very limited circumstances: when bucket sizes are of the order of memory page sizes (vs. say int keys at 1-in-1000 sparseness and 4k pages = most pages touched), and when the OS treats all-0 pages efficiently (so all-unused-bucket pages don't need backing memory), when address space is plentiful.... Commented May 2, 2016 at 2:39
  • @TonyDelroy - that's true it is oversimplification but the idea was to give a overview of what they are and why, not a practical implementation. The details of the latter are more nuanced, as you nod to in your expansion.
    – simon
    Commented Feb 13, 2019 at 21:10