0

In the implementation of tournament tree, extra space is used as data to be compared is set at leaves of the tree and then compared.I read that it is helpful when we have to merge k sorted arrays. Now, let's assume we want to merge k sorted arrays. If instead of storing the actual values, I store the indexes and make a min heap and then use a custom comparator function in min_heap implementation which sort by values at that index. By that we can know the next element to be added to the heap. Wouldn't it be better implementation as it would save half of our space? Moreover, time complexity would also be same. Isn't the above implementation better than Tournament tree approach?
Then, what can be the cases where tournament tree can be helpful?

shiwang
  • 150
  • 1
  • 13
  • Have you read https://www.geeksforgeeks.org/tournament-tree-and-binary-heap/ ? – Jim Mischel Feb 14 '18 at 05:19
  • Ok, so basically I am reducing the number of comparisons in trade off for space.. – shiwang Feb 14 '18 at 06:18
  • And I think its implemented the same what I have written. ie.by storing indexes rather than actual values. By that we can know from which array do we have to add the next element into the heap.@JimMischel – shiwang Feb 14 '18 at 08:36

1 Answers1

1

Tournament trees are useful for tournament sort, which is often used for N-way merges, and sometimes for external sorting. Tournament sort is considered a variant of heapsort.

Another application is finding the median of multiple sorted arrays, or finding the top (or bottom) k items in a list.

A tournament tree isn't a replacement for a binary heap, but rather a specific use of a binary heap.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351