views:

1368

answers:

3

What is a good algorithm for getting the minimum vertex cover of a tree?

INPUT:

The node's neighbours.

OUTPUT:

The minimum number of vertices.

+3  A: 

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:

  1. For each u vertex define S+(u) is cover size with vertex u and S-(u) cover without vertex u.
  2. S+(u)= 1 + Sum(S-(v)) for each child v of u.
  3. S-(u)=Sum(max{S-(v),S+(v)}) for each child v of u.
  4. Answer is max(S+(r), S-(r)) where r is root of your tree.


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.

Artem Barger
it dosen't help much,I'm looking for a pseudocode or a more detailed explanation on the algorithm
John Retallack
You need to find a way to somehow count the size of cover using information of each vertex, therefore define for each vertex variable which will count for you size there vertex included or not, generally described algorithm will return you the size value, but you can easily extend it to build a sort of the table there you will store your choice at each step.
Artem Barger
it dosen't necessarily need to be dynamic-programming
John Retallack
so perform exhaustive search. I think you are looking for more effective way, so it would be a dynamic programming.
Artem Barger
exhaustive search won't work,too inefficient
John Retallack
Beggars can't be choosers. He told you exactly what you should do, and you say "do it differently" so he does. Now you're saying his different-solution isn't good enough. What exactly do you want? The source code?
GMan
I didn't tell nobody "do it differently",I'm just tring to figure out the simplest way to do it, no matter the complexity,but back-tracking is to much
John Retallack
Finding minimum vertex cover is one of the hardest problem in CS, therefore it's could be efficiently solvable only for few cases, so to simplify and optimize it dynamic programing could be very useful, since it could give you solution in less time complexity than most over approaches. I'm not sure you will find another way to optimize it rather than backtracking. And read this, it could help you http://en.wikipedia.org/wiki/Dynamic_programming.
Artem Barger
I still don't get something ,If I have a node(u) who has two leafs as children,then both children will have S+(v1)=1 , S-(v1)=0( S+(v2)=1 S-(v2)=0) so (u) will have S+(u)=1+S-(v1)+S-(v2)=1 and S-(u)=0,what am I doing wrong ?,a simple exemple will be welcomed
John Retallack
"Finding minimum vertex cover is one of the hardest problem in CS, therefore it's could be efficiently solvable only for few cases ",I know that finding a minimum cover is a NP-complete problem if I'm looking for the minimum cover for a graph,but my case is simpler as I'm looking for the minimum cover of a tree
John Retallack
That the reason you can compute it efficiently, only because you can use the recursive structure of the tree. I give you a simple example:vertex v has two children u1 and u2. S+(u1)=S+(u2)=1 and S-(u1)=S-(u2)=0, so S+(u)=1, S-(u)=2, therefore solution is min{1,2}. You can deduce from it vertex cover is only v and has size of 1.
Artem Barger
BTW, the recursive structure of the tree is definitely pointing on backtracking solution.
Artem Barger
how come S-(u) is 2 when above you wrote that S-(u)=Sum(min{S-(v),S+(v)}).isn't it max{S-(v),S+(v)}
John Retallack
I think I have a mistake, need to think and I'll update my post.
Artem Barger
I've a reduction to slight different problem, but once you solve it it will solve also the original one.
Artem Barger
there still is a mistake,changing only min to max won't help ,for example: (3)(4) | (3)(1) | | | (0)(1) (0)(1) (0)(1) the example is the following format (S-v)(S+v) and max(S+(r), S-(r)) (where r is the root) is 4,which is obiously wrong
John Retallack
it didn't format the example right,the root (3,4) has a child(3,1) wich has 3 children (0,1) (0,1) (0,1)
John Retallack
As I said now it solves different problem. After you will do the compliment it will give you the solution to the vertex cover problem.
Artem Barger
what do you mean by "do the compliment" ?
John Retallack
Now, my solution will give you the maximum independent set of vertexes, by statement I've wrote above, the complement of this set is minimum vertex cover, by definition given from wiki.
Artem Barger
A: 
{- 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)
Dave
+1  A: 

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:

  1. Find all leaves of the tree (BFS or DFS), O(|V|) in a tree.
  2. If (u,v) is an edge such that v is a leaf, add u to the vertex cover, and prune (u,v). This will leave you with a forest T_1(V_1,E_1),...,T_n(U_n,V_n).
  3. Now, if V_i={v}, meaning |V_i|=1, then that tree can be dropped since all edges incident on v are covered. This means that we have a termination condition for a recursion, where we have either one or no vertices, and we can compute *S_i* as the cover for each *T_i*, and define S as all the vertices from step 2 union the cover of each *T_i*.

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.