A lesson from the data structures and algorithms bootcamp. About a 11 minute read.
A linked list chains nodes together with pointers instead of laying them out in a block. In real code you will reach for one rarely. In interviews and in your own understanding it earns its place for a different reason: it is the first structure made of nodes that point at other nodes, and getting comfortable relinking pointers here is what makes trees feel easy rather than frightening.
Each node holds a value and a reference to the next node. There is no index and no arithmetic: to reach the fifth item you start at the head and follow four links. The practical case for linked lists is weaker than textbooks suggest, since cache locality usually makes an array win even where the complexity table says otherwise. The real case is this: a linked list is a tree where every node has exactly one child. Everything you learn here about holding a pointer to the previous node, about not losing the rest of the list when you reassign a link, and about what null means at the end, transfers directly to trees with two children and then to graphs with many. It is the shallow end of the same pool.
The rest of this lesson continues with 5 further sections. See the full curriculum.
Browse all 536 practice puzzles