AI engineering glossary · Data structures algorithms
What is space complexity?
Space complexity: The amount of extra memory an algorithm needs as a function of input size, usually not counting the input itself. It matters when data is large or memory is limited, such as on a phone or a small server.
Space complexity: an example
Reversing a list by building a new list uses O(n) extra space. Swapping elements from both ends within the same list uses O(1) extra space.
Related terms
More Data structures algorithms terms
- Space-time trade-off
- Stable sort
- String matching
- Tabulation
- Time complexity
- Timsort
- Top-K problem
- Topological sort
Where you learn it
Space complexity is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.