Saturday, 23 April 2016

What is Space Complexity ?


Space Complexity

Space Complexity of an algorithm is total space taken by the algorithm with respect to the input size.
Space complexity = Auxiliary space + Space used by input

For example, if we want to compare standard sorting algorithms on the basis of space, then Auxiliary Space would be a better criteria than Space Complexity.
Example
Merge Sort uses O(n) auxiliary space (extra space)
Insertion sort and Heap Sort use O(1) auxiliary space.
Space complexity of all these sorting algorithms is O(n) though.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.