Index
An auxiliary data structure that lets you find rows without scanning the whole table. It speeds up reads.
Analogy
Like a book's index: you jump straight to the page instead of reading the whole book.
Test yourself: Index
Measure and optimize
What does adding an index cost?
A 1-million-row table with 3 indexes: each write updates the table and the 3 indexes, so 4 writes instead of 1.
Measure and optimize
Without an index, how many rows might the database check to find 1 email among 1 million?
Without an index the database reads row by row. If the email is at the end, or doesn't exist, it checks all 1,000,000.
Dense and sparse indexes
What is a database index like?
Instead of flipping through 500 pages, the index says 'page 312' and you go straight there.
0/3
â–¶ PlayLessons that use it
How DNS works
The internet's phone book
Big O notation
How much does it grow?
Space complexity
How much memory it asks for
Arrays
Adjacent cells
Queues
First in, first out
Deques
In and out at both ends
Trees in an array
No references, just math
Binary search trees
Smaller on the left, larger on the right
AVL trees
A tree that straightens itself
Heaps
The smallest, always on top
Building a heap
Bottom-up is cheaper
Binary search in depth
2 pointers closing in
Boundaries with binary search
Where to insert and where a run starts
Searching with a hash
From O(n²) to O(n) with a table
Choosing how to search
Brute force or using the order
What makes a good sort
5 things you ask of it
Selection sort
Picking the smallest, over and over
Bubble sort
The largest rises like a bubble
Insertion sort
Like arranging the cards in your hand
Quick sort
A pivot and 2 sides
Heap sort
Take the maximum and leave it at the end
Counting sort
Sorting by counting
Rebuilding a tree
Root, left and right
Subset sum
Groups that add up exactly
Solving with DP
State, transition and borders
Unbounded knapsack and coins
Repeats are allowed
Largest container
Move the shorter board
Databases
Where data is kept
SQL databases
Tables that relate
NoSQL databases
Beyond tables
SQL or NoSQL
Picking the right database
Measure and optimize
Measure first
Dense and sparse indexes
The book's index
Geohashing
A place in a few letters
The design steps
From data to bottlenecks
Designing Twitter
1 billion tweets a day
Designing Uber
10 million rides a day
