time complexity
Suppose two friends both promise to alphabetise a pile of exam papers for you. One finishes a stack of 100 in a minute; the other takes an hour. Knowing who is faster on one stack is not very useful. What you really want to know is how each one slows down as the stack grows: does doubling the pile double the work, or quadruple it, or make it explode? Time complexity is the study of exactly that. It is not about wall-clock seconds on a particular laptop, but about how the number of steps a procedure takes grows as the input gets bigger.
We make this precise with a machine model, usually a Turing machine (the endless notebook you can read, erase, and rewrite). The time complexity of a machine is a function T(n): for an input of size n, T(n) is the maximum number of steps the machine makes before halting, taken over all inputs of that size. Counting steps rather than seconds frees us from the speed of any one computer, and using the input size n as the variable lets us describe the whole family of inputs at once with a single growth curve, such as T(n) = 3n^2 + 5n + 2.
Time complexity matters because it is the yardstick of efficiency. Two algorithms can both be correct and both halt on every input, yet one finishes a realistic problem in seconds while the other would still be running when the sun burns out. Almost always we report the worst-case time and we describe it with big-O notation, keeping only the dominant growth term, because that is what tells us whether a method scales. The whole field of complexity theory is built on turning this intuition into something we can prove.
Scanning a list of n numbers once to find the largest takes about n comparisons, so its time complexity is roughly T(n) = n, written O(n). Comparing every pair of the n numbers to find the closest pair takes about n^2/2 comparisons, so T(n) is O(n^2). On a list of a million items the first does a million steps; the second does about five hundred billion.
Same input, two algorithms: the growth rate, not the constant, decides which one is usable at scale.
Time complexity describes how cost grows with input size, not the actual seconds on your machine; a faster computer shifts the constant but never changes the growth curve.