对偏序集进行排序?

发布于 2024-10-10 12:47:37 字数 208 浏览 4 评论 0原文

有大量的排序算法,但大多数只适用于全序集,因为它们假设任何两个元素都是可比较的。然而,是否有任何好的算法可以对某些元素无法比较的偏序集进行排序?也就是说,给定从偏序集中提取的一组元素 S,输出排序 x1, x2, ..., xn 使得如果 xi ≤ xj,i ≤ j?

There are a huge number of sorting algorithms out there, but most of them only work on totally-ordered sets because they assume that any two elements are comparable. However, are there any good algorithms out there for sorting posets, where some elements are uncomparable? That is, given a set S of elements drawn from a poset, what is the best way to output an ordering x1, x2, ..., xn such that if xi ≤ xj, i ≤ j?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心房的律动 2024-10-17 12:47:37

arxiv 上有一篇题为 Sorting and Selection in Posets 的论文。 org 讨论了 O((w^2)nlog(n/w)) 阶的排序方法,其中 w 是偏序集的“宽度”。我还没有读过这篇论文,但它似乎涵盖了你正在寻找的内容。

There's a paper titled Sorting and Selection in Posets available on arxiv.org which discusses sorting methods of order O((w^2)nlog(n/w)), where w is the "width" of the poset. I haven't read the paper, but it seems like it covers what you are looking for.

|煩躁 2024-10-17 12:47:37

拓扑排序非常适合对部分有序集进行排序。大多数算法都是 O(n^2)。以下是来自维基百科的算法:

L ← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges
while S is non-empty do
    remove a node n from S
    add n to tail of L
    for each node m with an edge e from n to m do
        remove edge e from the graph
        if m has no other incoming edges then
            insert m into S
if graph has edges then
    return error (graph has at least one cycle)
else 
    return L (a topologically sorted order)

有一个有用的视频示例。大多数类 Unix 系统都有 tsort 命令。您可以使用 tsort 解决视频的布朗尼示例,如下所示:

$ cat brownies.txt
preheat bake
water mix
dry_ingredients mix
grease pour
mix pour
pour bake

$ tsort brownies.txt
grease
dry_ingredients
water
preheat
mix
pour
bake

Topological sort is well-suited to sorting a partially ordered set. Most algorithms are O(n^2). Here's an algorithm from Wikipedia:

L ← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges
while S is non-empty do
    remove a node n from S
    add n to tail of L
    for each node m with an edge e from n to m do
        remove edge e from the graph
        if m has no other incoming edges then
            insert m into S
if graph has edges then
    return error (graph has at least one cycle)
else 
    return L (a topologically sorted order)

There's a helpful video example. Most Unix-like systems have the tsort command. You could solve the video's brownie example with tsort as follows:

$ cat brownies.txt
preheat bake
water mix
dry_ingredients mix
grease pour
mix pour
pour bake

$ tsort brownies.txt
grease
dry_ingredients
water
preheat
mix
pour
bake
云之铃。 2024-10-17 12:47:37

我将从选择交换排序开始。这是 O(n^2),我认为你不会做得更好。

I'd start with selection-exchange sort. That's O(n^2) and I don't think you'll do better than that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文