Introduction to Linked List
Channel: Neso Academy
Watch on YouTube →Data Structure • medium
Linked lists chain nodes via pointers instead of storing values in contiguous memory.
They shine for local insert/delete operations once node references are known.
Most linked-list problems test pointer movement discipline rather than raw complexity memorization.
Typical Complexity Baseline
| Metric | Value |
|---|---|
| Traversal | O(n) |
| insert/delete at node | O(1) |
See It
A small animated SVG that illustrates the core idea the moving parts you need to keep in your head when you read the rest of the guide.
Each node points to the next. Inserting between two nodes only rewires two pointers.
Watch First
A quick visual walkthrough before the detailed sections pick the format that helps you learn fastest.
Channel: Neso Academy
Watch on YouTube →Mechanics
The building blocks and terminology you need before everything else clicks. Skim or deep-read.
What it is Container with value and next pointer (and optional prev pointer).
Why it matters Node is a required building block for understanding how Linked List stays correct and performant on large inputs.
What it is First node reference.
Why it matters Head is a required building block for understanding how Linked List stays correct and performant on large inputs.
What it is Last node reference for O(1) append in doubly-linked variants.
Why it matters Tail is a required building block for understanding how Linked List stays correct and performant on large inputs.
What it is Dummy node used to simplify edge cases at head/tail.
Why it matters Sentinel node is a required building block for understanding how Linked List stays correct and performant on large inputs.
What it is Updating next/prev pointers safely during operations.
Why it matters Pointer rewiring is a required building block for understanding how Linked List stays correct and performant on large inputs.
What it is Each node points only to next node.
Why it matters Each node points only to next node. In Linked List, this definition helps you reason about correctness and complexity when inputs scale.
What it is Each node points to both prev and next nodes.
Why it matters Each node points to both prev and next nodes. In Linked List, this definition helps you reason about correctness and complexity when inputs scale.
What it is Node pointers eventually loop back to an earlier node.
Why it matters Node pointers eventually loop back to an earlier node. In Linked List, this definition helps you reason about correctness and complexity when inputs scale.
What it is Two-speed traversal trick for cycle/middle detection.
Why it matters Two-speed traversal trick for cycle/middle detection. In Linked List, this definition helps you reason about correctness and complexity when inputs scale.
What it is Reverse list by pointer rewiring without extra list allocation.
Why it matters Reverse list by pointer rewiring without extra list allocation. In Linked List, this definition helps you reason about correctness and complexity when inputs scale.
Walkthrough
Every frame of the concept diagram, laid out top-to-bottom so you can scroll through the algorithm at your own pace.
Linked list: 3 → 7 → 9 → 5 → 2. Each node holds a value and a next pointer.
Traversal step 1: start at head, cursor on node(3).
cursor = cursor.next → node(7).
cursor.next → node(9).
cursor.next → node(5). Each pointer hop is one cache miss that's why traversal is O(n) but slower than an array of equal length.
Insert 8 after node(9). First find the predecessor we already have it: node(9) at index 2.
Allocate a new node(8) somewhere in the heap (drawn separately).
new.next = predecessor.next = node(5).
predecessor.next = new. Splice complete in O(1).
Logical view: 3 → 7 → 9 → 8 → 5 → 2.
Now delete node(8). Find its predecessor node(9) at index 2.
predecessor.next = node(8).next = node(5). node(8) is now unreachable.
List restored: 3 → 7 → 9 → 5 → 2. Insert and delete are both O(1) once the predecessor is held.
Tradeoffs
When this technique wins, when it loses, and what to reach for instead.
Choose this when Choose linked list for frequent inserts/deletes in middle by node reference.
Tradeoff Random access by index is O(n).
Choose this when Choose linked list when you need custom node-level operations.
Tradeoff Deque is simpler and often faster for plain queue/stack usage.
Choose this when Use together in LRU-like designs where order + key lookup are needed.
Tradeoff Linked list alone cannot do fast key lookup.
In Production
Where this shows up at real companies and what the on-call engineer learned the hard way.
Kernel subsystems use intrusive linked lists for flexible insertion/removal in scheduling and memory metadata.
Takeaway Pointer-based structures are practical in systems-level code.
Earlier list internals and some modules rely on linked-node structures for efficient local edits.
Takeaway Linked lists remain relevant in core infrastructure components.
Buffer and lock manager internals often chain metadata objects via linked pointers.
Takeaway Node-level updates are useful when topology changes frequently.
Code
A clean reference implementation in TypeScript, Python, and Go. Switch languages with the toggle.
Iterative pointer rewiring with previous/current/next references.
Complexity: Time O(n), Space O(1)
Reverse singly linked list
type ListNode = { value: number; next: ListNode | null }
function reverseList(headNode: ListNode | null): ListNode | null {
let previousNode: ListNode | null = null
let currentNode = headNode
while (currentNode) {
const nextNode = currentNode.next
currentNode.next = previousNode
previousNode = currentNode
currentNode = nextNode
}
return previousNode
}
Watch Out
The bugs and edge cases that bite engineers most often. Skim before you ship.
Pro Tips
Small habits that pay off every time you reach for this pattern.
Pattern Recognition
Concrete signals that tell you this is the right pattern both at work and on LeetCode.
next references.Practice
A curated easy-to-hard problem ladder. Each one reinforces a specific aspect of the pattern.
| # | Problem | Difficulty | Typical Complexity |
|---|---|---|---|
| 1 | Reverse Linked List | Easy | O(n) |
| 2 | Merge Two Sorted Lists | Easy | O(n+m) |
| 3 | Linked List Cycle | Easy | O(n) |
| 4 | Remove Nth Node From End | Medium | O(n) |
| 5 | Reorder List | Medium | O(n) |
| 6 | Sort List | Medium | O(n log n) |
| 7 | Copy List with Random Pointer | Medium | O(n) |
| 8 | Reverse Nodes in k-Group | Hard | O(n) |
| 9 | Merge k Sorted Lists | Hard | O(n log k) |
| 10 | LRU Cache | Hard | O(1) ops |