Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Linked Lists Lab
Linear Data Structures
Concept shape
Core
0
1
2
3
4
5
Definition
A linked list stores nodes that point to the next node, so elements do not need contiguous memory.
Step 1 / 5
Concept shape
Linear Data Structures Core
Linked Lists
Welcome to the Linked Lists concept lab. A linked list stores each value inside a node, and each node points to the next node in the chain. Because nodes are connected by references, the list does not need one continuous block of memory. The cost is access: to reach the tenth node, you walk through the first nine nodes. Insertions and deletions are cheap only when you already have the relevant node or pointer. The must know points are: Head points to the first node. Traversal is O(n). Insertion is cheap only when you already have the position. The common operations are: insert head O(1), delete after node O(1), search O(n), traverse O(n). The complexity shape is Access/search O(n), insert/delete with node O(1). Watch out for these pitfalls: Losing the next pointer during deletion. Infinite loops from cycles. Forgetting empty-list cases. Related algorithms include Fast and Slow Pointers, Linked List Reversal.
Concept details
A linked list stores each value inside a node, and each node points to the next node in the chain.
Because nodes are connected by references, the list does not need one continuous block of memory.
The cost is access: to reach the tenth node, you walk through the first nine nodes. Insertions and deletions are cheap only when you already have the relevant node or pointer.
Must know
- Head points to the first node.
- Traversal is O(n).
- Insertion is cheap only when you already have the position.
Complexity
Access/search O(n), insert/delete with node O(1)
1.0x