I was wondering how the following two cases differ in space complexity.
Case 1: A = [i ** 2 for i in A]
Case 2: A[:] = [i ** 2 for i in A]
My understanding is that in both cases a new array is built (O(n)). In case 1, the reference is referring to the new array. In case 2, the reference is referring to what it was referring to, but its content is updated. Is it true?
Seems like you're right. Updating pre-allocated slots in memory takes longer time than initializing a new array.