AlgoScope

Merge K Sorted Lists

AlgorithmintermediateLinked List Operations

Keep the current heads in a min-heap so the global smallest is always one pop away.

Decision · step 2 of 10Merging Sorted Lists: Three lists through a heap
1✓6825349headtailpqr

Heads: 1 in a, 2 in b, 3 in c. The smallest is 1 from a, so it is unhooked from its list and linked after nothing: it becomes the merged head.

Open in the player →or start at step 2

What you will see

k list heads sit in a heap; the minimum pops out and its list advances.

How merging sorted lists works →

Cost

BestO(N log k)
AverageO(N log k)
WorstO(N log k)
SpaceO(k)

N total nodes across k lists.

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Each node announces its value and what it points to; each step announces the pointer change ("node 3 now points to node 5").

Reduced motion: Pointer arrows redraw in place with a brief emphasis instead of animating the detach and reattach.

Taught by the same lesson

Merging Sorted Lists covers these too, in the same run.