memory usage for n = 8
O(1)Constant — swap variables1 unit
O(log n)Logarithmic — recursive binary search3 units
O(n)Linear — copy of input array8 units
O(n²)Quadratic — 2D DP table64 units
Space complexity measures extra memory an algorithm uses as input grows.
Unlike time complexity, space only counts additional memory — not the input itself.
start
1 / 10
SPD0.5×
click to pause · hover for controls · fullscreen for more
Space Complexity
Watch memory grow — O(1), O(n), and O(n²) side by side
Visual by thisgirltech
BeginnerConcept