Hot answers tagged


Since the data structure is only created once, you can simply use an array ordered by the key. Each element in the array contains the key-value pair. Sorting the array is O(n*log(n)), which will be fast for 4e6 items and only needs to be done once. You can then use binary search (which is O(log2(n) or ~22) on the array to find the key. If not found, ...

Only top voted, non community-wiki answers of a minimum length are eligible