Dfs algorithm that decides if a directed graph has a unique topological sort

帅比萌擦擦* 提交于 2019-12-11 15:56:59

问题


I'm trying to struct an algorithm that uses DFS for the purpose of deciding whether a given directed graph has unique topological sort or not.
My approach to the problem is that only a specific graph has a unique topological sort. And that graph is a chain like graph, in which all of the vertices are connected to each other in one line. My dilemma is how to do an efficient DFS algorithm, and what exactly should I check.


回答1:


From here

a digraph has a unique topological ordering if and only if there is a directed edge between each pair of consecutive vertices in the topological order (i.e., the digraph has a Hamiltonian path).

So, you run DFS and you need to check that the longest path you went from start vertex has length |V|, then you have unique topological order. As MattTimmermans pointed out such graph can be reduced to a "chain graph".



来源:https://stackoverflow.com/questions/48030136/dfs-algorithm-that-decides-if-a-directed-graph-has-a-unique-topological-sort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!