04.09.2013 Views

Algorithm Design

Algorithm Design

Algorithm Design

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

558<br />

Chapter 10 Extending the Limits of Tractability<br />

10.2 Solving NP-Hard Problems on Trees<br />

In Section I0.I we designed an algorithm for the Vertex Cover Problem that<br />

works well when the size of the desired vertex cover is not too large. We saw<br />

that finding a relatively small vertex cover is much easier than the Vertex Cover<br />

Problem in its ful! generality.<br />

Here we consider special cases of NP-complete graph problems with a<br />

different flavor--not when the natural "size" parameters are small, but when<br />

the input graph is structurally "simple." Perhaps the simplest types of graphs<br />

are trees. Recall that an undirected graph is a tree if it is connected and has<br />

no cycles. Not only are trees structurally easy to understand, but it has been<br />

found that many NP-hard graph problems can be solved efficiently when<br />

the underlying graph is a tree. At a qualitative level, the reason for this<br />

is the following: If we consider a subtree of the input rooted at some node<br />

u, the solution to the problem restricted to this subtree only "interacts" with<br />

the rest of the tree through v. Thus, by considering the different ways in which<br />

v might figure in the overall solution, we can essentially decouple the problem<br />

in v’s subtree from the problem in the rest of the tree.<br />

It takes some amount of effort to make this general approach precise and to<br />

turn it into an efficient algorithm. Here we will see how to do this for variants<br />

of the Independent Set Problem; however, it is important to keep in mind that<br />

this principle is quite general, and we could equally well have considered many<br />

other NP-complete graph problems on trees.<br />

First we will see that the Independent Set Problem itself can be solved<br />

by a greedy algorithm on a tree. Then we will consider the generalization<br />

called the Maximum-Weight Independent Set Problem, in which nodes have<br />

weight, and we seek an independent set of maximum weight. Weql see that<br />

the Maximum-Weight Independent Set Problem can be solved on trees via<br />

dynamic programming, using a fairly direct implementation of the intuition<br />

described above. ~<br />

A Greedy <strong>Algorithm</strong> for Independent Set on Trees<br />

The starting point of our greedy algorithm on a tree is to consider the way a<br />

solution looks from the perspective of a single edge; this is a variant on an<br />

idea from Section 10.!. Specifically, consider an edge e = (u, v) in G. In any<br />

independent set S of G, at most one of u or v can belong to S. We’d like to find<br />

an edge e for which we can greedily decide which of the two ends to place in<br />

our independent set.<br />

For this we exploit a crucial property of trees: Every tree has at least<br />

one Ieaf--a node of degree 1. Consider a leaf ~, and let (u, u) be the unique<br />

edge incident to v. How might we "greedily" evaluate the relative benefits of<br />

10.2 Solving NP-Hard Problems on Trees<br />

including u or u in our independent set S? If we include u, the only other node<br />

that is directly "blocked" from joining the independent set is u. If we include<br />

u, it blocks not only v but all the other nodes joined to u as well. So if we’re<br />

trying to maximize the size of the independent set, it seems that including u<br />

should be better than, or at least as good as, including u.<br />

maximum-size independent set that contains<br />

Proof. Consider a maximum-size independent set S, and let e = (u, v) be the<br />

unique edge incident to node v. Clearly, at least one of u or v is in S; for if<br />

neither is present, then we could add v to S, thereby increasing its size. Now, if<br />

v ~ S, then we are done; and if u ~ S, then we can obtain another independent<br />

set S’ of the same size by deleting u from S and inserting v. ~<br />

We will use (10.5) repeatedly to identify and delete nodes that can be<br />

placed in the independent set. As we do this deletion, the tree T may become<br />

disconnected. So, to handle things more cleanly, we actually describe our<br />

algorithm for the more general case in which the underlying graph is a forest-a<br />

graph in which each connected component is a tree. We can view the problem<br />

of finding a maximum-size independent set for a forest as really being the same<br />

as the problem for trees: an optimal solution for a forest is simply the union<br />

of optimal solutions for each tree component, and we can still use (10.5) to<br />

think about the problem in any component.<br />

Specifically, suppose we have a forest F; then (10.5) allows us to make our<br />

first decision in the following greedy way. Consider again an edge e = (u, v),<br />

where v is a leaf. We will include node v in our independent set S, and not<br />

include node u. Given this decision, we can delete the node u (since it’s already<br />

been included) and the node u (since it cannot be included) and obtain a<br />

smaller forest. We continue recursively on this smaller forest to get a solution.<br />

To find a maximum-size independent set in a forest F:<br />

Let S be the independent set to be constr~cted ~(initially empty)<br />

While F has at least one edge<br />

Let e=(u,u) be an edge of F such that u is a leaf<br />

Add u to S<br />

Delete from F nodes u and v, and all edges incident to them<br />

Endwhile<br />

Return S<br />

559

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!