Hash Map Flashcards

1
Q

Properties of Hash Maps

A

Not sorted
Unique keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Hash Map time complexity

A

Search, insert, delete all O(1)
Building a Hash Map is O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Time complexity vs others

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Hash Map implementation

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly