Complexity analysis
Estimating, without running the code, how an algorithm's time and memory grow as the amount of data grows.
Example
Without testing anything, you know 2 nested loops over 1,000 items do 1 million steps, and over 2,000, 4 million.
Test yourself: Complexity analysis
Measuring efficiency
What's a problem with measuring an algorithm by running it?
The same code can take 2 seconds on a 10-year-old computer and 0.2 on a new one: the number says more about the machine than the algorithm.
Measuring efficiency
Complexity analysis describes how time and memory grow as the input's ___ grows.
What matters isn't which data, but how much: with 1,000 elements an O(n) algorithm does 1,000 steps; with 2,000, twice as many.
Measuring efficiency
What's an advantage of complexity analysis over running the code?
Saying "O(n²)" holds on a laptop or a 64-core server: with 10 times the data, 100 times the work on both.
0/3
â–¶ PlayLessons that use it
Clusters
Many machines, one system
Proxies
A middleman in between
Scaling
Bigger or more machines
Big O notation
How much does it grow?
Measuring efficiency
Fast and light on memory
Time complexity
Count steps, not seconds
Memory and cache
Close is fast
Searching with a hash
From O(n²) to O(n) with a table
Choosing how to search
Brute force or using the order
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
Divide and conquer
Split, solve and combine
NoSQL databases
Beyond tables
Replication
Copies of the database
Sharding
Splitting the database into pieces
Database federation
Several databases that look like one
N-tier architecture
An app in floors
Message brokers
A middleman for messages
Monoliths and microservices
1 block or many pieces
Microservices done right
Microservices without traps
Event-driven architecture
Announcing what happened
CQRS
Write on one side, read on the other
GraphQL and gRPC
Other ways to talk to an API
Real time: long polling, WebSockets and SSE
Letting the server speak first
