Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a Heap and a Loser Tree in external sorting?

I felt that they are very similar to each other, except at some concepts. In external sorting their functions are basically the same, that is to find the minimal/maximal value in k runs. So are there some significant differences between them two ?

like image 906
Flybywind Avatar asked Oct 07 '11 10:10

Flybywind


People also ask

What is the difference between heap and array?

Heap takes less time complexity as compared to the sorted arrays in terms of creation. Building heap takes O(n) time complexity, whereas building Sorted Array takes O(n. log n) time. Insertion and deletion in the heaps are efficient heaps as compared to sorted arrays.

Is a heap just an array?

A heap is a binary tree inside an array, so it does not use parent/child pointers. A heap is sorted based on the "heap property" that determines the order of the nodes in the tree. Common uses for heap: To build priority queues.

Is a heap a perfect tree?

A heap is a complete binary tree. A max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node. A min-heap is defined similarly.

Does a heap have to be sorted?

In a heap, the highest (or lowest) priority element is always stored at the root. However, a heap is not a sorted structure; it can be regarded as being partially ordered.


1 Answers

For the most part, loser trees and heaps are quite similar. However, there are a few important distinctions. The loser tree, because it provides the loser of each match, will contain repeat nodes. Since the heap is a data-storing structure, it won't contain these redundancies. Another difference between the two is that the loser tree must be a full binary tree (because it is a type of tournament tree), but the heap does not necessarily have to be binary.

Finally, to understand a specific quality of the loser tree, consider the following problem: Suppose we have k sequences, each of which is sorted in nondecreasing order, that are to be merged into one sequence in nondecreasing order. This can be achieved by repeatedly transferring the element with the smallest key to an output array. The smallest key has to be found from the leading elements in the k sequences. Ordinarily, this would require k − 1 comparisons for each element transferred. However, with a loser tree, this can be reduced to log2 k comparisons per element.

Source: Handbook of Data Structures and Applications, Dinesh Mehta

like image 166
Viky Avatar answered Nov 15 '22 08:11

Viky