我需要知道我应该为以下情况选择哪种算法

时间:2018-06-08 12:58:53

标签: algorithm sorting data-structures graph-algorithm storing-data

我有四个组件A,B,C,D。哪个依赖关系流如A -> B -> C -> D。 A取决于B,B取决于C,C取决于D.在这种情况下我应该使用哪种算法。

1 个答案:

答案 0 :(得分:1)

您要查找的算法是拓扑排序

Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of
vertices such that for every directed edge u-v, vertex u comes before v in the 
ordering. Topological Sorting for a graph is not possible if the graph is not 
a DAG.