beginner8 min read·Updated September 23, 2026
Middle of a Linked List (Even Length) Explained: 1→2→3→4 vs 1→2→3→4→5
Master finding the middle of an even-length linked list. Trace 1→2→3→4 vs 1→2→3→4→5 with fast-slow pointers, mental models, and edge cases.
By Learnisim AI·Published September 23, 2026
LEARNING ARCSetup → Model in the example → Full trace → Twist → Edge cases → Apply
PREREQUISITES
- Basic pointer navigation
- Node structures
Why
Why Find the Middle of a Linked List When Length Is Unknown
Imagine you are holding the head of a singly linked list:
1 -> 2 -> 3 -> 4. You need to find its middle element, but unlike an array, there is no index 0 or .length property waiting for you. If you have an even-length list like our Given 1 -> 2 -> 3 -> 4, the exact midpoint falls between 2 and 3. Standard convention dictates returning the second middle, which is node 3. Without a specialized strategy, your first instinct might be to traverse the entire list just to count its nodes, divide by two, and then walk back to the middle. That means traversing the links twice. For longer lists, doing two full passes wastes valuable execution cycles when you could be scanning the data on the fly.Model
The Fast and Slow Pointers Mental Model
Phase 2: The Two-Pointer Race Track
Imagine you are supervising a track where two runners start together at the head node 1 of our linked list . Runner
slow takes one step at a time, moving to slow.next. Runner fast takes two steps at a time, leaping over nodes by doing fast.next.next. Because fast covers ground twice as fast as slow, the exact moment fast reaches the finish line (the end of the list), slow is guaranteed to be standing right at the halfway point.This single-pass coordination solves our dilemma without ever counting nodes or calculating length upfront. Whether we feed in the even list or the odd list , the pacing relationship remains identical. When
fast hits the end of the track, slow has traversed precisely half the distance.Syntax
Syntax and Node Definitions for Linked List Traversal
Phase 3: Syntax & APIs
To translate our two-pointer mental model into working code for the list , we need standard pointer definitions and a while loop condition. In Python, a linked list node is represented as a class holding a value and a reference to the next node:
With our nodes initialized, the fast and slow pointers start together at the
head. The loop must check both fast and fast.next to avoid a NullPointerException (or AttributeError in Python) when jumping two steps ahead:A common syntax mistake is forgetting to check
fast.next alongside fast, which crashes the program when fast reaches the exact end of an even-length list.Worked example
Tracing the Two-Pointer Algorithm on Even and Odd Lists
Phase 4: Tracing the Fast and Slow Pointers
Let us run our two-pointer traversal on our locked working examples: the even-length list 1→2→3→4 and the odd-length list 1→2→3→4→5. We initialize both
slow and fast at head (node 1) and advance slow by 1 step and fast by 2 steps in each iteration.Given
- Even List:- Odd List:
Steps for the Even List ()
- Iteration 0 (Start):slow = node 1, fast = node 1- Iteration 1:
slow moves to node 2, fast moves to node 3- Iteration 2:
slow moves to node 3, fast moves past node 4 (to null)- Termination:
fast is null, so the loop terminates. slow rests at node 3, which is the second middle.Steps for the Odd List ()
- Iteration 0 (Start):slow = node 1, fast = node 1- Iteration 1:
slow moves to node 2, fast moves to node 3- Iteration 2:
slow moves to node 3, fast moves to node 5- Iteration 3:
slow moves to node 4, fast moves past node 5 (to null) — wait, let us trace iteration 3 carefully: at iteration 2, slow is at node 3, fast is at node 5. Since fast.next is null, the loop condition fast and fast.next evaluates to false and the loop terminates. Thus slow rests at node 3.Result
Both the even-length list () and the odd-length list () correctly return node 3 when using the standard LeetCode convention.Practice
Practice Finding the Second Middle in an Even-Length Linked List
Phase 5: Practice
Now it is your turn to apply the fast and slow pointer technique to our working example. Recall our even-length linked list , where we want the algorithm to return node 3 as the second middle.
Examine your understanding of the pointer updates:
slow = slow.next and fast = fast.next.next inside the loop while fast and fast.next:. Write out or mentally trace what happens to slow and fast when head points to a two-node list .The Task
Consider a linked list with two nodes:
1 -> 2 -> None. Using the standard tortoise-and-hare traversal where slow and fast both start at 1, evaluate the loop condition and state which node value is returned.Apply
Applying the Fast and Slow Pointer Pattern to Related List Problems
Phase 6: Transfer
Now that you have mastered how the fast and slow pointer strategy isolates the second middle of our even list (landing on node 3), you can apply this exact pacing mechanic to adjacent linked list problems. Because a linked list does not allow random access, almost every problem requiring relative position or distance relies on varying pointer speeds or staggered start times.
Consider a classic variation: determining if a linked list contains a cycle. Instead of moving one pointer at twice the speed to find the end of the list, you keep the same speeds—
slow moves 1 step, fast moves 2 steps—inside a circular structure. If a cycle exists, the fast pointer will eventually loop around and catch up to the slow pointer from behind, just as a runner laps another on a track. Another direct application is finding the -th node from the end, where you stagger the start of two pointers by steps instead of moving them at different speeds.Whenever you face a singly linked list problem where you cannot know the total length or count elements in advance, think back to the two-pointer rhythm we used for our even list. Adjusting the ratio of their speeds or the offset of their start times unlocks solutions in time and space.
FAQ
What is the result when finding the middle of the even list 1→2→3→4?
Using the standard fast-and-slow pointer approach, the algorithm returns node 3 as the second middle element for the even-length list 1→2→3→4.
How does the fast and slow pointer technique work for linked lists of unknown length?
The slow pointer moves one step at a time while the fast pointer moves two steps. When the fast pointer reaches the end, the slow pointer is precisely at the middle.
What is the time and space complexity of finding the middle of a linked list?
The time complexity is O(N) because we traverse the list in a single pass, and the space complexity is O(1) since we only use two pointer variables.