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

后端 未结 7 691
感动是毒
感动是毒 2020-12-28 16:55

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

INPUT:

The node\'s neighbours.

OUTPUT:

The minimum number of vertice

7条回答
  •  长情又很酷
    2020-12-28 17:18

    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.

提交回复
热议问题