什么是排序部分有序列表的最佳方法是什么? [英] What is the best way to sort a partially ordered list?

查看:930
本文介绍了什么是排序部分有序列表的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是最好的一个小例子来说明。
由于关系

Probably best illustrated with a small example.
Given the relations

A < B < C
A < P < Q

正确的输出将

Correct outputs would be

ABCPQ or APQBC or APBCQ ... etc.

在换言之,任何顺序是有效,其中给定的关系式成立。

In other words, any ordering is valid in which the given relationships hold.

我最感兴趣的解决方案是最容易实现的,但最好为O(n)的速度和时间有趣的是也。

I am most interested in the solution that is easiest to implement, but the best O(n) in speed and time is interesting as well.

推荐答案

这就是所谓的拓扑排序

标准的算法,输出一个最小的元素,然后将其删除,重复,直到完成。

The standard algorithm is to output a minimal element, then remove it and repeat until done.

这篇关于什么是排序部分有序列表的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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