Be the first user to complete this post

  • 0
Add to List
Beginner

3. Hash Table - Java

Objective: To implement a Hash Table

Input:  A set of pairs of keys and values

Approach:

  • Create a Hash Table
    • Hashtable<Integer, String> ht = new Hashtable<Integer, String>();
  • Insert values in hash table using put(key,value)
    • ht.put(key, value);
  • Get values from hash table using get(key)
    • ht.get(key);
hash table
hash table

Advantage: The search time for any element is O(1) since it uses the key to find an element so it takes constant time. But the drawback is that it takes extra space.

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