VC Tree
VC Tree
Assumption: The rooted binary tree T is given as part of the input. A post order traversal
of the rooted tree T ensures that for every node u that is not a leaf, both its children appear
before u.
For every node x ∈ V ( T), let Tx be the subtree of T rooted at the node x.
Subproblem Definition:
For every node x ∈ V ( T ), we define three subproblems.
• MVC( x, 0) be the weight of a minimum weight vertex cover of Tx that does not
contain x.
1
Recurrence of subproblem:
The recurrence of the subproblems MVC will look at the values for its two children and
will solve it.
Base Case: If x is a leaf, then MVC( x, 0) = 0 since Tx is just a single node tree and trivially
∅ is a vertex cover of Tx and that is the only possible vertex cover for the subproblem
MVC( x, 0). Similarly, { x } is the only possible vertex cover for the subproblem MVC( x, 1).
Hence, MVC( x, 1) = wt( x ).
Non-Leaf nodes: Let x1 and x2 be two children of x. Then, we have the followings.
Algorithm Description:
1. Let ρ be a post order traversal of the vertices of tree T. Note that the root r appears
at the end, and for every other node x, their children appear before x.
2. Process the nodes in the order in which they appear in ρ.
3. Repeat the following steps for every node.
4. If x is a leaf, then set A[ x, 0] = 0, i.e. the value of MVC( x, 0) and A[ x, 1] = wt( x ), i.e.
the value of MVC( x, 1). Set A[ x, 2] = min( A[ x, 0], A[ x, 1]).
5. If x is not a leaf, then let x1 and x2 be its two children. Set A[ x, 0] = A[ x1 , 1] +
A[ x2 , 1]. Set A[ x, 1] = wt( x ) + A[ x1 , 2] + A[ x2 , 2]. Set A[ x, 2] = min{ A[ x, 0], A[ x, 1]}.
6. Finally, return A[r, 2] where the root r appears at the last.
Running Time: Computing post order traversal of a rooted tree takes O(n)-time where
n is the number of nodes in a tree (binary) rooted at r. Hence, the ordering ρ is a post-
order traversal of the nodes of the tree. The root appears at the end. For every leaf node
x (including checking whether x is a leaf or not), computing MVC( x, 0), MVC( x, 1) and
VC( x ) take O(1)-time. If x has some child, then the following happens. Suppose that x
has t children. Then, accessing each of its children takes O(1)-time and then time taken
to compute the value MVC( x, 1) takes O(t)-time computing and MVC( x, 0) takes O(t)-
time. Since t = 2 here as T is a binary tree, computing MVC( x, 1) and MVC( x, 0) both take
O(1)-time. Finally, computing VC( x ) takes O(1)-time. Therefore, the total running time
is O(n).
2
Advise for assignment and exam: You must write the above mentioned details in parts
when you answer a DP question in the exam. Remember that DP recurrence is separate
from the algorithm description. You can write a pseudocode that can use memoization
method or method of filling up table. The above algorithm uses filling up of table that
is the same as tabulation method. In summary, your solution must contain the following
components.
• Subproblem definition.
Exercise: Even if the tree T is not a binary tree, you can design a dynamic programming
algorithm with designing exactly the same subproblem definition. Think what the recur-
rence of the subproblem will be. A small change will work out. But it is your exercise
to figure it out. Also, think a high level idea how you can implement that algorithm in
O(n)-time.