Skip to main content
ICT
Lesson AB27 - Java Lists and Iterators
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

E. LinkedList vs ArrayList page 7 of 9

An important aspect of good programming is to choose the best data structure to solve a particular problem. Here are some advantages and disadvantages of using one versus the other — LinkedList vs ArrayList:

Operation LinkedList ArrayList
Searching Best performance is O(N) because the list must be searched sequentially even if it is ordered. Best performance is O(log N) if the list is ordered because a binary search can be used.
Insertion/deletion Performance is O(1) no matter how big the list is. At most, two elements are affected (see Lesson AB30). Performance is O(N) because many elements of the list may have to be moved.
Accessing by index Performance is O(N). Performance is O(1).

When designing a program to build a telephone directory, for example, ArrayList might be a better choice than LinkedList. The directory would not change often, so insertion/deletion would not be a major concern. However, fast searching would be important.

On the other hand, LinkedList might be better for a print spooler program. Print jobs will frequently be inserted (when a new print request is received) and deleted (when the print job is sent to the physical printer). The list could even be prioritized so that small print jobs would be inserted near the front of the list. However, searching through the list for a particular print job would not be a common occurrence.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.