Gregory M. Kapfhammer
Key Concept
Corresponding Diagram
In-Class Discussion
In-Class Activity
Details in the Textbook
Algorithms
Data structures
Software engineering tools
Java programming language
Algorithm evaluation techniques
Collection of nodes
Form a linear sequence
Singly-linked list ...
Node stores data and a next pointer
Doubly-linked list ...
Node stores data and a next and previous pointer
What does this look like in memory?
addFirst
Insert an element at the head of a linked list
See Code Fragment 3.11 for the algorithm
See Figure 3.12 for an illustrative diagram
What is the performance of this algorithm? Why?
addLast
Insert an element at the tail of a linked list
See Code Fragment 3.12 for the algorithm
See Figure 3.13 for an illustrative diagram
What is the performance of this algorithm? Why?
What if we did not maintain a tail reference?
removeFirst
Remove an element at the head of a linked list
See Code Fragment 3.13 for the algorithm
See Figure 3.14 for an illustrative diagram
What is the performance of this algorithm? Why?
removeLast
Remove an element at the tail of a linked list
The textbook does not present this algorithm
But, discussing this algorithm is important!
How would this algorithm work?
What is the performance of this algorithm? Why?
The linked list has a key deficiency! How to fix it?
removeLast
method fast?