👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
Note : If you haven’t read our article on temporal complexity , we recommend that you start there. Part 2 of this series assumes you know several possible Big O values.
In our first article on Big O scoring and temporal complexity , we are talking about the time it takes for the algorithm to complete as its input increases. This is important when interacting with very large datasets. A large dataset combined with a fair amount of time complexity leads to more efficient algorithms. However, there is another aspect of Big O notation that must be taken into consideration: The complexity of the space.
What is the space complexity
Time complexity and space complexity ? are similar with respect to the amount of input to an algorithm. When time complexity is related to quantity operations that an algorithm must perform to complete, spatial complexity is related to the total amount of space needed to complete the algorithm. Spatial complexity is expressed in terms of Big O notation.
Spatial complexity includes the amount of space needed for input and the auxiliary space needed in the algorithm for execution . Auxiliary space is the extra space used to store temporary or variable data structures used to solve the algorithm. Just like in time complexity, the Big O of an algorithm considers the worst case, or the asymptotic upper bound.
Calculating the space needed to run an algorithm
When calculating the spatial complexity of an algorithm, look at two things: the size of the input and the space auxiliary required to perform the function. In most cases, we are not reducing the size to the number of bytes of the entry - we are just looking at how much memory the entry or auxiliary space should use.