What is time complexity?
Time complexity is a way to assess how an algorithm's running time changes depending on the size of the input data (n). It shows the growth rate of the number of operations, not the actual time in seconds.
Why it is needed
It allows algorithms to be compared regardless of the computer, language, and implementation. In other words, it answers the question:
What happens if the data grows by a factor of 10, 100, or 1,000,000?
How it is expressed
Big-O notation is used - (O(1), O(\log n), O(n), O(n \log n), O(n^2)) and so on.
For example:
- (O(1)) - the time does not depend on the data size (constant)
- (O(n)) - the time grows linearly
- (O(n^2)) - quadratic growth (becomes very slow on large data)
What exactly is measured
The count is of basic operations:
- comparisons
- memory accesses
- arithmetic operations
- iterations
What matters is not the exact number, but how it grows as n increases.
Summary
Time complexity answers the key question:
how much does the algorithm slow down as the volume of data grows?
It shows whether an algorithm will scale or will "die" on large input data.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.