0
$\begingroup$

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?

$\endgroup$
0
$\begingroup$

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
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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