Math Fundamentals18 sections · 814 units
Open in Course

How to Analyze Code

(Counting loops)

To find Big O, count nested loops. One loop is O(n). Two nested loops are O(n²). Three nested loops are O(n³).

If a loop halves the range each iteration, it is O(log n). If you recurse and combine results, add up the work at each level.

Sequential operations add. Nested operations multiply. Take the dominant term.