Hash Map Flashcards
Properties of Hash Maps
Not sorted
Unique keys
Hash Map time complexity
Search, insert, delete all O(1)
Building a Hash Map is O(n)
Time complexity vs others
Tree Map is O(logn) for insert/delete while Hash Map is O(1).
Tree Map is O(n) for search while Hash Map is O(1)
Sorted array is O(n) for insert/delete and O(logn) for search.
Hash Map implementation
Backed by an array. Array indices are computed by hashing the keys. Hashing generates an integer based on the key. Modding(%) this integer by the size of the array produces an index that is guaranteed to be in-bounds. Collisions can occur and can be mitigated in a variety of ways including increasing the size of the array, chaining (storing a linked list of k/v pairs in under one key), and open indexing (putting it in the next open index).