I am reading Cracking the Coding Interview and in the Big O chapter, there is an explanation on Amortized Time. The classic example of something such asn ArrayList needing to grow is used here. When an array needs to grow, insertion will take O(N)
time assuming it has to copy N elements to the new Array. This is fine.
What I don't understand is that as the array is doubled in capacity, why would an amortized time for each insertion be O(1)
From everything I understand, anytime you insert into an array, it is always an O(N)
operation. How is it different for Amortized Time? I'm sure the text is correct, I'm just not grokking the O(1)
amortized time concept.