60 likes | 173 Vues
This overview covers essential topics for CS-2852 students, focusing on ArrayLists and LinkedLists, their methods, and time complexity analysis. Key aspects include implementing key ArrayList methods (e.g., add, get, remove), understanding the differences between arrays and ArrayLists, and using interfaces in Java's Collection Framework. Students will learn to write loops for repetitive tasks, the significance of generics, and when to use Collection<E> versus List<E>. A comparison of LinkedLists with ArrayLists highlights their unique capabilities and performance aspects.
E N D
CS-2852Data Structures • Week 4, Class 1 - Review • Review! • Thursday • Exam I - Review • Implementing ArrayList • Big-O • Iterators – High-level description • Linked Lists – comparison with ArrayLists CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Review of 1011 and 1021 • Write a loop for a given repetitive task • Explain the difference between a class and an interface • Describe key differences between an array and an ArrayList<E> object • Implement classes and methods that make use of generics • Write code that uses an ArrayList<E> or two • Use references to interfaces instead of concrete classes wherever possible CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Interfaces • Use the Collection<E> and List<E> interfaces defined in the Java Collection Framework • Explain when to use Collection<E> instead of List<E> and vice versa • Demonstrate correct use of generics when declaring Collection<E> and List<E> interfaces • Describe the implications of an interface extending another interface • List two classes that implement the List<E> interface CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Implementing ArrayLists • Write the method headers for the key methods of an ArrayList • Don’t need to match Java API perfectly • Just include arguments needed to perform the job • Implement the key methods of ArrayListt • add(E) • add(int, E) • clear() • contains(Object) • equals(Object) • get(int) • indexOf(Object) • isEmpty() • remove(int) • remove(Object) • set(int, E) • size() • subList(int, int) • toArray() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Linked Lists – comparison with ArrayLists • Methods offered • Determine order given a single add() method • Describe key differences between our implementation of theLinkedList<E>class and Java’s. CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Time Complexity • Determine the asymptotic time complexity for a method from our simple ArrayList class. • Identify key loops that make ArrayLists or LinkedLists faster for a given problem, provided the method for the LinkedList class. • Determine the asymptotic time complexity for a given method from the source code • Determine the simplified O(f(n)) for a T(n) polyomial CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick