Linked lists: pointer surgery you can trust
A linked list is the one structure where the pointer is the data, so every bug is an aliasing bug — this lesson builds the three routines every list question is assembled from (in-place reversal, the sentinel node, and the fast/slow pair), proves why Floyd's tortoise and hare must meet, and derives the cycle-start formula instead of memorising it.
What you'll be able to do
- Write an in-place reversal from its loop invariant rather than from memory, and state what each of the three pointers is for
- Use a sentinel node to delete the special cases at the head of a list, and say why the head is special in the first place
- Apply the fast/slow pair to find the middle, the kth-from-last node, and a cycle, in one pass and O(1) space
- Prove that the tortoise and hare must meet inside a cycle, and derive where the cycle begins
- Say when a linked list is the right structure in real code, and when it is a worse array
The rest of this lesson is in the app
A linked list is the one structure where the pointer is the data, so every bug is an aliasing bug — this lesson builds the three routines every list question is assembled from (in-place reversal, the sentinel node, and the fast/slow pair), proves why Floyd's tortoise and hare must meet, and derives the cycle-start formula instead of memorising it. This walkthrough runs about 26 minutes, with runnable code you can edit and re-run as you read.
Continue in ChannelPulseThe first module of every track is free to read on the web — see what's open in Coding & data structures.