在多根图中找到根

时间:2015-05-04 16:05:29

标签: complexity-theory graph-algorithm digraphs

我们处理可能包含或不包含循环的有向图,并且可以连接或不连接。我们希望找到最小的顶点集,以便可以从图中访问图中的每个其他顶点。

例如,给定: http://i.stack.imgur.com/wtRYB.png(因此我不会发布图片:/)

解决方案可以是(A,E)或(A,F)。

我的第一种方法是寻找没有父母的节点(indegree = 0),但这没有考虑上述周期。

经过快速搜索,我发现SO中非非循环有向图很少。那么,你可以建议我使用最低复杂度的算法是什么?

1 个答案:

答案 0 :(得分:0)

Second attempt.

This is what I've thought of:

let V be a copy of the set's vertex.

  1. Choose node from V. Mark it somehow
  2. While V has a parent unmarked, choose it.
  3. When the process finishes, you'll be left with one root. Note that it can be part of a cycle, the marks will make sure the process finishes.
  4. Now propagate recursively a delete message between the childs of the root. That is, it will order his childs to order his childs the same and then delete themselves from V.
  5. Choose another node from wht's left of V; rinse and repeat.

It works, but I cannot help but wonder if there is a faster method. Ideas?