Lecture 3 - Physical Data Structures
Lecture 3 - Physical Data Structures
LinkedList is a linear collection of data elements whose order is not given by their physical placement
in memory
LinkedList is our choice when the access to the element at specific position is rarely used
The performance enhancement is revealed during the frequent insertion, deletion and retrieval of both
the first and the last elements ONLY
LINKEDLIST<T>:ITERATORS
MyLinkedList can also implement an Iterable<T>
interface
It needs iterator() method to be implemented
That method should return an instance of Iterator
Create a private class which implements Iterator<T>
Implement hasNext() and next() methods
See next slide for results…
LINKEDLIST<T>:ITERATORS
𝑂(𝑁 2 )
𝑂(𝑁)
𝑂(𝑁)
PERFORMANCE DIFFERENCE
ArrayList`s advantages over LinkedList:
Accessing an element at specific position
Less memory usage
ArrayList is better for storing and accessing data
Implement everything (including example methods from this lecture) for MyDoublyLinkedList<T>
LITERATURE
Algorithms, 4th Edition, by Robert Sedgewick and Kevin Wayne, Addison-Wesley
Chapter 1.3