Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Hash Table Implementation

Objec­tive : To imple­ment a Hash Table

Input:  A set of pairs of keys and values

Approach:

    • Cre­ate a Hash Table
      • Hashtable<Integer, String> ht = new Hashtable<Integer, String>();
    • Insert val­ues in hash table using put(key,value)
      • ht.put(key, value);

  • Get val­ues from hash table using get(key)
    • ht.get(key);
hash table

hash table

Advan­tage : The search time for any ele­ment is O(1) since it uses key to find an ele­ment so it takes con­stant time. But draw­back is that it takes extra space.

Com­plete Code:


Out­put:

All values inserted
Employee with ID 1 is Sumit
Employee with ID 3 is Rishi

You may also like...