【发布时间】:2023-03-19 04:35:01
【问题描述】:
我需要找到需要从连接图中删除的最小边数(可能有循环并且具有未加权的无向边),以便我最终得到两个给定的节点 - A 和 B 在单独的不连接部分中。
输入:边,节点 A,节点 B。(从 A 到 B 至少存在 1 条路径) 输出:要移除的最小边数,以便 A 和 B 之间没有路径
我只能想到最坏的解决方案:-
best = no. of edges in the given connected graph G
For each possible subset S of Edges in the given connected graph G
Graph temp = G minus edges S
if there exists a path between A and B in temp
continue
else
best = Min(best, no. of edges in S)
return best
我正在寻找一种解决方案,它可以在一两秒内轻松处理具有 15 个顶点的图形。 我想知道我的解决方案是否足够好。
谢谢!
附:我不确定我的解决方案的大 O 复杂度是 2^n 还是 n*(2^n) 或 (n^2)*(2^n)。我认为是后者,但我想确定。
【问题讨论】:
标签: algorithm graph graph-algorithm