Skip to content

Hash Tables

Devrath edited this page Feb 13, 2024 · 5 revisions

Defining HashTable

  • Hash Tables are used for very fast insertion and retrieval of data.
  • The adding and retrieval of data happens in constant time.
  • It is the collection of key and value pairs.
    • Key can be any type of object and necessarily need not have to be a number.
    • Value can also be any type of object.

Sample use-case

  • Consider a collection of records, where the user object consists of properties like name,age,email
  • Here we can use the email field as the key for each object.
  • You pass a key as an email to the HashTable collection, It will return the corresponding employee.

What other collection returns data in constant time ----> Arrays

  • We know that in arrays, when we pass the index we can get the value in constant time.
  • But here we can pass only the integer as a key and we can't pass any other type here.
Clone this wiki locally