Hacker News new | ask | show | jobs
by ant6n 1795 days ago
But you know, hash tables have O(n) access...
2 comments

Some implementations have O(n) access in the worst case.

Often people are interested in something like the 99.9999%ile case. And, of course, you can design hash tables with better worst case behaviour.

It's almost trivial to get a hash table with O(log n) worst case access: when you have a collision, just resolve it with a tree instead of a linked list.

With some more fancy math, you can also get O(1) amortized worst case behaviour with arbitrarily high probability that doesn't depend on your input data.

And this is where interviewing gets hard. Are we really going to not hire someone because hash table is O(n) in the worst case but O(1) on average. It seems like half the time there isnt a match, the interviewer is just as wrong as the candidate, and they are looking for someone who knows the same info as them, even if its half baked.