FoundationsHow we measure cost
Before any data structure or algorithm, get three tools in place: Big-O to describe cost, recursion to think with, and amortised analysis to explain why something is "fast on average". Every complexity figure elsewhere on the site builds on these.
Why learn Foundations
Where it shows upGo from 100 rows to a million — ten thousand times the data — and an O(n²) program does a hundred million times the work, while O(n log n) does about thirty thousand times. Big-O lets you predict that before you write the code.
→ Lesson: Big-O NotationWhen the array fills up it has to move, and that one push is O(n) — but averaged out, each push is still constant time. Amortised analysis is how you talk about "occasionally slow, fast overall".
→ Lesson: Amortized AnalysisFolders contain folders; expressions contain expressions. Recursion lets you describe one layer and leave the rest to the same function. Trees, DFS, divide and conquer and DP are all built on it.
→ Lesson: Recursion