Uploaded by Rahul Kumar Sinha

1Advantages and Disadvantages for using HashTabel

advertisement
Advantages and Disadvantages
for using HashTabel
Ankit tanwar(046)
Hashtable stores key/value pair in hash table. In Hashtable we
specify an object that is used as a key, and the value we want to
associate to that key. The key is then hashed, and the resulting
hash code is used as the index at which the value is stored
Advantages
• Hash tables have high performance when looking
up data, inserting, and deleting existing values.
• The time complexity for hash tables is constant
regardless of the number of items in the table.
• They perform very well even when working with
large datasets.
The main advantage of hash tables over other table data
structures is speed. This advantage is more apparent when the
number of entries is large. Hash tables are particularly efficient
when the maximum number of entries can be predicted, so that
the bucket array can be allocated once with the optimum size
and never resized.
If the set of key–value pairs is fixed and known ahead of time (so
insertions and deletions are not allowed), one may reduce the
average lookup cost by a careful choice of the hash function,
bucket table size, and internal data structures. In particular, one
may be able to devise a hash function that is collision-free, or
even perfect. In this case the keys need not be stored in the
table.
While the advantages of hash table is same when we talk
about insertion, deletion or searching of an element, there's
a huge advantage that hash table has over address table,
which is that it maintains the size constraint. Let us consider
a key = 7898789, which in turn is a large number, if we
insert this in a direct address table, then we are wasting too
much space as we will have to find this location(key) and
then insert the value at that location, but in case of a hash
table we can process this key via a hash function, say it
yields us = 17, now we are only left with inserting at
position(17) of the hash table.
Disadvantage
• You cannot use a null value as a key.
• Collisions cannot be avoided when generating keys using. hash
functions. Collisions occur when a key that is already in use is
generated.
• If the hashing function has many collisions, this can lead to
performance decrease.
Although operations on a hash table take constant time on
average, the cost of a good hash function can be significantly
higher than the inner loop of the lookup algorithm for a sequential
list or search tree. Thus hash tables are not effective when the
number of entries is very small. (However, in some cases the high
cost of computing the hash function can be mitigated by saving
the hash value together with the key.)
For certain string processing applications, such as spell-checking,
hash tables may be less efficient than tries, finite automata, or
Judy arrays. Also, if there are not too many possible keys to
store—that is, if each key can be represented by a small enough
number of bits—then, instead of a hash table, one may use the
key directly as the index into an array of values.
Download