Table of Contents

Description

Think of a hash table as a dictionary. You want to find all the information you can on a word - its spelling, pronunciation, definition, synonyms, etc. But you don’t want to read through every page of the dictionary until you find the word. Instead, you can take the first letter of the word and go to that part of the book. All you need is the first letter of the word, and you can find all the info you want about the word really quickly.

![Untitled](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b351554b-ea91-402d-a544-61e0a94a1766/Untitled.png>)

Usage

Implementation

Standard Implementation: Array of Linked Lists

![Untitled](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a5fc34cf-e224-4923-9cd2-a384a178ca1f/Untitled.png>)

![Untitled](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/33c64f3d-1254-48db-b2ae-c168cf5ec0c3/Untitled.png>)

- One linked list for each hashed version of a Key
- The value paired with the key is placed into the linked list as a node.
- Insertion process
    - Key-value pair inserted
    - Key is hashed, converted to hashcode
    - Hashcode is converted to index in array
    - Value paired with the key is inserted into the linked list at that index.
- Collisions
    - Sometimes two different keys have the same hashcode. This is called a collision.
    - Their values are placed into the same linked list.
    - Linked lists are small compared to the array, so resolving collisions by searching the linked list is fast compared to searching the whole array.
        - O(1) vs O(N)