Must a hash table be implemented using an array? Will an alternative data structure achieve the same efficiency? If yes, why? If no, what condition must the data structure satisfy to ensure the same efficiency as provided by arrays?
Must a hash table be implemented using an array? Will an alternative data structure
Share
No. You could implement the
HashTableinterface with other datastructures besided the arrray. E.g. a Red-Black tree (java’s TreeMap).This offers
O(logN)access time.But
Hash Tableis expected to haveO(1)access time (at best case – no collisions).This can be achieved only via an array which offers the possibility of random access in constant time.
Must have a comparable performance (less than
O(N)) with an array. A treemap hasO(logN)worst access time for all operations