Merging K Sorted Lists
In this next section, we’re going to temporarily leave the world of external-memory algorithms and return to some plain old internal-memory algorithms. Eventually, we’ll tie this back into external-memory Mergesort. Okay, here goes.
Whenever I’ve discussed merging lists throughout this book, I’ve always been referring to the idea of merging two lists at once. But let’s say that we have more than two ordered lists, like three, or four, or seventy-six. How would we go about merging them? Again, right now I’m just talking about merging lists in memory. We’re assuming that our RAM can comfortably accommodate all of our lists at the same time.
At first glance, we can apply the classical merging algorithm to as many lists as ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access