Suppose I have two lists with names a and b of both sizes n, and I want to perform the following operation to set a slice with k <n
a[:k] = b[:k]
The Python wiki Time Complexity page says that the complexity of setting the slice is O (n + k), where k is the length of the slice. I just can't understand why this is not just O (k) in the above situation.
I know that slicing returns a new list, so this is O (k), and I know that the list stores its data in continuous mode, so inserting an element in the middle will take O (n) time. But the above operation can be easily performed in O (k) time. Did I miss something?
Also, is there any documentation where I can find detailed information about such issues? Should I take a look at CPython implementation?
Thanks.
source share