Purchase Solution

Merging Sorted Lists Using Heaps

Not what you're looking for?

Ask Custom Question

I need help figuring out an algorithm that will merge k sorted lists into one sorted lists in O(n lg k) time where n is the number of elements in ALL the input lists.

I believe we are supposed to use a Heap for k-way merging.

Purchase this Solution

Solution Summary

This solution assists in merging sorted lists using heaps.

Solution Preview

Yes, you can do it with (binary) heaping in O(n log k) time

I assume that you have some familiarity with heaps and/or access to appropriate books or notes.

For definiteness, let us use a Min-Heap.

We need here to recall only the following 3 properties of heaps:

- A Heap is a nearly complete binary tree and, given k items, they can be arranged into a Heap in a O(k log k ) time.

- If the root of a Heap is replaced by a new item, the whole structure can be "heapified", that is the new item can trickle down to such a node as to make the tree a heap again, in O(log k) time.

- The root of a Min-Heap is the minimum of all its elements

Now let ...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Networking Questions

This quiz consists of some basic networking questions.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.