学习元素顺序的排序算法? [英] Sorting algorithm that learns the order of elements?

查看:94
本文介绍了学习元素顺序的排序算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种算法的名称,该算法根据这些元素的排序列表来学习一组元素的顺序,然后能够使用该顺序对由某些元素组成的列表进行排序。

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".

然后执行该图的拓扑排序

这篇关于学习元素顺序的排序算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆