book-notes

Chapter 5 - Hash tables

Suppose you work at a grocery store. When a customer buys an item, you have to look up the price in a book.

# of items Simple search Binary search Hash table
100 100 7 1
1,000 1,000 10 1
10,000 10,000 14 1

Hash function

Hash table

Use cases

Collisions

Average and worst case performance

| | Hash tables (average) | Hash tables (worst) | Arrays | Linked lists | | —— | ——————— | ——————- | —— | ———— | | Search | O(1) | O(n) | O(1) | O(n) | | Insert | O(1) | O(n) | O(n) | O(1) | | Delete | O(1) | O(n) | O(n) | O(1) |

Load factor

A good hash function

Recap