Today's interview was suddenly asked about the specific implementation of HASHMAP, a face of the feeling of a confused force, usually used is just a direct new a hashmap, and then put (Key,value), get (key) and remove (key) operation, suddenly asked the principle, So I still need to mend it.
Let's start by talking about some common data structures
(1) Array: Array words generally need to open up a continuous space, so occupy a serious memory, space complexity is very large. But it is convenient to find, can use binary search, the complexity is probably O (l). Of course, the delete and insert operations are more complex because the elements need to be moved
(2) linked list: Do not need continuous storage space, can be discretized storage. So the memory is relatively loose, the space complexity is very small. However, finding the words is more complicated and needs to be traversed from head to determine if the elements are needed.
(3) Stack: Stack words are actually extended from the vector, and vector is implements the list of this interface, so in fact, the stack is based on a linked list to achieve. However, due to its particularity, there are only push (object) and pop () two functions, so the time complexity of the operation is also O (1).
(4) HashMap: This is the next point. Since the array is convenient to find, and the storage of the list is convenient, there is no way, can combine the advantages of both. This is how HashMap is implemented.
Java--hashmap