There is a lot of information on time complexity analysis. For example, we know that for calculating the time complexity we study the number of operations (e.g. traversal, swapping, comparisons etc.) an algorithm performs.

I have not been able to lay my hands on the considerations for space complexity analysis.

Q) What are the main considerations in space complexity analysis?

  • $\begingroup$ For calculating the space complexity we study the number of memory locations (e.g. variables, arrays, data structures etc.) an algorithm uses. $\endgroup$
    – user16034
    Jul 16, 2022 at 9:12

1 Answer 1


Usually, when talking about Turing Machines - the space complexity refers to the furthest position the TM's head will reach in its entire execution for the given input. For every step further - another memory block can be used. (there are a few other alternative definitions, all of them use this basic one)

For practical terms, its not "crystal clear" but there are still a few rules:

  • Numbers, letters (not full strings however!) and all other "primitive" types are usually considered with $O(1)$ space (even though that's not entirely correct).
  • Lists with $n$ elements, or strings with $n$ letters - take $O(n)$ space
  • Any other data structure takes whatever memory needs for its components (for example, if we have a structure holding two lists, the first with $k_1$ elements and the second with $k_2$ elements - then the storage will take $O(k_1+k_2)$)
  • The total "space complexity" of a particular method is determined by the total space it allocated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.