For a place that claims to be culturally diverse, I realized there was a hidden list of acceptable cultures, and mine was not one of them. I politely declined the offer and decided to stay a bit closer to home.
For a place that claims to be culturally diverse, I realized there was a hidden list of acceptable cultures, and mine was not one of them. I politely declined the offer and decided to stay a bit closer to home.
Maybe its just a different flavor of Kool-Aid. Cynicism about X is often as much of an irrational orthodoxy as X is.
This doesn't invalidate your experience at all - the interviewer may or may not have been talking about this, and there may well be cultural issues there - but I learned this interesting distinction recently, figured I would pass it on.
Just the growth of the operations performed.
In the real world, it may thus be better to use a computationally more complex algorithm than a computationally simpler one in certain cases, if you happen to have a system that delivers big enough optimizations for the complex algorithm.
Anyone who said that to me would seriously risk a sock to the jaw from my non-Stanford educated fist, interview or no. That is an incredibly rude and condescending thing to say.
Thankfully that guy didn't interview me during my interview at Google, and my fist remained wrapped around my dry-erase marker instead.
Many young skinny-jeans-wearing progressives here quite openly harbor grossly ignorant steroetypes of a wide variety of unacceptable cultures: the south, the midwest, Republicans, Christians, and conservatives, among others.
When challenged, they typically deny that their cartoonish, caricatured views of these groups are stereotypes, and insist that that's simply the way it is.
Just wearing a button-down shirt (or, God forbid, a tie) is more than enough to stigmatize you as "one of them" and get you instantly ostracized (while they simultaneously loudly trumpet the value of diversity and tolerance.)
> cartoonish, caricatured views of these groups are stereotypes
I cannot tell if this is satire.
It's a dumb question to be authoritative about because there are different implementations of hashmap and hashcode meaning that you can't guarantee the runtime complexity.
According to the SO answer above Java8 will be mostly O(1) but full buckets may be stored as trees meaning that they will be O(log n). But as the answer says
"So no, O(1) certainly isn't guaranteed - but it's usually what you should assume when considering which algorithms and data structures to use."
The interviewer could have explored the candidates knowledge of how hashmap is implemented, or could be implemented, which would be more rewarding than insulting and gloating.
I think the big misunderstanding in most of these answers is assuming a fixed amount of buckets are used in Java's implementation. That is not correct, the put() method will rehash your table if it grows too big. (meaning that on average put() is O(1) but has a very real possibility of being O(n).
Is the n in log2(n) the size of thing you're hashing? AFAIK the O(1) statement is referring to how many things you have hashed.
Calling a hash table O(log2(N)) gets misleading when you measure a hash function's performance, and it doesn't change as the table grows.
So you're right about your technicality, but you're using big-O slightly differently than how everyone else is using it.
The implications are interesting, in that if the hash computation did grow as O(log2(N)), then it would (theoretically) outperform the current typical O(1) hash table implementation, and they would meet only when the table is full.
Another way to see O(1) is that hash computation is always implemented not as a log2(N) function, but is log2(MAX_N), where MAX_N is the size of a full table, and since MAX_N is a constant, the complexity is O(1).
A side note is that not all hash tables are implemented using an array that can hold N items. Some hash tables use linked lists instead of re-hashing for collisions, meaning that your array can be arbitrarily less than N in size, meaning that it is definitely possible to have a hash function that takes less than log2(MAX_N) time. In that case, insertion time becomes explicitly greater than O(1).
"The implications are interesting, in that if the hash computation did grow as O(log2(N)), then it would (theoretically) outperform the current typical O(1) hash table implementation, and they would meet only when the table is full."
How would O(log n) ever out perform constant time, O(1)? Could you elaborate?
In this case, if your hash always takes 64 bit values and always produces 64 bit values, it is O(1). If your hash were O(log2(N)), then your hash function with an empty table would do 1 bit worth of work, and would do only one operation. But when the table grew to contain 1,000 elements, it would do 10 bits worth of work.
The O(log2(N)) algorithm with N < 2^64 is always faster (in theory) than the O(1) algorithm that does a constant 64 bits of work.
The O(1) algorithm pays off in spades for N >> 2^64, it will become much faster than the logarithmic one, but for small N, log(N) is smaller than 64.
I usually think of hashtables though as being O(1) in referring to the look up(amortized) and not the hash code itself.
It is O(1) if the hashmap is sparsely populated but if there are hash collisions the items are stored in a list (tree from 8) so is not O(1) in worst case
With a finite number of buckets (which is inherent to hashmap), asymptotic performance will never conform to the "sparsely populated" constraint, so its O(n).
(That its concrete performance is roughly constant-time within certain size bounds in non-pathological cases is important knowledge, too, though.)