0% found this document useful (0 votes)
19 views3 pages

VC Tree

The document describes a dynamic programming algorithm to find the minimum weighted vertex cover of a binary tree. It defines subproblems of finding minimum vertex covers that include or exclude each node, with recurrences that combine solutions for child subproblems. The algorithm runs in O(n) time by processing nodes in postorder and filling a table with subproblem solutions.

Uploaded by

aniketgupta3001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
19 views3 pages

VC Tree

The document describes a dynamic programming algorithm to find the minimum weighted vertex cover of a binary tree. It defines subproblems of finding minimum vertex covers that include or exclude each node, with recurrences that combine solutions for child subproblems. The algorithm runs in O(n) time by processing nodes in postorder and filling a table with subproblem solutions.

Uploaded by

aniketgupta3001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Minimum Weighted Vertex Cover in a Tree

Given an undirected graph G = (V, E), a set S ⊆ V ( G ) is said to be a vertex cover of G


if for every (u, v) ∈ E( G ), u ∈ S or v ∈ S (or both). If the graph is vertex weighted, i.e.
every vertex has a weight, say the vertex v has wt(v), then the weight of a vertex cover
wt(S) = ∑ wt(v).
v∈S
A vertex cover S of a graph G is called a minimum weighted vertex cover of G if wt(S) is
minimum among all possible vertex covers of G.
Problem: The input to the problem is a vertex weighted rooted binary tree T = (V, E)
and wt : V ( T ) → R+ .
Objective: Find a vertex cover with minimum total weight.

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, 1) be the weight of a minimum weight vertex cover of Tx that contains x.

• MVC( x, 0) be the weight of a minimum weight vertex cover of Tx that does not
contain x.

• VC( x ) be the weight of a minimum weight vertex cover of Tx .

Trivially observe that VC( x ) = min{MVC( x, 0), MVC( x, 1)}.


Explanation for the ease of interpretation: Let S be a minimum weight vertex cover of
the tree Tx subject to the constraint that x ∈ S, then S is a representative optimal solution
for the subproblem MVC( x, 1). Similarly, if S is a minimum weight vertex cover of the
tree Tx subject to the constraint that x ∈
/ S, then S is a representative optimal solution for
MVC( x, 0).

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.

MVC( x, 0) = MVC( x1 , 1) + MVC( x2 , 1)

MVC( x, 1) = wt( x ) + VC( x1 ) + VC( x2 )

Finally, VC( x ) = min{MVC( x, 1) + MVC( x, 0)}.


Subproblem that solves the final problem: Solving the subproblems for the root vertex r
solves the final problem. Hence, VC(r ) solves the final problem.

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.

• Recurrence relation for the subproblem.

• The specific subproblem that solves the final problem.

• High level description of the algorithm.

• Explanation of the running time of your algorithm.

Explanations for Correctness of the Recurrence od Subproblem: You have to convince


yourself for the following two statements. Think about it why that is the case. It will be
proof by contradiction.

• Statement-1: Let S be a minimum weight vertex cover of Tx such that x ∈ S, i.e. S is


an optimal solution for MVC( x, 1). Furthermore, let y and z be the two children for
x. Then, S = { x } ∪ Sy ∪ Sz such that Sy is an optimal solution for the subproblem
MVC(y, 1) and Sz is an optimal solution for the subproblem MVC(z, 1).

• Statement-2: Let S be a minimum vertex cover of Tx such that x ∈ / S, i.e. S is an


optimal solution for MVC( x, 0). Furthermore, let y and z be the two children for x.
Then, S = Sy ∪ Sz such that Sy is an optimal solution for the subproblem MVC(y, 1)
and Sz is an optimal solution for the subproblem MVC(z, 1).

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.

You might also like