3. ArrayLists_outside

# Run in o n time in worst case if we use the array in

This preview shows pages 7–10. Sign up to view the full content.

run in  O ( n )  time in worst case If we use the array in a circular fashion,  operations insert (0, x )   and  erase (0, x )   run in  O (1)  time In an  insert   operation, when the array is full,  instead of throwing an exception, we can  replace the array with a larger one ©  2010 Goodrich, Tamassia

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Array Lists 8 Growable Array-based Array  List In an  insert(o)  operation  (without an index), we always  insert at the end When the array is full, we  replace the array with a  larger one How large should the new  array be? Incremental strategy : increase  the size by a constant  c Doubling strategy : double the  size Algorithm insert ( o ) if t = S.length - 1 then A new array of size … for i 0 to n - 1 do A [ i ] S [ i ] S A n n + 1 S [ n - 1] o ©  2010 Goodrich, Tamassia
Array Lists 9 Comparison of the Strategies We compare the incremental strategy and  the doubling strategy by analyzing the total  time  T ( n )  needed to perform a series of  n   insert(o) operations We assume that we start with an empty stack  represented by an array of size  1 We call amortized time of an insert operation  the average time taken by an insert over the  series of operations, i.e.,   T ( n )/ n ©  2010 Goodrich, Tamassia

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern