Loading section...

Reading Complexity at a Glance

You do not need to run timing experiments every time you want to know if code will scale. Experienced data engineers glance at code and immediately identify its complexity class. This section teaches you the three simple rules that make that possible. Rule 1: Sequential Steps Add When steps run one after another (not nested), you add their complexities. Two sequential loops over n items contribute O(n) + O(n) = O(2n), which simplifies to O(n). It does not matter if you loop through the data twice or five times. The runtime still doubles when n doubles. Rule 2: Nested Steps Multiply When a loop is nested inside another loop, you multiply their iteration counts. But not all nested loops produce O(n²). If the inner loop runs over a different, smaller collection, the analysis changes. Rule 3: