Codele / Data structures
Big-O: measuring speed
Some jobs stay quick however much data there is. Others get slower and slower. We count steps to see how the work grows when the data grows.
- To compare ways of doing a job, count the steps and watch how the count grows as the data grows.
- O(1): always the same work, like jumping to a spot in an array.
- O(log n): halving each time, like searching a binary search tree. Doubling the data adds only one step.
- O(n): look at every item once, like walking a linked list. O(n²): compare every pair, and doubling the data makes it four times the work.
- This way of naming growth is called Big-O. It ignores small details and shows the shape of the growth.
Loading the playable lesson…