To answer this question,we must fist know what is 'in place algorithm'?
By the wikipedia, an in-place algorithm is an algorithm which transforms input using a data structure with a small, constant amount of extra storage space.
What's the relationship between 'Overwrite input' and 'in place algorithm':
1. If one overwrite it's input, isn't it must an in place algorithm?
No, for example, the quicksort always overwrite it's input, but it need O(log(n)) extra space to keep track of the recursive function calls.
2. If one is an in place algorithm, does it must overwrite its input?
No, for example, the algorithm that find the minimum number in an array, it's an in place algorithm, only require O(1) extra space, but it need not to overwrite its input.
So, there is no absolute relationship between them, the input is usually overwritten by a in place algorithm.
And how to know if a method in an in place algorithm?
Well, I think you must look at it's implementation, the source code, the same method may use the different algorithm, after all, methods or functions are not the same thing as algorithms.
BTW, there is an easy way to know if the input of an method is overwritten:
>>> lst = [1, 2, 3]
>>> id(lst)`
3070142764
>>> lst = lst[: : -1]
>>> id(lst)
3070142828
>>> lst.reverse()
>>> id(lst)
3070142828
After lst[: : -1]
, the id of lst has changed, so lst[: : -1]
create a new list object, and after lst.reverse()
, the id of lst isn't changed, so lst.reverse()
overwritten its input.