# Computer Science 101

## Data Abstraction

Gregory M. Kapfhammer

# Color Scheme

**Key Concept**

**Corresponding Diagram**

**In-Class Discussion**

**In-Class Activity**

**Details in the Textbook**

**What have we studied so far?**

# Key Topics

Algorithms

Data structures

Software engineering tools

Java programming language

Algorithm evaluation techniques

**Data structures, algorithms, and efficiency**

**Designated nodes: Head and tail of the linked list**

**Traversal from head to the tail**

**Why would we perform this operation?**

**How costly is this operation?**

**Names: "Link hopping" or "pointer hopping"**

**Restricted modes of interaction**

`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?**

**Doubly Linked List to the rescue!**

**Store a reference to the next and previous node**

**Header and trailer sentinels**

**Benefits: always insert between two nodes**

**Organize yourselves into teams of two or three**

**Review the methods on pages 135 - 137**

**What is the worst-case time complexity?**

**Why is the **`removeLast`

method fast?

**Round-robin scheduling in operating system**

**Connections to the previous material?**

**Any questions about linked lists?**