简体   繁体   English

删除最小节点数以使图形断开连接

[英]Remove minimum number of nodes to make graph disconnected

Find the minimum number of nodes that needs to be removed to make graph disconnected( there exists no path from any node to all other nodes).找到使图断开连接需要删除的最小节点数(不存在从任何节点到所有其他节点的路径)。 Number of nodes can be 10 5节点数可以是 10 5

First of all, to find a node that is not needed to make the graph connected, you need to find a cycle.首先,要找到一个不需要使图连通的节点,您需要找到一个循环。 Once you find a cycle, then you know all those edges in those cycle are not needed.一旦你找到一个循环,那么你就知道那些循环中的所有这些边都是不需要的。 All the remaining edges in the graph are needed to hold the graph together, so you do a simple traversal of the graph and count the number of vertices connected to find the minimum number of nodes that needs to be removed to make graph disconnected.图中的所有剩余边都需要将图保持在一起,因此您对图进行简单的遍历并计算连接的顶点数以找到需要移除以使图断开连接的最小节点数。 I'm not sure if this is the most efficient way, just the most efficient in my head.我不确定这是否是最有效的方式,只是我头脑中最有效的方式。 If V is the number of vertices and E is the number of edges, the time complexity will be somewhere around O(V + E) + O(V), since the initial cycle finding is O(V + E) and the counting of the nodes is O(V).如果 V 是顶点数并且 E 是边数,则时间复杂度将在 O(V + E) + O(V) 左右,因为初始循环查找是 O(V + E) 并且计数节点是 O(V)。 Since E >= V, the time complexity can be rounded to O(E), but with huge constant factors.由于 E >= V,时间复杂度可以四舍五入到 O(E),但具有巨大的常数因子。

Consider the graph undirected.考虑无向图。

totalDegree = sum of degree of all nodes.
while(totalDegree > 0) {
    Remove the node with highest degree and it's edges.
    Update degree count of each node.
    totalDegree = sum of degree of all remaining nodes.
}
remaining nodes are all disconnected

Trying to think of a case where it will not give the min number of nodes.试图考虑一个不会给出最小节点数的情况。

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

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