What is a good algorithm for getting the minimum vertex cover of a tree?
The node's neighbours.
The minimum number of vertices.
The size of the minimum vertex cover is 1 (by taking either of the endpoints). 3. Star: |V | − 1 vertices, each of degree 1, connected to a central node. The size of the minimum vertex cover is k − 1 (by taking any less vertices we would miss an edge between the remaining vertices).
A vertex-cover of an undirected graph G = (V, E) is a subset of vertices V' ⊆ V such that if edge (u, v) is an edge of G, then either u in V or v in V' or both.
The minimum vertex cover problem is the optimization problem of finding a smallest vertex cover in a given graph. The vertex cover problem is an NP-complete problem: it was one of Karp's 21 NP-complete problems. It is often used in computational complexity theory as a starting point for NP-hardness proofs.
The vertex cover problem is an NP-Complete problem, which means that there is no known polynomial-time solution for finding the minimum vertex cover of a graph unless it can be proven that P = NP. There, however, exists polynomial-time approximate algorithms to find the vertex cover of a graph.
I didn't fully understand after reading the answers here, so I thought I'd post one from here
The general idea is that you root the tree at an arbitrary node, and ask whether that root is in the cover or not. If it is, then you calculate the min vertex cover of the subtrees rooted at its children by recursing. If it isn't, then every child of the root must be in the vertex cover so that every edge between the root and its children is covered. In this case, you recurse on the root's grandchildren.
So for example, if you had the following tree:
A
/ \
B C
/ \ / \
D E F G
Note that by inspection, you know the min vertex cover is {B, C}
. We will find this min cover.
Here we start with A
.
We move down to the two subtrees of B
and C
, and recurse on this algorithm. We can't simply state that B
and C
are not in the cover, because even if AB
and AC
are covered, we can't say anything about whether we will need B
and C
to be in the cover or not.
(Think about the following tree, where both the root and one of its children are in the min cover ({A, D}
)
A
/|\___
B C D
/|\
E F G
)
But we know that AB
and AC
must be covered, so we have to add B
and C
to the cover. Since B
and C
are in the cover, we can recurse on their children instead of recursing on B
and C
(even if we did, it wouldn't give us any more information).
Let C(x)
be the size of the min cover rooted at x
.
Then,
C(x) = min (
1 + sum ( C(i) for i in x's children ), // root in cover
len(x's children) + sum( C(i) for i in x's grandchildren) // root not in cover
)
T(V,E) is a tree, which implies that for any leaf, any minimal vertex cover has to include either the leaf or the vertex adjacent to the leaf. This gives us the following algorithm to finding S, the vertex cover:
Now, all that remains is to verify that if the original tree has only one vertex, we return 1 and never start the recursion, and the minimal vertex cover can be computed.
Edit:
Actually, after thinking about it for a bit, it can be accomplished with a simple DFS variant.
I hope here you can find more related answer to your question.
I was thinking about my solution, probably you will need to polish it but as long as dynamic programing is in one of your tags you probably need to:
After reading this. Changed the above algorithm to find maximum independent set, since in wiki article stated
A set is independent if and only if its complement is a vertex cover.
So by changing min to max we can find the maximum independent set and by compliment the minimum vertex cover, since both problem are equivalent.
{- Haskell implementation of Artem's algorithm -}
data Tree = Branch [Tree]
deriving Show
{- first int is the min cover; second int is the min cover that includes the root -}
minVC :: Tree -> (Int, Int)
minVC (Branch subtrees) = let
costs = map minVC subtrees
minWithRoot = 1 + sum (map fst costs) in
(min minWithRoot (sum (map snd costs)), minWithRoot)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With