Create a linked list with a set of k arrays that represent hash tables.
According to the idea of ββthe first site, let the hash tables be 1, 4, 9, 16, 25, 36, 49, ... elements in size.
Thus, the data structure contains N=k*(k+1)*(2*k+1)/6=O(k^3) (this is the result of the well-known summation formula for adding squares) of elements with k hash tables.
Then you can sequentially search each hash table for elements. Hash validation, insertion, and deletion operations work in O(1) time (assuming a separate chain so that deletions can be processed correctly), and since k<sqrt(N) (actually less than the cubic root), this meets the requirements time of your algorithm.
If the hash table is full, add the sitelink in the linked list. If the hash table is empty, remove it from the list (add it if necessary later). Inserting / deleting a list is O(1) for a doubly linked list, so this does not affect the time complexity.
Note that this improves other answers that offer a direct hash table because rewriting is not required as the data structure grows.
source share