【问题标题】:Best Algorithm to sort a list of sorted arrays? [duplicate]对已排序数组列表进行排序的最佳算法? [复制]
【发布时间】:2018-11-06 22:20:53
【问题描述】:

所以我有 5 个块(假设大小为 2000 个项目)每个排序数据。有没有一种算法可以利用这个属性来优化对整个 10,000 个项目的排序?

【问题讨论】:

标签: algorithm


【解决方案1】:

不知道,但你可以列出每个块的最小元素,即 5 个元素,记住它们来自哪个块。

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.

【讨论】:

  • 这是一种非常昂贵的方法。使用优先级队列(通常是二进制堆)而不是排序。
  • @JimMischel 这就是我想说的,对每个元素中最小的元素进行排序是在做一个优先队列。
  • 使用基于堆的优先级队列和排序项目数组之间有很大的不同。与优先级队列的合并是 O(n log k),其中 n 是项目的总数,k 是列表的数量。您使用排序来选择下一个最高值的方法是 O(n * (k log k))。
猜你喜欢
  • 1970-01-01
  • 2011-11-27
  • 1970-01-01
  • 2010-09-07
  • 1970-01-01
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
  • 2017-07-16
相关资源
最近更新 更多