How is time complexity measured?
Not in seconds, but in how the work grows as the input size n grows. NIST describes big-O notation as a theoretical measure of the execution of an algorithm, usually the time or memory needed, given the problem size n [1]. Formally, f(n) = O(g(n)) means that past some value k, f(n) never exceeds a fixed constant c times g(n) [1]. So n² + 3n + 4 is O(n²), because it stays below 2n² for every n above 10 [1].
Any such measure depends on a model of computation. What gets counted might be comparisons, floating-point multiplications, disk accesses or network messages [1].
Why does the difference matter in practice?
NIST's own example: quicksort, at O(n log n) on average, can beat bubble sort at O(n²) on large inputs even when it runs on a slower machine [1].
A concrete case from Python: the bisect module finds where a new item belongs in a sorted list in O(log n), but the insertion itself is O(n), so insertion dominates the total cost [2]. Likewise, pop(0) on a list costs O(n) in memory movement, while collections.deque handles both ends at roughly O(1) [3].
Does Big O give the exact running time?
No. Big O is an upper bound. Strictly speaking 3n + 4 is also O(n²); the notation is often misused to mean "equal to", and Θ(n) is the notation for that tighter claim [1]. The constant c in the definition also means constant factors drop out of the picture [1].