Finding middle element of linked list with 1 pass, is this a creative useless answer?
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
Finding the middle of a linked list in one pass is not a gimmick. It is the standard fast-and-slow pointer technique, and it is both practical and elegant. The reason it matters is that singly linked lists do not support direct indexing, so a good solution should avoid extra traversal state when possible.
The Core Idea
The technique uses two pointers:
- '
slowmoves one node at a time' - '
fastmoves two nodes at a time'
When fast reaches the end of the list, slow is at the middle.
That works because fast covers distance at twice the speed. By the time it has taken 2k steps, slow has taken k steps, which places slow halfway through the traversed list.
Why a One-Pass Solution Is Useful
A two-pass solution is also correct:
- walk the list to count nodes
- walk again to the middle index
That is easy to explain, but the one-pass method has real advantages:
- it avoids a second traversal
- it keeps memory usage constant
- it generalizes to related pointer problems
On short lists the performance difference is small. On very long lists, or in streaming-style list processing, the one-pass approach is cleaner and often preferred.
This is why the answer is not "creative but useless." It is a standard interview and production technique.
Python Example
Here is a complete Python implementation:
For the list 1 -> 2 -> 3 -> 4 -> 5, the answer is clearly 3.
What Happens on Even-Length Lists
Even-length lists require a convention. For 1 -> 2 -> 3 -> 4, there are two "middle" candidates: 2 and 3.
The implementation above returns the second middle, which is 3.
That happens because the loop continues while fast and fast.next both exist. If you want the first middle instead, you can change the loop condition or track the previous slow node.
Example that returns the first middle:
The key point is not that one convention is universally correct. The important part is choosing one deliberately.
Reasoning About Correctness
A simple way to reason about the algorithm is to count iterations. After one loop:
- '
slowhas moved1' - '
fasthas moved2'
After k loops:
- '
slowhas movedk' - '
fasthas moved2k'
The loop stops when fast cannot advance two more steps. At that moment, slow has covered about half the traversable distance, which places it in the middle position by the chosen convention.
This is a good example of using relative speed rather than explicit counters.
Why Linked Lists Make This Pattern Natural
On an array, finding the middle is trivial because random access gives you array[len(array) // 2]. A linked list does not offer that. You only move node by node.
That limitation is exactly why fast-and-slow pointers are so valuable with lists. The same idea also shows up in:
- cycle detection
- splitting a list for merge sort
- checking whether a list is a palindrome
So learning the middle-finding version is worthwhile beyond the immediate problem.
Complexity
The time complexity is O(n) because each pointer traverses at most the list length up to a constant factor. The space complexity is O(1) because only a few pointer variables are used.
That is asymptotically optimal for a singly linked list. You cannot do better than linear time because you must inspect enough nodes to know where the middle is.
Common Pitfalls
The most common mistake is forgetting to handle the empty list. If head is None, the function should return None or raise a deliberate error depending on your API.
Another issue is ambiguity on even-length lists. Many bugs come from assuming everyone means the same middle. State clearly whether you return the first middle or the second.
Some implementations also write the loop condition incorrectly and dereference fast.next when fast is already None. The safe pattern is:
Finally, do not oversell the one-pass answer as a magical optimization. It is better than two passes, but mainly because it is the standard clean solution for pointer-based traversal, not because it changes the asymptotic class.
Summary
- The fast-and-slow pointer method is the standard one-pass way to find a linked list middle.
- It is useful, not a useless trick, because linked lists do not support indexing.
- The algorithm runs in
O(n)time andO(1)space. - Even-length lists require an explicit convention for which middle to return.
- The same pointer pattern appears in several other important linked-list problems.
Related reading
- Finding Minimum Completion Time of Scheduled Tasks with Topological Sort
- Finding minimum cut-sets between bounded subgraphs
- Finding minimum moves required for making 2 strings equal
- Finding minimum number of points which covers entire set of intervals?
- Finding multiple entries with binary search
- Finding neighbourhoods cliques in street data a graph
- Finding minimum number of presses to shut down lamps
- Finding nearest point in an efficient way

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.