-1

So I have 5 blocks (let's say of size 2000 items) each of sorted data. Is there an algorithm that would be able to take advantage of this attribute to optimize sorting the whole 10,000 items?

RChuDChu
  • 21
  • 1

1 Answers1

0

Don't know any but you can make list of the smallest for each block, that is 5 elements, remember which block they came from.

Then sort them.
Remove the smallest and add to the result
Take the next smallest from the list that the smallest was from and place it in the correst sorted position.
Surt
  • 13,762
  • 3
  • 21
  • 34
  • That's a horribly expensive way to do it. Use a priority queue (usually a binary heap) instead of sorting. – Jim Mischel Nov 06 '18 at 23:18
  • @JimMischel that was what i tried to say, sorting the smallest element of each is making a prioriy queue. – Surt Nov 08 '18 at 06:08
  • There is a big difference between using a heap-based priority queue and sorting an array of items. The merge with a priority queue is O(n log k), where n is the total number of items, and k is the number of lists. Your method that uses sorting to select the next highest is O(n * (k log k)). – Jim Mischel Nov 08 '18 at 12:54