# Time Complexity and Space Complexity

# Time Complexity

The time complexity is the runtime of the code, and it is expressed by big O notation. Big O notation means we only look at the highest exponent of the runtime, without considering its coefficients or other lower order terms.

For example, if the precise function of the time complexity of the code is:

` 5n² + 3n + log2(n)`

We would said it is O(n²), we do not consider its coefficient 5 and other lower terms such as 3n and log2(n).

When determine runtime of the code we should not memorize which big-O expression goes with a given algorithmic structure, we should count up the number of operations that the algorithm requires and compare that to the size of the input.

# Space Complexity

Storing values in variables always take memory (RAM), examples:

Most Primitives like numbers and booleans take O(1)/Constant Space

Strings, Arrays, and Objects take up O(n)/ Linear Space

**Time Complexity Prioritized Over Space Complexity**

The cost to produce and run processors are much higher compare to RAM. The speed is more important to users compare to RAM usage.