Recall our implementation of the ArrayBag class that used a dynamic resizing str
ID: 3801706 • Letter: R
Question
Recall our implementation of the ArrayBag class that used a dynamic resizing strategy for the underlying array. Specifically, the add method checked to see if the array was full and used the resize method to double the capacity of the elements array, as shown below. public boolean add (T element) {if (isFull ()) {resize (size * 2);} elements [size] = element; size ++ return true;} The resize method is O(N), but we said that the overall add method was O(1) by using what analysis technique? A. best case analysis B. worst case analysis C. amortized analysis D. doubling analysisExplanation / Answer
C) Amortized analysis because, In an amortized analysis, the time required to perform a sequence of data-structure operations is averaged over all the operations performed.
Note: The term averaged
So That is why Add becomes O(1) because on an average it adds using O(1)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.