Why is the time complexity of Python’s list.append() method O(1)?
It’s amortized O(1), not O(1). Let’s say the list reserved size is 8 elements and it doubles in size when space runs out. You want to push 50 elements. The first 8 elements push in O(1). The nineth triggers reallocation and 8 copies, followed by an O(1) push. The next 7 push in O(1). The … Read more