24 January
Information Processing Letters 16 (1983) 23-25 North-Holland Publishing Company
A MODIFICATION Kenneth
OF THE GREEDY
ALGORITHM
FOR VERTEX
1983
COVER
L. CLARKSON
Departmenr of Compuier Science, Stanford University, Stanford, CA 94305, U.S.A. Communicated by Michael A. Harrison Received 5 August 1982 Revised 5 September 1982
Keywords: Combinatorial
problems,
computational
complexity
The vertex cover problem for simple undirected graphs is the following: Given a graph G with vertex set V and edge set E, and with weight find a set of vertices Co, function w:V+R+, such that every edge in E meets Co, (is covered) and weight w(C,,) = Z~Ec,,,w(v) is a minimum over all such covers. This problem is NP-complete [6,3], and no known polynomial time algorithm returns a cover with weight guaranteed to be less than double the optimum. Recently, Hochbaum [4] has reported algorithms that have better performance guarantees for certain classes of graphs. In particular, for graphs with all weights equal to 1 (i.e., unweighted) and with all vertex degrees less than some fixed A, an algorithm requiring O(Mfi) time is given returning a cover with weight within a factor of 2 - 2/A of the optimum, i.e., with performance ratio 2 - 2/A. Here M = ]E] and N = IV]. In this note we describe a simple modification of the greedy algorithm requiring O(M log N) time and having a performance ratio of 2 for general weighted graphs. In addition, for unweighted graphs with maximum degree A, and with the weight of the optimum cover Co, less than fN, the algorithm has performance ratio 2 - 2/(A - 2). Further, for any class of unweighted graphs with ]Co,]A < 2N and A -+ 00 with N, the performance ratio approaches 1 asymptotically. The greedy algorithm for finding a vertex cover is the following. 0020-0190/83/0000-0000/$03.00
Q 1983 North-Holland
while
G is not empty do choose V E V with w(v)/dc(v) minimum over all v; add V to Co, delete i; and resulting isolated vertices from G
od
Here de(v) denotes the ‘current’ degree of vertex v. The greedy algorithm has the intuitive appeal that the vertex with the least ‘cost per covered edge’ is put in the cover at each step. However, as Johnson and Lovasz have shown for the unweighted case and Chvatal has shown for the general case, the performance ratio w(Co)/w(C,,,) of the greedy algorithm can be as bad as log N [5,7,2]. Suppose though that the greedy algorithm is modified in the following way: When a vertex v is put in the cover, its edge cost w(v)/dc(v) is subtracted from the weights of each of its current neighbors. Then the resulting algorithm has all the characteristics described above. Put more precisely, let WC(V) denote the ‘current weight’ of v in the algorithm, and et(e) denote the cost of edge e, the weight ‘paid’ to cover e. Then the modified greedy algorithm MG is the following. for all v E V do WC(V)+ w(v) od for all e E E do et(e) + 0 od while G is not empty do
choose V with wc(v)/dc(v)
minimum
over all
v; 23
Volume
16, Number
1
INFORMATION
PROCESSING
W + wc(v)/dc(v); for each {u,i} E E do WC(U)+ WC(U)- W; ec({u,S;}) + W od; WC(V)+ 0; add V to C,,, delete V and resulting isolated vertices from G od
LETTERS
For completeness,
C ec(e>= C eEE
v E C,,,
WC(V) 2 0,
et(e) 2 0
always
for all v E V and e E E, and at the beginning the while loop the condition w(v) = WC(V) +
C
(1) of
C ec((u,v>> ju,v)=n
(2)
for all v, and w(v) =
C ec({u,v>> (u.v)E E
(3)
for all v E C,,. Conditions (l)-(3) imply that the performance ratio of algorithm MG is at most 2, by the proof of Bar-Yehuda and Even [l] of the performance of a different algorithm having an ‘accounting’ function et(e) satisfying conditions (l)-(3). Their proof depends on two facts following from (l)-(3): that w(C,o
>5 2 c
ec(e>
we prove fact (5):
C ec({u,v>> i C w(v), (v,u) E E
VECOPT
c
VEC,,
c
w(v)=
C ec(lu,v>>.
~~Ct”K; (U,V)E E
so that a given edge is counted at most twice in this sum. In fact, if an edge connects v E C,, to a vertex not in C MG, that edge’s cost is overcounted. These facts allow us to prove the slightly sharper performance bounds indicated, when combined with the fact that for graphs with all vertex weights equal to 1
ec({u,v})
holds for all v. This invariant is true before the body of the loop is executed, and for any u affected by the inner loop, the value W is added and subtracted from the invariant for u. Also, a vertex V has de(v) of its edges increase their ec values from 0 to wc(v)/dc@), adding WC@) to the invariant left-hand side, while this value is subtracted on the next line. Therefore, the invariant is true before the main loop begins, and remains true throughout execution. The invariant implies that w(v) 2
1983
since Co, is a vertex cover and by (2). Fact (4) follows from
wG40) =
Although the values et(e) have no effect on the algorithm, they are useful in its analysis. To see that algorithm MG has general performance ratio 2, note that
24 January
throughout the algorithm, where d(v) denotes the degree of vertex v in G. This follows by induction: Suppose the weight of vertex v changes from w to w’, and its degree from d to d - 1. Then by choice of cover vertex, w’ 2 w - w/d, so w(d-1)/d d-l
WI
d_l’
w =z%.
Thus we know that costs of edges belonging to vertices not in the cover are ‘overcounted’, and that edge costs are bounded below by l/A. Further, we may assume w.1.o.g. that no v E V has degree less than 2: isolated vertices may be ignored, and edges from a vertex of degree 1 can be covered by the other vertex without increasing the cost of the cover. Therefore the bound (4) overcounts at least 2(N - w(C,,)) edges costing at least l/A, and it can be improved to
w(CMO
>
5
2(N- w(C,o>)
2W(COPT >-
A
or
(4)
w(CA4f.3) ~ w(CoPT)
(5)
The performance bounds from this inequality.
etE
1
and that C LZCE 24
ec(e> s w(Co,).
indicated
above
follow
Volume
16. Number
1
INFORMATION
Although the performance bounds proven are not significantly better than for known algorithms, it is interesting that such a seemingly small change in the greedy algorithm can improve its asymptotic performance so much.
References [I] R. Bar-Yehuda
and S. Even, A linear-time approximation algorithm for the weighted vertex cover problem, J. Algorithms 2 (1981) 198-203.
PROCESSING
LETTERS
24 January
1983
PI V. ChvBtal, A greedy heuristic for the set-covering
problem, Math. Oper. Res. 3 (1979) 233-235. [31 M.R. Carey and D.S. Johnson, Computers and Intractability (Freeman, San Francisco, 1979). Efficient bounds for the stable set, vertex [41 D.S. Hochbaum, cover, and set packing problems, Appl. Discrete Math., to appear. algorithms for combinatorial [51 D.S. Johnson, Approximation problems, J. Comput. Systems Sci. 9 (1974) 256-278. problems, [61 R.M. Karp, Reducibility among combinatorial in: R.E. Miller and J.W. Thatcher, eds., Complexity of Computer Computations (Plenum Press, New York, 1972). [71 L. LovBsz, On the ratio of optima1 integral and fractional covers, Discrete Math. 13 (1975) 383-390.
25