Space complexity
How the memory an algorithm uses grows as the amount of data grows.
Example
Copying a list of 1,000 numbers uses 1,000 more slots: O(n). Adding it up uses 1 variable: O(1).
Test yourself: Space complexity
Space complexity
Which space is NOT usually counted in space complexity?
Adding up a list of 1 million numbers uses 1 extra variable: O(1). The input million was there before starting.
Space complexity
Which part of temporary space is usually ignored?
The code takes the same space with n = 10 as with n = 1 million. Frames and variables, on the other hand, can grow with n.
Space complexity
Why is the worst case used for space?
If at its peak it needs 2 GB and the machine has 1 GB, it crashes, even if the rest of the time it uses 10 MB.
0/3
â–¶ Play