reconstruct a sequence from a set of partial order

2019-08-18 01:23发布

I have a set of elements pairs. Each one of theses pairs means : In the final sequence the first elements precedes the second element. The set of pairs contains enough pairs to reconstruct a unique sequence.

eg. :

If my set of pairs is {(A, B), (A, C), (C, B)}

= A precedes B, A precedes C and C precedes B.

my final sequence is ACB.

Now, I need an algorithm to reconstruct sequences from this kind of pair sets. Efficiency is critical. Any smart tip is welcome !

2条回答
ゆ 、 Hurt°
2楼-- · 2019-08-18 01:59

This is problem of Topological sorting of Oriented graph. Read More

查看更多
冷血范
3楼-- · 2019-08-18 02:09

Create a directed graph from those pairs, then perform topological sort.

查看更多
登录 后发表回答