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
Middle of Linked List (Fast & Slow Pointer Race) Even length (1→2→3→4) returns 2nd middle (3) | Odd length (1→2→3→4→5) returns true center (3) Even List: 1 → 2 → 3 → 4 (Fast reaches end, Slow stops at 3) 1 2 3 4 None slow fast Even List Takeaway: • Fast reaches None (past node 4). • Slow has advanced exactly 2 steps to node 3. • Returns node 3 (LeetCode standard). Loop Condition: while fast and fast.next Odd List: 1 → 2 → 3 → 4 → 5 (Fast lands exactly on last node 5) 1 2 3 4 5 None slow fast Odd Length Outcome: • Fast stops on node 5 (fast.next is None). • Slow rests squarely on the exact center node 3. Python Implementation (Single Pass - O(N) Time, O(1) Space): slow = head; fast = head while fast and fast.next: slow = slow.next # 1 step fast = fast.next.next # 2 steps
Middle of 1→2→3→4 and of 1→2→3→4→5 overview diagram
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.
Finding the Middle of a Linked List (Unknown Length) Even-length example: 1 → 2 → 3 → 4 (Returning second middle: Node 3) The Dilemma: • Singly linked lists have no index (no arr[i]) and no .length property. • Naive approach: Count entire list first, divide by 2, walk back (2 full passes = wasted cycles). • Optimal approach: Fast & Slow pointers in ONE single pass! Concrete Example: 1 → 2 → 3 → 4 (Even length) Node 1 Val: 1 Node 2 Val: 2 Node 3 Mid (2nd mid) Node 4 Val: 4 (Tail) SLOW (1x) FAST (2x) Naive 2-Pass Method 1. Traverse entire list to count nodes (N = 4). 2. Calculate middle index (N / 2 = 2). Result: 2 full traversals. Slow for long data streams. Optimal Tortoise & Hare (1-Pass) • Fast moves 2 steps while Slow moves 1 step. • When Fast reaches tail/null, Slow is at middle (Node 3). Result: O(N) time, O(1) space, exactly ONE pass!
Why Find the Middle of a Linked List When Length Is Unknown diagram
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.
The Fast & Slow Pointers Mental Model (Tortoise & Hare) Odd Length List: 1 → 2 → 3 → 4 → 5 1 2 3 4 5 🐢 slow (mid) 🐇 fast (end) Odd Length Result: Fast reaches 5 (last node). Slow lands exactly on node 3 (middle). Even Length List: 1 → 2 → 3 → 4 (Classic Even Dilemma) 1 2 3 4 null 🐢 slow (2nd mid) 🐇 fast (last) Even Length Result: Fast reaches 4 (then fast.next is null). Slow lands on node 2 (second middle). How the Two-Pointer Pacing Works (Zero-Pass Size Discovery): 1. Double Speed Rule • slow = slow.next (+1 step) • fast = fast.next.next (+2 steps) Fast covers distance twice as fast. 2. Exact Halving Ratio When fast travels distance N, slow has traveled exactly N / 2. No length calculation needed upfront! 3. Termination Condition • Loop runs while: fast != null && fast.next != null Stops precisely at the correct middle.
The Fast and Slow Pointers Mental Model diagram
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:
python
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
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:
python
slow = head
fast = head
while fast and fast.next:
    slow = slow.next
    fast = fast.next.next
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.
python
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def middleNode(head: ListNode) -> ListNode:
    # Complete the pointer initialization and loop guard
    pass
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.
python
def middleNode(head):
    slow = head
    fast = head
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
    return slow
Phase 4: Tracing Fast & Slow Pointers Even-length list (1 -> 2 -> 3 -> 4) terminal state demonstration Even List: 1 -> 2 -> 3 -> 4 -> null (Iteration 2 Terminal State) Node 1 val: 1 Node 2 val: 2 Node 3 val: 3 (Middle) Node 4 val: 4 null slow pointer fast -> null Odd List Trace: 1 -> 2 -> 3 -> 4 -> 5 -> null • Iteration 0: slow = node 1, fast = node 1 • Iteration 1: slow = node 2, fast = node 3 • Iteration 2: slow = node 3, fast = node 5 • Iteration 3: fast.next is null -> Loop Terminates! Result: Both even & odd lists correctly return Node 3. Traversal Loop Logic slow = head fast = head while fast and fast.next: slow = slow.next fast = fast.next.next
Tracing the Two-Pointer Algorithm on Even and Odd Lists diagram
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.
python
def middleNode(head):
    slow = head
    fast = head
    # Complete the loop and return slow
    return slow
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.

Keep learning