Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 1.22 KB

File metadata and controls

24 lines (18 loc) · 1.22 KB

Hash Tables

Terminology

  • Hashtable: a data structure - an array that stores key value pairs for a hash in 'buckets'
  • Hash: is a string that has been converted to a secure value that will be used as an index?
  • Buckets: stored in each index of the array of the hashtable array, each bucket can contain multiple key/value pairs
  • Collisions: when multiple keys end up being stored in the same index of the hashtable
  • Chaining: utilizes a linked list to store multiple key/value pairs at the same index, one way to resolve collisions

Uses

  • Hashtables are used to quickly store and retreive hash values
  • Efficient because the BigO is O(1) for looking up key/value pairs

How it works

  • referencing the index of the key/value pair directly is what makes hash tables efficient
  • a hash function is used place the key/value pair at a specific location
  • the hash function recieves the items key and generates the index where it should be placed in the hashtable
  • the function receives the key, and generates a number based on the key
  • this number is the bucket index/location for the key/value pair
  • the same key should generate the same bucket index/output
  • this index number allows quick reference with an efficiency of O(1)