AlgoViz

Singly linked list

easy 18 min

A singly linked list is a chain of nodes where each node holds a value and a pointer to the next node.

Where it shows up

The same pattern appears across everyday software.

  • Hash table chaining

    Many hash tables, such as Java's HashMap for short chains, store keys that collide in the same bucket as a linked list. New keys go in at the head, and lookups walk the short chain.

  • Stacks and queues

    A linked list with the head as the top is a stack with O(1) push and pop and no resizing. Add a tail pointer and it is a queue with O(1) enqueue at the tail and dequeue at the head.

  • Operating system free lists

    Memory allocators keep free blocks in a linked list, often storing the next pointer inside the free block itself, so finding and returning a block is a pointer change.

  • Undo history and playlists

    Undo histories, music playlists and image viewers that only move forward are chains of states or items, each pointing at the next one.

  • Graph adjacency lists

    A sparse graph stores, for each vertex, a list of its neighbours. Classic implementations use one linked list per vertex.

  • Compilers and symbol tables

    Symbol tables and scope chains link entries together so that a new scope can be pushed on the front and dropped in O(1) when it ends.