快速的相对排名算法算法、快速

2023-09-11 22:54:11 作者:陌上花开√醉流年

比方说,我自己100视频游戏,我想订购他们最喜欢最不喜欢。这很难让每个视频游戏,重新presents我是多么喜欢它的数值,所以我想他们比较彼此。

Let's say I own 100 video games, and I want to order them from most liked to least liked. It's very hard to give each video game a numeric value that represents how much I like it, so I thought of comparing them to each other.

一个解决方案,我想出了是捡2随机视频游戏,并选择其中一个我更喜欢,并丢弃另一个。不幸的是这种解决方案只是让我知道排名第一的视频游戏,因为这将是最后剩下的一个,并提供了有关他人的信息很少。我可以再重复该过程对于其他99视频游戏,等等,但是这是非常不切实际的:为O(n ^ 2)

One solution I came up with is picking 2 random video games, and selecting which one I liked more, and discarding the other one. Unfortunately this solution only lets me know the #1 video game since that would be the last one remaining, and provides little information about the others. I could then repeat the process for the other 99 video games, and so on but that is very impractical: O(n^2).

是否有任何O(N)(或只是合理的),可用于基于相关标准数据进行排序算法?

Are there any O(n) (or just reasonable) algorithms that can be used to sort data based on relative criteria?

推荐答案

您可以使用快速排序又名支点排序。选择一个游戏,和所有其他的游戏比较,所以你有一组更糟糕的游戏,更好的游戏。重复每个半递归。一般情况下表现为n日志ñ。

You could use quicksort aka pivot sort. Pick a game, and compare every other game to it, so you have a group of worse game and better games. Repeat for each half recursively. Average case performance is n log n.

http://en.wikipedia.org/wiki/Quicksort