Generally, the space complexity is O(1) for while loops, and O(n) for all other methods. In the recursion best case, however, where it’s terminated early, the space complexity can approach O(1).