Hash Table

Harsh chandrakar
2 min readMar 7, 2022

--

This is one of the most common data structures asked in interview questions and hashes are important all across computer science you can see them on databases, caches and you can see them in many places as well. over here I will cover the difference between a hash table and the array, how the hash table is useful? so let's begin with the topic

Difference between the hash table and array

hash table has different names on different programming languages like in javascript its object, python its dictionary and etc. arrays have different names as well like in python it is the list. the basic difference between them is

Array:

  • fixed-size
  • Have indexes which are numbers, and values that are elements in the array
  • Each item is placed next to the other in a cell in memory. Elements are in order
  • To search for an item, we need to loop through the array
  • When insert an item (similar to when we delete an item), it will shift other elements and change the index numbers and change the array length.
  • Take less memory because we don’t need to store value for each item

Hash Table: is also called hash map, map, unordered map, dictionary, object, etc…

  • No size limit
  • We can set key and value pairs. Keys are properties of an object, and values are what we assign to the keys
  • There is no concept of order. Items are placed all over places
  • To search for an item, we don’t need to loop through other elements
  • When inserting an item (similar to when we delete an item), it doesn’t change the values of other keys
  • Take more memory because we need space to store value for each key

Time complexity diffrence

--

--

No responses yet