Suppose we have the function below:
def foo(nums):
nums = sorted(nums)
return nums
In our function, we overwrite our original parameter nums
, by storing the sorted version of the input in it.
My question is simple: does overwriting the input count toward auxiliary space occupation? More specifically, is the auxiliary space of our function O(N)
or O(1)
?
I know this question is not very nuanced, but I cannot find a clear answer anywhere. I understand that sorted()
produces and stores a new version of the list. In this way, such an operation occupies O(N)
space, where N
is the length of the input list.
However, since we are overwriting the input, which already held a list of size N
, do we still consider this operation occupying additional O(N)
space?