šļø Memory Tower
0
Memory Gems Used
O(1)
Space Complexity
Variables
(O(1) each)
(O(1) each)
Arrays
(O(N) each)
(O(N) each)
Recursion Stack
(Depth = O(?))
(Depth = O(?))
Objects/Matrices
(O(?) each)
(O(?) each)
Variable (1 gem)
Array (N gems)
Recursive Call
Object/Matrix
š» Current Code
Select a scenario to see the code...
š Understanding Space Complexity
Space complexity measures the total memory used by an algorithm:
- O(1): Fixed number of variables, regardless of input size
- O(N): Memory grows linearly (e.g., creating array of size N)
- O(N²): Memory grows quadratically (e.g., NĆN matrix)
- Recursion: Each call adds to the call stack - depth determines space!