Time Complexity vs Space Complexity
Time Complexity measures how the running time of an algorithm grows as a function of the size of its input, typically expressed using asymptotic notation like Big-O. It does not measure actual wall-clock time (which depends on hardware), but rather the number of fundamental operations performed relative to input size n.
Space Complexity measures how much additional memory an algorithm requires as a function of input size, including auxiliary space used for variables, recursion stacks, or temporary data structures, in addition to the input itself. In interviews, 'space complexity' usually refers to auxiliary space, excluding the space needed for the input.
Time complexity: growth of number of operations vs input size
Space complexity: growth of memory usage vs input size
Both are typically expressed with Big-O, Big-Theta, or Big-Omega notation
There is often a time-space trade-off, e.g., memoization trades space for time
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience