Reverse Linked List Visualization & Animation
Reverses a singly linked list in-place by relinking pointers; O(n) time, O(1) space.
## What is it?
Reverse a singly linked list so that the last node becomes the head. An essential linked list operation used as a building block in many problems.
## How it works
**Iterative (in-place):**
- Use three pointers: `prev = null`, `curr = head`, `next`
- In each step: save `curr.next`, set `curr.next = prev`, advance `prev = curr`, advance `curr = next`
- When `curr == null`, `prev` is the new head
**Recursive:**
- Base case: empty or single node
- Reverse rest of list, then `head.next.next = head`, `head.next = null`
- Return new head (last node of original)
## When to use
- Palindrome Linked List (reverse second half, compare)
- Reverse sublist or groups of k nodes
- Reorder list problems
## Key Points
- Iterative: O(n) time, O(1) space — preferred
- Recursive: O(n) time, O(n) call stack space
- Always return the new head (the original tail)
Category: algorithms
Difficulty: beginner
- reversal-pattern
- linked-list
Time Complexity: O(n)
Space Complexity: O(1)
View Reverse Linked List Visualization