Big O
A way to say how much an algorithm's work grows when the data grows.
Example
Searching a list of 1,000 items one by one is O(n): up to 1,000 steps. With binary search it's O(log n): about 10 steps.
Test yourself: Big O
Big O notation
Going through a whole list 1 time is…
To search a 1,000-element list one by one, in the worst case you look at all 1,000: O(n).
Big O notation
O(1) means time doesn't depend on the size of the data.
Constant time: it takes the same with 10 or with 1 million elements.
Big O notation
Which of these tasks is O(n)?
Summing 1,000 prices takes 1,000 additions: it grows just like the data.
0/3
â–¶ Play