Middle of Linked List Visualization & Animation
Finds the middle node of a linked list in one pass using fast (×2) and slow (×1) pointers.
## What is it?
Find the middle node of a singly linked list in a single pass using the fast and slow pointer (Floyd's tortoise and hare) technique.
## How it works
- Use two pointers: `slow` and `fast`, both starting at `head`
- Move `slow` one step and `fast` two steps each iteration
- When `fast` reaches the end (or `fast.next == null`) → `slow` is at the middle
- For even-length lists, this returns the second middle node
## When to use
- Splitting a linked list into two halves (e.g., for Merge Sort on linked lists)
- Palindrome Linked List check (find middle, reverse second half, compare)
- Any problem requiring the midpoint of a linked list
## Key Points
- O(n) time, O(1) space — no need to count length first
- The fast-slow pointer trick is reused in cycle detection, kth-from-end, and more
- Handles both odd-length (one clear middle) and even-length (convention: second middle)
Category: algorithms
Difficulty: beginner
- fast-and-slow-pointers
- linked-list
Time Complexity: O(n)
Space Complexity: O(1)
View Middle of Linked List Visualization