Time complexity of enumerating an n-vertex subgraph

I have an algorithm for creating a list of all possible subgraphs on P vertices through a given vertex. This is not ideal, but I think it should work fine. The problem is that I get lost when I try to calculate its time complexity.

I called something like T(p) = 2^d + 2^d * (n * T(p-1) )where d=Δ(G), p=#vertices required, n=|V|. This is just a hunch. Can anyone help me with this?

The powerSet () algorithm used must be 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);
    }
}
+3
source share
1 answer

, , , , , connectedSoFar, , connectedSoFar.size() + .size() n, , node .

, 2 d ; "elase" O (n), connectedSoFar n . connectedSoFar O (n log n) , | | & Leq; . O (n) ; O (d) - k, .

X (n), n - .

X (n) ~ 2 d (n + n log n + n (d + X (n - 1)))

, n .

X (n) ~ 2 d (n (1 + d + log n + X (n - 1)))

d , D = 2 d 1,

X (n) ~ D n (d + log n + X (n - 1))

X (n) ~ (2 d) n n! (d + log n)

, :)

+1

All Articles