A linked list is a dynamic, linear data structure where elements are stored as nodes in non-contiguous memory locations, with each node holding both data and a reference (pointer) to the next node. Unlike arrays, linked lists enable efficient insertions and deletions without shifting elements, making them particularly suitable for scenarios with frequent modifications or unknown sizes. The trade-off is slower random access (requiring sequential traversal) compared to arrays, but for stacks, queues, and many algorithmic problems, this flexibility is often worth it β especially when you understand that the choice between linked lists and arrays isn't about pure speed, but about cache behavior, access patterns, and dynamic sizing needs. In systems programming, variants like the Linux kernel's intrusive linked list (list_head) further reduce allocation overhead by embedding the link node inside the data structure itself.
What This Cheat Sheet Covers
This topic spans 14 focused tables and 105 indexed concepts, 92 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core List Types
Not all linked lists are the same chain of nodes β the variant you pick determines what becomes cheap and what becomes possible. The progression here runs from the bare singly linked list up through doubly and circular forms, then into specialized variants like skip lists and intrusive lists that trade simplicity for faster search or tighter memory layout.
| Type | Example | Description | |
|---|---|---|---|
node1 β node2 β node3 β null | β’ Each node contains data and one next pointer β’ traversal is unidirectional (forward only). Most common and memory-efficient type. | ||
null β node1 β node2 β node3 β null | β’ Each node has prev and next pointers enabling bidirectional traversal β’ doubles memory overhead but simplifies deletions and reversals. | ||
node1 β node2 β node3 β node1 | β’ The last node points back to the first instead of null β’ ideal for round-robin scheduling or applications requiring continuous looping. | ||
node1 β node2 β node3 β node1 | β’ Combines doubly linked structure with circular connectivity β’ both head.prev and tail.next point to each other, enabling efficient queue/deque operations. | ||
struct task { int pid; struct list_head list; }; | β’ List node embedded directly in the data structure rather than wrapping it β’ used in the Linux kernel ( list_head)β’ &bull β’ fewer allocations and better cache locality than non-intrusive variants. | ||
Bottom: 1β2β3β4β5Top: 1β3β5 | β’ Multi-level linked list with probabilistically placed express lanes at upper levels β’ achieves $O(\log n)$ search in sorted data by skipping nodes. | ||
[1,2,3] β [4,5,6] β [7,8] | β’ Each node stores an array of elements instead of a single value β’ reduces pointer overhead and improves cache locality for better performance. | ||
node.link = prev β next | β’ Memory-efficient doubly-linked list storing XOR of addresses instead of two separate pointers β’ rarely used today due to complex pointer arithmetic and lack of garbage collection support. |