简体   繁体   English

如何将有向无环图转换为树

[英]how to convert a directed acyclic graph into a tree

I want to convert a directed acyclic graph (DAG) into a tree, by duplicating the nodes that has more than one parent. 我想通过复制具有多个父节点的节点将有向无环图(DAG)转换为树。 what is the most efficient way of doing so? 最有效的方法是什么?

You can use depth first search or breadth first search for that. 您可以使用深度优先搜索或宽度优先搜索。 Does not matter. 没关系。 The only difference is that you want duplicate the first vertices that you already visited (go into depth 1 of visited, not more). 唯一的区别是您想复制已经访问过的第一个顶点(进入访问的深度1,而不是更多)。

Here is DFS for java: http://algs4.cs.princeton.edu/41graph/DepthFirstSearch.java.html , but there are many implementations. 这是Java的DFS: http : //algs4.cs.princeton.edu/41graph/DepthFirstSearch.java.html ,但是有许多实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM