3. ArrayLists_outside

Array based implementation use an array a of size n a

Info icon This preview shows pages 4–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Array-based Implementation Use an array  A  of size  N A variable  n  keeps track of the size of the array list  (number of elements stored) Operation  at ( i ) is implemented in  O (1)  time by  returning  A [ i ] Operation  set ( i,o ) is implemented in  O (1)  time by  performing  A [ i ] = o A 0 1 2 n i ©  2010 Goodrich, Tamassia
Image of page 4

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

View Full Document Right Arrow Icon
Array Lists 5 Insertion In operation  insert ( i , o ), we need to make room  for the new element by shifting forward the  n - i   elements  A [ i ], …, A [ n - 1] In the worst case ( i = 0 ), this takes  O ( n )  time A 0 1 2 n i A 0 1 2 n i A 0 1 2 n o i ©  2010 Goodrich, Tamassia
Image of page 5
Array Lists 6 Element Removal In operation  erase (i), we need to fill the hole left by the  removed element by shifting backward the  n - i - 1   elements  A [ i + 1], …, A [ n - 1] In the worst case ( i = 0 ), this takes  O ( n )  time A 0 1 2 n i A 0 1 2 n o i A 0 1 2 n i ©  2010 Goodrich, Tamassia
Image of page 6

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

View Full Document Right Arrow Icon
Array Lists 7 Performance In the array based implementation of an array  list: The space used by the data structure is  O ( n ) size empty at   and  set   run in  O (1)  time insert   and  erase  
Image of page 7
Image of page 8
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