VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 07: Linked lists and caches

Lesson 7.5 of 8 in this module Unrolled Pro

Merge Two Sorted Lists

Merge two sorted linked lists into one sorted list by splicing their nodes. From collecting all values and sorting (O(N log N)), to a recursive merge (O(N) time, O(N) call stack), to an iterative merge with a dummy tail that rewires nodes in O(1) extra space. Then k sorted lists with a heap (O(N log k)), stability for equal keys, merging sorted event logs from many workers lazily, and deduplicating candidate document ids from several retrievers in one pass.

about 10 min 6 Python examples 2 quick checks

Problem. Given the heads of two sorted linked lists a and b, merge them into one sorted list made of the same nodes, and return its head.

text
a = 1 → 2 → 4,   b = 1 → 3 → 4      →   1 → 1 → 2 → 3 → 4 → 4
a = None,        b = 0               →   0

This is the merge step of merge sort, and the core of every "combine sorted streams" problem: compare the two fronts, take the smaller, repeat.

ML context. Sorted streams are everywhere in data systems: per-worker event logs sorted by timestamp, per-shard search results sorted by score, posting lists of document ids in an inverted index. Merging them without re-sorting is how a training data pipeline interleaves shards in time order, and how a retrieval system combines candidates from several retrievers (Changes C and D).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Merge Two Sorted Lists"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee