Suppose you have an interface like so (Java example):
interface ImmutableMap<K,V> {
V get(K key);
}
One way to implement it would be to use a hash table (HashMap), which gives O(1) average performance assuming a good hash function, and O(n) worst case.
However a hash table is mutable - it also allows removing and putting elements in the map - which may mean compromises are being made in the performance of get
, for the sake of making put
and delete
faster.
So the question is - what improvements could be made for just implementing get
- perhaps O(1) worst case, or just better general performance (e.g. by a factor of 2) if not asymptotically faster?