What he will do is take each item after the end of the range of items to remove and move it in the list by the number of items deleted. As for performance indicators, after the end of the range of moved items, one copy will be displayed for each item. This means that it will work best when removed from the end (this will be O (1)) and worst when deleted from the beginning (O (n)).
As an example, consider the following list:
index - value
0 - A
1 - B
2 - C
3 - D
4 - E
5 - F
6 - G
If we call RemoveRange(2, 2) then we remove the two elements starting at index 2, so we remove C and D.
This means that E needs to be copied to index 2, then F needs to be copied to index 3, and G needs to be copied to index 4. For each element after one last element there is one copy operation.
Please note that due to the fact that you can move the entire memory block “up” by two, it becomes more efficient in practice when copying each element individually. It is much easier for computer memory to move the entire memory block by a fixed number of bytes than to move many small sections of memory to different arbitrary locations. However, it will have the same asymptotic complexity.
Servy source share