我想知道是否有一种算法的名称,该算法根据这些元素的排序列表来学习一组元素的顺序,然后能够使用该顺序对由某些元素组成的列表进行排序。
I was wondering if there is a name for an algorithm that learns the order of a set of elements based on sorted lists of these elements and then is able to sort lists consisting of some of these elements using that order.
示例:
我们有5个元素:小,小,中,大, 巨大。当然,该算法无法理解这些词的含义。我们可以在其中形成其中一些单词的列表,并按单词的大小(从最小到最大)进行排序:
We have 5 elements: "tiny", "small", "medium", "large", "huge". The algorithm doesn't understand the meaning of these words, of course. We can form lists with some of these words in it which are sorted by the "size" of the word (from smallest to largest):
- 小,中,大
- 小,中,大
- 小,小,大,大
我搜索的算法仅采用这些排序列表,并与所有单词,正确排序(例如[ tiny, small, medium, large, huge])。
The algorithm I search takes only these sorted lists and forms a single list with all the words, correctly sorted (that would be ["tiny", "small", "medium", "large", "huge"]).
推荐答案您可以从示例中构建有向图,其中单词是顶点,并且边缘反映序列。例如。第一个示例将从小到中等以及从中到巨大的边缘。
You can build up a directed graph from the examples where the words are the vertices and with edges reflecting the sequence. E.g. the first example would give edges from "small" to "medium" and from "medium" to "huge".
然后执行该图的拓扑排序。
更多推荐
学习元素顺序的排序算法?
发布评论