Let us suppose that for each node ‘’ in the graph, we consideras the size of minimum vertex cover for a subtree which is rooted at node ‘’.
![]()
![]()
Fig: A undirected graph.
Vertex cover is a set of vertices that includes at least one endpoint of every edge of the graph. In order to find the size of smallest vertex cover of the given graph, we will use dynamic programming approach where we will find out all possible vertex cover of all subproblems and then select that vertex cover which is smallest.
Our base condition will be when our node ‘u’ is leaf node. In this case, . This is because we cannot obtain subtree from leaf node.
For any internal node of a subtree, we have:
On solving the above recursive equation, we will get output as , where r is the root of the tree. Thus,is the size of the minimum vertex cover. The algorithm according to the above stated recursion relation, solve all the subproblem in order of decreasing depth of the tree.
This recursion will run in linear time that is
