3. ArrayLists_outside

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

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

View Full Document Right Arrow Icon
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
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
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
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern