[英]Graph Theory: Remove nodes, but create new vertices to keep graph connected
自从我从事算法和图论研究以来已经有很多年了,因此,如果我的回答显得有些生疏,我会提前道歉。
Create a worklist W.
Add r, the root node, to W.
While W is not empty:
Remove the first entry from W; call it s.
For each of s's children:
Add it to W.
If s is of type B
In the graph, set s's parent to be the parent of s's children.
Remove s from the graph.
对于根节点为B型的情况,我认为可以创建一个虚拟根(类型为<> B)作为原始根节点的父级。 尽管最终图形仍将保持连接,但这将取决于您的要求,因为需要删除虚拟根。 在您的示例中,A2将是一个孤儿,将被丢弃。 但是,您最终可能还会得到两个或多个断开的图形:A2-> A5; A3-> A4(例如)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.