AlgoViz

O(1) constant space

easy 14 min

O(1) space means an algorithm uses a fixed amount of extra memory, a few variables, no matter how large the input is.

Six O(1) space techniques

Read it, run it, change a line and run it again.

Loading editor…

Every function keeps a fixed handful of variables (pointers, a temp, a tracker) and never allocates anything sized by n. The in-place ones modify their argument.