Foundations · Unit 8
Linked Lists
Arrays are great until you need to insert something in the middle. To slip a value into position 3 of an array, every element after it has to shuffle one seat over to make room. For a big array, that is a lot of shuffling for one insertion.
A linked list solves that differently. Instead of one solid block of memory where position matters, it is a chain of small pieces called nodes, each holding a value and a pointer to the next node. Like train cars coupled together: to add a car in the middle, you do not move the other cars, you just unhook one coupling and re-hook it around the new car.
That flexibility comes at a price. Because the pieces are scattered and only connected by pointers, you lose the array's instant "jump to position 5." To reach the fifth node you have to walk the chain from the start. This unit is about that trade: what a linked list gives you, what it takes away, and when the deal is worth it.
You’re not signed in. Your progress here won’t be saved.
The structure: nodes and pointers
A linked list is made of nodes. Each node holds two things: a value, and a pointer (a reference) to the next node in the chain. You keep a reference to the first node, called the head, and from there each node points to the one after it.
The last node has nowhere to point, so its next pointer is null. That null is how you know you have reached the end. So a list is just: head, then follow next, next, next, until you hit null.
In a singly linked list, what does the last node's next pointer point to?
The drills and graded test are premium
The lessons above are free. The interactive practice that turns recognizing the pattern into recalling it on a blank page unlocks with premium:
- ✓2 applied drills: train spotting when the concept applies
- ✓A 5-question graded test to clear the unit
- ✓The full guided problem ladder with faded hints, plus the cold-read capstone
From $6/month. Cancel anytime.