Unit 06

Hashing

What if you could jump straight to a value without searching or traversing anything? A hash function turns a key into an address, getting you close to that ideal.

"apple" hash(key) apple "apple" always hashes to the same bucket — no scanning needed to find it again

// the hash function decides exactly where a key lives

What it is

A hash table stores key-value pairs. A hash function converts each key into a number (an index), which tells the table exactly which "bucket" to store the value in. Looking up a key later just means running it through the same hash function and going straight to that bucket — no scanning required.

Why it's useful

Where it struggles

Time complexity

OperationAverageWorst case
InsertO(1)O(n)
LookupO(1)O(n)
DeleteO(1)O(n)

Quick check

← Graphs Next: Sorting Techniques →