我有一个算法,用于通过给定顶点创建 P 顶点上所有可能的子图的列表。它并不完美,但我认为它应该可以正常工作。问题是当我尝试计算它的时间复杂度时我迷路了。
我想出了类似的东西T(p) = 2^d + 2^d * (n * T(p-1) )
,在哪里d=Δ(G), p=#vertices required, n=|V|
。这真的只是一个猜测。谁能帮我这个?
使用的 powerSet() 算法应该是O(2^d)
or O(d*2^d)
。
private void connectedGraphsOnNVertices(int n, Set<Node> connectedSoFar, Set<Node> neighbours, List<Set<Node>> graphList) {
if (n==1) return;
for (Set<Node> combination : powerSet(neighbours)) {
if (connectedSoFar.size() + combination.size() > n || combination.size() == 0) {
continue;
} else if (connectedSoFar.size() + combination.size() == n) {
Set<Node> newGraph = new HashSet<Node>();
newGraph.addAll(connectedSoFar);
newGraph.addAll(combination);
graphList.add(newGraph);
continue;
}
connectedSoFar.addAll(combination);
for (Node node: combination) {
Set<Node> k = new HashSet<Node>(node.getNeighbours());
connectedGraphsOnNVertices(n, connectedSoFar, k, graphList);
}
connectedSoFar.removeAll(combination);
}
}