|
|
|
|
|
by justinhj
3543 days ago
|
|
http://stackoverflow.com/questions/4553624/hashmap-get-put-c... 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. |
|