We have been given tree lets say T with vertices set V, now try giving an algorithm to find the minimum cardinality subset of vertices W. Given every vertex in the set V has an edge with at least one vertex in set W.
1 Answers
This can be solved in linear time by a recursive algorithm. Start by selecting a root for the tree, and building a list of children for each vertex. We say that a set of vertices "covers" a subtree if every vertex in the subtree (except possibly the root of the subtree) is either in the set or adjacent to a member of the set.
The algorithm takes as input a vertex v
in this tree, and returns a tuple of three numbers, which are the minimum cardinalities of subsets covering v
's subtree which respectively (a) include the vertex v
, (b) do not include v
but do include at least one of v
's children, and (c) include neither v
nor any of v
's children.
The base case of the algorithm is to return the tuple (1, 0, 0)
when the input v
is a leaf node. In the recursive case, the tuple (a, b, c)
can be computed from the results of recursively calling the algorithm on v
's children. Rather than solve the whole problem for you, I will leave it to you to figure out how to do this.
The final answer is then min(a, b, c+1)
where a, b, c
are the results from calling the algorithm on the root node.

- 47,440
- 4
- 68
- 97