{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Array based implementation use an array a of size n a

Info iconThis 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
Background 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
Background 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
Background 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  
Background 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 ]}