A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Linked Lists

College Depth 79 in the knowledge graph ☐ I know this ☆ Set as goal
511topics build on this
334prerequisites beneath it
See this on the map →
Arrays and ListsPrimitive Data Types+2 more→→Binary TreesCircular Linked Lists+6 more
linked-list nodes pointers data-structures

Core Idea

A linked list is a linear data structure where each element (node) stores a value and a reference (pointer) to the next node. Unlike arrays, linked lists do not require contiguous memory; elements are connected via pointers. Singly linked lists allow traversal in one direction; doubly linked lists add a previous pointer enabling bidirectional traversal. Insertions and deletions at known positions run in O(1) time, but random access requires O(n) traversal.

How It's Best Learned

Implement a Node class with value and next fields, then build operations (insert, delete, traverse) from scratch. Drawing box-and-arrow diagrams for each operation makes pointer manipulation concrete before coding.

Common Misconceptions

Explainer

Arrays store elements in contiguous memory, so accessing element i is a single calculation (base address + i × element size) — O(1) random access. The cost is that inserting or deleting in the middle requires shifting all subsequent elements. Linked lists take the opposite trade: elements live anywhere in memory, connected by pointers. This makes insertion and deletion cheap at known positions but makes random access expensive — you must follow the chain one node at a time.

Each node in a singly linked list contains two things: a value and a next pointer referencing the following node. The last node's next pointer is null, marking the end of the list. A head pointer is the entry point to the whole structure. To traverse the list, you start at head and follow next pointers until you reach null. To insert after a given node `p`: set `newNode.next = p.next`, then `p.next = newNode` — two pointer updates, O(1). Order matters: if you set `p.next = newNode` first, you lose the reference to the rest of the list.

The O(1) insertion claim requires an important qualification: it assumes you already *have* a reference to the node you are inserting after. If you need to find that node first — say, "insert after the node with value 42" — you pay O(n) for the traversal. This is why the "linked lists beat arrays for insertion" argument is only true in specific contexts (like building a queue where you always append to the tail, which you can maintain as a constant-time pointer).

Doubly linked lists add a prev pointer to each node. This costs memory (two pointers instead of one per node) but pays off in flexibility: you can traverse backward, and you can delete a node in O(1) given only a reference to it (because you can reach its predecessor via `node.prev`). In a singly linked list, deleting a node requires its predecessor's reference, forcing a traversal from the head. Data structures like browser history, LRU caches, and the standard library's `deque` use doubly linked lists for this reason.

Linked lists are the conceptual foundation for the stack, queue, and tree structures you will encounter next. Once you can reliably manipulate pointers — insert, delete, reverse — those more complex structures become much easier to reason about, because they are all variations on the same node-and-pointer model.

Practice Questions 3 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → Defining and Calling Functions → Functions: Decomposing Problems → Function Parameters and Argument Passing → Return Values → Variable Scope → Introduction to Classes → Linked Lists

Longest path: 80 steps · 334 total prerequisite topics

Prerequisites (4)

Leads To (8)