intermediate9 min read·Updated September 24, 2026

Intersection of Two Linked Lists Explained: Intersect at 8 Walkthrough

Master the intersection of two linked lists concept. Follow a step-by-step trace of A=4→1→8→4→5 and B=5→6→1→8→4→5 using the two-pointer bridge model.

By Learnisim AI·Published September 24, 2026
LEARNING ARCSetup → Model in the example → Full trace → Twist → Edge cases → Apply
PREREQUISITES
  • Basic pointer manipulation
  • Singly linked list traversal
Two Linked Lists Intersecting at 8 ($A = 4\to1\to8\to4\to5$, $B = 5\to6\to1\to8\to4\to5$) List A 4 1 List B 5 6 1 Shared Memory Suffix (Exact Same Object References) 8 Intersection 4 5 null The Two-Pointer Bridge Model ($Len_A + Len_B = Len_B + Len_A$) 1. Mismatched Lengths • List A prefix length = 2 ($4\to1$) • List B prefix length = 3 ($5\to6\to1$) • Direct walks miss each other Offset creates synchronization gap. 2. Cross-Teleportation • Pointer p travels A then B • Pointer q travels B then A • Total steps are identical! $5 + 6 = 6 + 5 = 11$ steps total. 3. Perfect Alignment • Pointers meet at node 8 • Returns node reference instantly • $O(N)$ time & $O(1)$ space Zero extra memory allocation.
Intersect at 8: A = 4→1→8→4→5, B = 5→6→1→8→4→5 overview diagram
Why

Why Two Linked Lists Can Share a Tail Without Copying

Phase 1: The Shape of Shared Memory

Imagine you are managing two separate text histories in memory where both timelines eventually merge into the exact same sequence of edits. In data structures, this is represented by two singly linked lists that share a common tail, such as our locked working example: list and list . They start with different prefix nodes ( versus ), but once they hit node 8, they point to the exact same memory objects all the way to the end.
Without a clever pointer strategy, finding where these two lists merge requires checking every node in list against every node in list using a nested loop, or storing references in a hash set with extra space. That brute-force approach ignores the structural gift of the merged tail: once two nodes point to the same next object, they can never split back apart. We need an approach that effortlessly bridges the gap between different prefix lengths without allocating extra memory.
javascript
// Given list A: 4 -> 1 -> 8 -> 4 -> 5
// Given list B: 5 -> 6 -> 1 -> 8 -> 4 -> 5
// Expected Intersection: Node with value 8 (shared object)

function getIntersectionNode(headA, headB) {
  // TODO: Why do standard pointer traversals miss each other here?
}
Why Two Linked Lists Can Share a Tail Without Copying List A and List B diverge in their prefixes, but merge permanently at node 8 List A (Head) 4 1 List B (Head) 5 6 1 Shared Memory Zone (Once merged, lists can never split) 8 4 5 null Intersection Node (Value: 8) 1. The Length Mismatch • List A length = 5 nodes • List B length = 6 nodes • Direct traversal misses because pointers finish at different times. 2. The Two-Pointer Trick • Pointer P1 starts at Head A. • Pointer P2 starts at Head B. • When one hits null, jump it to the other list's head. 3. Perfect Synchronization • Both travel distance: PrefixA + Tail + PrefixB • They automatically align at the exact shared node 8! Complexity: O(N) time, O(1) space
Why Two Linked Lists Can Share a Tail Without Copying diagram
Model

The Two-Pointer Bridge Model for Linked List Intersections

Phase 2: The Two-Pointer Bridge Model

When looking at our working example where list () and list () merge at node 8, the core hurdle is mismatched head lengths. List has a unique prefix of length 2, while list has a unique prefix of length 3 before hitting the shared node 8.
Instead of measuring lengths or using nested loops, we deploy a path-redirection model. We imagine two runners, pointer starting at the head of list and pointer starting at the head of list . When a pointer reaches the end of its list (hits null), it instantly teleports to the head of the opposite list and continues walking.
Let us visualize what happens to their total travel distance. Pointer travels list followed by list . Pointer travels list followed by list . Because addition is commutative (), both pointers travel the exact same total number of steps before they align at the intersection node 8.

The Anatomy of the Shared Suffix

Once both pointers cross into the shared tail starting at node 8, they are locked in sync. Every subsequent step they take together is identical: . The elegance of this model is that the distance mismatch is completely dissolved during the first pass of cross-traversal.
The Two-Pointer Bridge Model for Linked List Intersections Pointer P (List A + B) and Pointer Q (List B + A) travel identical total distance before meeting at node 8 List A Head 4 4 1 List B Head 5 5 6 1 SHARED SUFFIX (Locked in sync) 8 Intersection 4 5 null p reaches null → jumps to Head B q reaches null → jumps to Head A 1 The Length Mismatch • List A prefix len: 2 (4 → 1) • List B prefix len: 3 (5 → 6 → 1) • Direct parallel walk fails because B is always 1 step ahead of A. Result without bridge: Pointers never align at node 8. 2 Path-Redirection Magic • Pointer P travels: Len(A) + Len(B) • Pointer Q travels: Len(B) + Len(A) • Commutativity ensures equal sums: A + B == B + A Total steps per pointer: 2 + 3 + 3 = 8 total steps. 3 Lock-In & Intersection • Mismatch is fully absorbed on the first cross-traversal pass. • Both enter node 8 simultaneously. • O(N + M) Time | O(1) Space Zero Extra Memory: No hash sets or length counts needed.
The Two-Pointer Bridge Model for Linked List Intersections diagram
Worked example

Tracing the Intersect at 8 Example Step by Step

Phase 3: Walking the Dual Paths

Now let's trace our locked example from start to finish. We have list A starting at head 4 with length 5 (), and list B starting at head 5 with length 6 (). Both lists merge at node 8, sharing the exact same remaining tail nodes .
Given:
- Pointer p starts at A.head (node 4).
- Pointer q starts at B.head (node 5).
Steps:
1. First Pass (Individual Lists): p travels through and then jumps to B.head. Meanwhile, q travels through and then jumps to A.head.
2. Absorbing the Offset: Because list B has one extra node at the front, pointer p hits null earlier and switches to B.head while q is still finishing list B. When q hits null, it switches to A.head. At this exact moment, p has traveled the length of A plus the prefix of B, and q has traveled the length of B plus the prefix of A.
3. Second Pass (The Convergence): Both pointers are now equidistant from the intersection node. Stepping forward in lockstep, p and q march simultaneously through the shared tail until they land on node 8.
Result:
The pointers collide at node 8 on the second pass, returning the correct shared intersection object.
Try this: Given list A = [4, 1, 8, 4, 5] and list B = [5, 6, 1, 8, 4, 5] intersecting at node 8:
1.Trace pointer p and pointer q step-by-step through their first pass.
2.Note the exact node where pointer p hits null and redirects to B.head.
3.Predict the exact iteration count on the second pass where p and q point to node 8 simultaneously.
Phase 3: Walking the Dual Paths (Intersecting at Node 8) List A (len 5): 4 1 List B (len 6): 5 6 1 Shared Tail Nodes (Merge Point) 8 4 5 null Pointer p (starts at A.head) • 1st Pass: A nodes + B prefix + hits null • Travels length of A (5) + B prefix (1) = 6 steps • Redirects to B.head (Node 5) • 2nd Pass: Marches simultaneously with q Result: Both land on Node 8 together! Pointer q (starts at B.head) • 1st Pass: B nodes + A nodes + hits null • Travels length of B (6) + A prefix (2) = 8 steps • Redirects to A.head (Node 4) • Absorbs exact offset difference of lists Equidistant from Node 8 for 2nd Pass p q
Tracing the Intersect at 8 Example Step by Step diagram
Practice

Predicting Pointer Paths on Alternate Intersect Scenarios

Phase 4: Practice

Now that you have seen how the dual-pointer traversal equalizes the length difference in our working example ( and ), it is time to test your mental model on a structural variation. Consider what happens when one list is completely disjoint from the other, or when they intersect at their very first nodes.
Imagine you are running the exact same pointer-switching logic on two lists that never intersect: list has length 3 and list has length 4, and neither shares any memory nodes. Before writing any code, trace mentally: what will the pointers and point to after both lists have been fully traversed twice, and what should your loop condition return?
Keep the core invariant in mind: pointer traverses then , while pointer traverses then . If they never share a tail node, they must finish their second traversal at the exact same moment. Think about how their final step resolves to null and why that prevents an infinite loop.
Try this: Consider two non-intersecting lists where List A has 3 nodes and List B has 4 nodes. Trace pointers p (starting at
a.and q (starting at

B) through their full double-traversal cycle. What are the exact values of p and q at the end of iteration step 7 (), and what value does the algorithm return?
Apply

Applying the Two-Pointer Bridge Pattern to Real-World Graph and Stream Problems

Phase 5: Apply

You have mastered how two runners traversing combined paths and will naturally synchronize at node 8 by absorbing length differences. This same structural trick—routing pointers through each other's full domain to eliminate length offsets—extends far beyond simple singly linked list intersections. Whenever two dependent sequences or streams must be aligned without using extra memory for hash sets, treating the traversal lengths as an additive identity () is your primary tool. Consider how this logic generalizes when pointers move through cyclic graphs or when memory constraints strictly forbid modifying the original node structures.
python
def find_intersection_or_variant(headA, headB):
    # Apply the two-pointer bridge pattern learned from the Intersect at 8 example
    pass

FAQ

How do lists A = 4→1→8→4→5 and B = 5→6→1→8→4→5 intersect at node 8?
Despite having different prefix lengths (2 vs 3 nodes before the intersection), both lists share the exact same tail nodes starting at 8 (8→4→5). Because nodes in linked lists are memory references, sharing a tail means they merge into the exact same objects.
Why does the two-pointer bridge model work when lists have different lengths?
By having pointer A traverse list A then jump to list B, and pointer B traverse list B then jump to list A, both pointers travel a combined distance equal to (Length A + Length B). This forces them to align perfectly at the intersection node on their second pass.
What is the time and space complexity of the two-pointer intersection approach?
The time complexity is O(N + M), where N and M are the lengths of the two lists, because each pointer traverses at most two lists. The space complexity is O(1) since we only use two pointer variables without extra data structures.
What happens if the two linked lists never intersect?
If there is no intersection, both pointers will reach the null terminator at the end of their second pass simultaneously. The loop terminates naturally, returning null or None.

Keep learning