Advanced Topics in Computer Science

Unit 3: Linked Lists

Students move beyond array-backed collections and learn how references can connect nodes into flexible linear structures.

Unit Focus

What this unit is really teaching

The emphasis is on pointer/reference reasoning, diagrams, edge cases, and implementation from first principles.

Key Topics

  • +Node classes, references, null, and object identity
  • +Singly linked lists, doubly linked lists, heads, tails, and sentinels
  • +Traversal, search, insertion, deletion, and list reversal
  • +Edge cases: empty lists, one-node lists, first and last node updates
  • +Comparing linked lists with arrays and ArrayLists
  • +Iterators and simple custom list APIs

Practice Work

Implementation and analysis tasks

Student task

Implement a custom linked list with add, remove, contains, and reverse operations.

Student task

Use diagrams to debug reference bugs before changing code.

DSA Assignment Bank

30 interview-style algorithm questions for this unit

Code Scholars provides structured assignments, implementation support, edge-case review, and runtime analysis coaching so students learn the concept rather than only memorizing a solution.

1

Pointer reversal

Reverse a singly linked list

Reverse a list in place by moving links one at a time and explain which variables must be preserved before reassignment.

2

Fast and slow pointers

Detect a cycle in a list

Use two references moving at different speeds to decide whether a list contains a cycle.

3

Cycle entry logic

Find where a cycle begins

After detecting a cycle, find the node where the cycle starts and justify why the second phase works.

4

Two-list traversal

Merge two sorted lists

Combine two sorted linked lists into one sorted list without creating new data nodes.

5

Two-pointer gap

Remove the nth node from the end

Use two references with a fixed gap so a node can be removed in one pass.

6

Fast and slow pointers

Find the middle node

Return the middle node of a linked list and define the expected result for even-length lists.

7

Stable partitioning

Partition around a value

Rearrange nodes so values below a pivot appear before the others while preserving relative order within each group.

8

Adjacent comparison

Remove duplicates from a sorted list

Given a sorted linked list, remove repeated values while keeping one copy of each value.

9

Sentinel node

Remove all duplicated values

Given a sorted linked list, remove every value that appears more than once, using a sentinel to handle head removals.

10

Carry handling

Add two numbers stored in lists

Add numbers represented by reversed digit lists and produce a new list with correct carry propagation.

11

Reverse second half

Check whether a list is a palindrome

Determine whether a linked list reads the same forward and backward without converting the entire list to a string.

12

Split, reverse, merge

Reorder a list by alternating ends

Transform a list so nodes alternate from the front half and reversed back half.

13

Length and reconnect

Rotate a list by k positions

Move the last k nodes to the front after computing length and handling k larger than the list length.

14

Local pointer rewiring

Swap nodes in pairs

Swap every adjacent pair of nodes without changing stored values.

15

Group reversal

Reverse nodes in fixed groups

Reverse nodes k at a time and leave the final short group unchanged.

16

Reference identity

Find list intersection by reference

Given two singly linked lists that may share node objects, find the first shared node by reference.

17

Mapping nodes

Copy a list with extra references

Copy a linked structure where each node has next and extra references while preserving relationships.

18

Merge sort on lists

Sort a linked list

Sort a linked list using split and merge rather than random indexing.

19

Sorted prefix

Insertion sort a linked list

Build a sorted linked list by inserting each original node into the correct position.

20

Value and link copy

Delete a node with only that node reference

Explain when copying the next node data works and why it fails for the final node.

21

Depth-first linking

Flatten a multilevel list

Flatten nodes that may have child lists into a single linked list in depth-first order.

22

Edge cases

Maintain head and tail correctly

Implement addFirst, addLast, removeFirst, and removeLast while handling empty and one-node lists.

23

Custom list API

Design an iterator

Create an iterator over a custom linked list that supports hasNext and next without exposing node references.

24

ADT implementation

Implement a queue with linked nodes

Use linked nodes to implement enqueue and dequeue while preserving O(1) access to both ends.

25

ADT implementation

Implement a stack with linked nodes

Use linked nodes to implement push, pop, and peek with correct empty-list behavior.

26

Mutation while traversing

Remove values by predicate

Remove every node whose value matches a condition without skipping nodes or losing the remaining list.

27

Pointer construction

Split a list into alternating lists

Split one list into two lists by alternating nodes and preserving original node order.

28

Run processing

Compress repeated values

Given a sorted linked list, replace each run with one node storing value and count.

29

Pointer trace

Debug a lost-reference bug

Given a flawed insert method, identify the exact assignment that loses the rest of the list.

30

DSA support

Plan a linked-list assignment

Design a practice assignment that requires diagrams, implementation, edge-case tests, and runtime explanation.

Need support with Unit 3?

Work through the concepts, code, edge cases, and runtime analysis with 1:1 guidance.