Hash table
A structure that stores key-value pairs and finds a key in 1 step on average.
Example
Checking whether 1 user exists among 1 million with a hash table takes about 1 step.
Test yourself: Hash table
Hash tables
A hash table stores pairs of key and ___.
For example, the key 12836 with the value "Ana". Given the key 12836, the table returns "Ana" in 1 step.
Hash tables
Walking every element of a hash table costs O(___).
You have to visit each one: with 10,000 pairs, 10,000 steps. What's O(1) is looking up 1 key.
Hash tables
You want to count how many times each word appears in a 100,000-word book. What do you use?
Each word adds 1 to its counter in O(1): 100,000 steps in total. With an array, searching each word among those already seen could be billions.
0/3
â–¶ PlayLessons that use it
Big O notation
How much does it grow?
Measuring efficiency
Fast and light on memory
Space complexity
How much memory it asks for
Types of structures
How they relate and where they live
Arrays
Adjacent cells
Linked lists
Links of a chain
Hash tables
From key to slot in 1 calculation
Hash collisions
When 2 keys want the same spot
Hash algorithms
A good hash spreads evenly
The k largest
Keep the best without sorting everything
Graphs
Points and connections
Graph operations
Adding and removing vertices and edges
Walking a graph
BFS and DFS, now with cycles
Searching with a hash
From O(n²) to O(n) with a table
Choosing how to search
Brute force or using the order
Rebuilding a tree
Root, left and right
Permutations
Every possible order
