Singly Linked Lists

Lesson 9 of 20

Follow head and curr along a node chain — insert at the front in two moves and watch a middle node get bypassed.

The big picture

The big picture

A linked list trades instant indexing for painless growth: each node knows only the next node, and every operation is just pointer rewiring.

A chain of nodes

Each Node holds one value and one next reference. There is no underlying array — the list exists only through its links.

head is everything

The single named reference into the chain. Lose head and every node after it becomes unreachable — the garbage collector cannot save you.

null ends the walk

The last node’s next is null. Every traversal loops while curr != null, then hops onto null to stop.

Fast at the front

Insert at head is two pointer moves — O(1) whether the list holds 3 nodes or 3 million.

Slow in the middle

Reaching position i costs i hops — O(n). ArrayList.get(i) is instant; LinkedList.get(i) walks the chain, hop by hop.

No shifting, ever

Arrays shove elements aside to insert; a list rewires two links instead. That is the trade for giving up random access.