It is a collection of items which are stored in such a way as to make it easy to find them later.
Each position in the hash table is called slot, can hold an item and is named by an integer value starting at 0.
The mapping between an item and a slot where the item belongs in a hash table is called a Hash Function. A hash Function accepts a key and returns its hash coding, or hash value.
Assume we have a set of integers 54, 26, 93, 17, 77, 31. Our first hash function required to be as "remainder method" simply takes the item and divide it by table size, returning remainder as its hash value i.e.
Now when we need to search any element, we just need to divide it by the table size, and we get the hash value. So we get the O (1) search time.
Now taking one more element 44 when we apply the hash function on 44, we get (44 % 11 = 0), But 0 hash value already has an element 77. This Problem is called as Collision.
Collision: According to the Hash Function, two or more item would need in the same slot. This is said to be called as Collision.
Figure: using a hash function h to map keys to hash-table slots. Because keys K2 and k5 map to the same slot, they collide.
Why use HashTable?
So Hash Table requires less storage. Indirect addressing element with key k is stored in slot k with hashing it is stored in h (k) where h is a hash fn and hash (k) is the value of key k. Hash fn required array range.
Application of Hash Tables:
Some application of Hash Tables are: