JAVA LISTS COMPARISON OF IMPLEMENTATIONS List Comparisons 1








- Slides: 8

JAVA LISTS

COMPARISON OF IMPLEMENTATIONS List Comparisons 1, 00 E+01 1, 00 E+00 • Locality 1, 00 E-03 1, 00 E-04 1, 00 E-07 1, 00 E-08 Easy access to ends Size Array. List Linked. List Java. Array. List Java. Linked. List Comparisons - Big-Oh Constants 1, 00 E-06 Time / Theoretical Time What conclusions did you draw? 1000000 1, 00 E-06 • Lets run a quick experiment • 10000 1, 00 E-05 • Linked-list-based • 100 1, 00 E-02 Time • Array-based 1, 00 E-01 1 1 1000000 1, 00 E-07 1, 00 E-08 1, 00 E-09 Array. List Size Linked. List Java. Array. List Java. Linked. List

COMPARISON OF IMPLEMENTATIONS List Iteration Comparison 1, 00 E+00 1000000 1, 00 E-03 1, 00 E-04 1, 00 E-05 1, 00 E-06 1, 00 E-07 What conclusions did you draw? 1, 00 E-08 1, 00 E-09 Size Java. Array. List Java. Linked. List Big-oh Constants 1, 00 E-07 Time/Theoretcal Time • 100 1, 00 E-02 Time • What about iteration? • Lets run a quick experiment 1, 00 E-01 1 1 10000 1, 00 E-08 1, 00 E-09 Size Java. Array. List Java. Linked. List 1000000

SUMMARY OF CLASSES CONCERNING LISTS • Vector<E> - Growable-array using incremental strategy (sort of deprecated) • Array. List<E> - Growable-array using doubling strategy (supports List) • Linked. List<E> - Doubly linked list (supports List, Deque, Stack, and Queue) • Others outside the scope of this course • To find how to use them, go to the Java API!

Iterable<E> Object Collection<E> Abstract. Collection<E> List<E> Interfaces Classes Abstract. List<E> Abstract. Sequential. List<E> Linked. List<E> Array. List<E>

EXAMPLE OF USING ARRAYLIST<E> 1. Scanner s = new Scanner(new File(“numbers. txt”)); 2. Array. List<Integer> numbers = new Array. List<Integer>(); 3. while(s. has. Next. Int()) 4. numbers. add(s. next. Int()); 5. …elsewhere… 6. int sum = 0; 7. for(int n = 0; n < numbers. size(); ++n) 8. sum += numbers. get(n);

CHOOSING ARRAYLIST VS LINKEDLIST • General guideline – 95% of the time Array. List should be the go-to List – note this is a made up statistic, based on my experience. • Educated guess • • • Start with array list for quick implementation If linked list provides better big-oh complexity switch to it Otherwise, you need to experiment with both to make best selection

PROBLEMS • Linear regression. Lets help the sciences by creating a simple program for linear regression modeling. Look here for how we compute correlation coefficients. Here is experimental data. • For a given data file, find the correlation coefficient between all pairs of columns. Find the most correlated items (can be positive or negative). • I recommend trying the solve this problem for x 08. txt • Lets discuss together how to break the problem down into manageable pieces. • Use my starter code to help you parse the file.