CS 663: Patter Matchg Algorthms Scrbe: Che Jag /9/00. Itroducto PTAS for B-Packg The B-Packg problem s NP-hard. If we use approxmato algorthms, the B-Packg problem could be solved polyomal tme. For example, the smplest approxmato algorthm s the Frst-ft algorthm, whch solves the B-Packg problem tme O ( log ). We use the approxmato factor to determe how good our approxmato algorthm s. Let A (I ) be the umber of bs requred by the approxmato algorthm, ad let OPT (I ) be the optmal umber of requred bs for put I. We say that algorthm A has approxmato factor C f for every put I: A ( I ) C OPT ( I ) ( C ) Ths equalty meas that the approxmato algorthm would ot use more tha C tmes the optmal umber of bs, whch s also the upper boud of Obvously, the closer C s to, the better the approxmato. the approxmato algorthm. Clam: The B-Packg problem has a PTAS (Polyomal Tme Approxmato Scheme). I.e., Gve > 0, oe ca always produce approxmato algorthm whose () tme s polyomal ad ; ad () whose approxmato factor s, A( I ) (+ ) OPT ( I ). Specal Cases for B-Packg Before provg that the B-Packg problem has a PTAS, frst cosder two Specal Cases for B-Packg to get some terestg coclusos.. Case : All tem szes less tha δ Clam : If tem sze u < δ for = to, the FF( I ) (+ ) OPT ( I ) + FF (I ) = the umber of bs of Frst-ft algorthm.
Proof f δ / Q FF( I ) OPT ( I ) + (Proved by Frst-ft) ad δ / + FF( I ) OPT ( I ) + (+ ) OPT ( I ) + f δ < / The above fgure shows the stuato at the ed of rug the Frst-ft. Sce all tem szes are less tha δ, there would be less the δ empty space each b (except, possbly, for the last b). So, the flled part (blue) = u ( FF( I ) )( δ ), FF ( I ) s the umber of bs, = δ s the smallest empty space wth ay b. Aother way of thkg = u s that suppose we could smash all the tems & bled them, ad the put them to bs wthout leavg ay spare space. OPT (I ). = u ca ot be more tha Therefore, ( FF( I ) )( δ ) = u OPT ( I ) FF ( I ) OPT ( I ) /( δ ) But /( δ ) +, Q ( + )( δ ) = + δ ( ) ad δ < / 0< ( + )( δ ) FF( I ) OPT ( I ) /( δ ) (+ ) OPT ( I ) FF( I ) (+ ) OPT ( I ) +
Clam proved.. Case : There are oly k dfferet szes of tems Clam : If there are oly k dfferet szes of tems, + OPT (I ) could be foud determstcally tme O ( k ) wthout usg approxmato algorthm. Proof Observato: The umber of subsets of elemets s expoetal ( ) the geeral case, whle the umber of subset s polyomal O ( k ) the case where k s fxed. Why? Sort the tems by sze, the dvde the tems to k groups. Deote a subset by a k-tuple of the umber of elemets of each sze the subset. Example..., Suppose tems {/, /4, /3, /7, /9, /, /3, /4, /9} k(=5) groups {/, /4, /3, /7, /9} k We could deote subset {/, /4, /3, /9, /9} by <,,, 0, >, where represets the umber of tmes /9 appeared. Obvously, all of these umbers caot greater tha. So we have O ( k ) subsets. Compute OPT (I ) Usg dyamc programmg. Fd the subsets that ca be packed b Fd the subsets that ca be packed bs Observato: each of these subsets Fd the subsets that ca be packed OPT(I) bs must be composed of two subsets, each of whch ca be packed b
Sce OPT ( I ). There are teratos at most, ad each teratos has O( k ) subsets. Implemetato Step. Sort the subsets by the sum of ther szes. Those wth sum ot exceedg ca be packed a sgle b. Call them -b subsets. Step. For all pars of -b subsets, cosder ther uo. Every uo that s ot a -b subset s a -b subset. Step +. For all pars cosstg of a -b subset ad a -b subset, cosder ther uo. If t s ot a -b subset or less, the t s a (+)-b subset. If the etre set s packed doe, else cotue to ext step. Tme k We cosder all pars each terato, thus tme s O (( ) ) = O ( k ) per terato. + Sce there are o more tha teratos, total tme s O ( k ). Clam proved. 3. Prove PTAS for B-Packg 3. Specal cases To prove PTAS for B-Packg problem, frst cosder two specal cases. Gve I { s s... } = ad, s 3.. Case : all tem szes are o more the / Clam 3: If tem sze u / for = to, A( I ) (+ ) OPT ( I ) + Proof Usg Clam drectly. 3.. Case : all tem szes are more the / Clam 4: If tem sze u > / for = to, There exsts a packg algorthm PA wth approxmato factor PA(I) (+)OPT(I)+
Proof Fx k (we wll later see how to choose t), the cosder the followg approxmato algorthm. Step. Sort I o-decreasg order. Splt to k groups of k elemets each. Step. Pack the frst group G at most k bs, because we have k elemets G Step 3. Costruct set I`. Dscard G frst, ad the chage all umbers each group to largest umber group. Step 4. Fd OPT (I`) by usg the method.. Tme. Sortg: O ( log). Packg frst group: O () 3. Costructg I`: O () 4. Fdg OPT(I`): O ( / k + ). Sce we dvde I to k groups, there are o more tha k - dfferet szes of tems I`, so that we could use Clam. Coclude: Tme O ( / k + ) Approxmato Factor Sce we used k bs to pack the frst group ad OPT(I`) bs to pack the rest of groups, we have approxmato factor: PA ( I ) = OPT ( I`) + k Lemma: OPT ( I`) OPT ( I ) Proof G / Costruct set I``. Dscard the last group k frst, ad the chage all umbers each
group to the smallest umber group. Example G G G3 G4 I 0 9 8 7 7 6 6 6 5 3 I`` 8 8 8 6 6 6 5 5 5 dscarded I` dscarded 7 7 7 6 6 6 3 3 Clearly OPT ( I``) OPT ( I ), because there are less elemets I`` ad the sze of elemets are smaller. Also OPT ( I`) OPT ( I``), because f compare G set I`` wth G + set I` (showed red arrow), we see that () all the sze of elemets I`s group are o more tha those I``s group; ad () the umber of elemets I`s group s o more tha those I``s group. Coclude, OPT ( I`) OPT ( I``) OPT ( I ) 3 Choose k Approxmato Factor Q PA ( I ) = OPT ( I`) + k Ad OPT ( I`) OPT ( I ) PA ( I ) OPT ( I ) + k Now choose k = = S Sce u OPT ( I ) s proved., = = u OPT ( I ) k OPT ( I ) + A( I ) OPT ( I ) + k ( + ) OPT ( I ) + Therefore, PA( I ) ( + ) OPT ( I ) + Tme
= k = S S = But s > / for = to, so: k S = = = + 4 + Therefore, Rug Tme O ( ) = O ( ) Sce s gve (fxed), ths packg algorthm s polyomal. 3. Geeral case Implemetato Clam 4 proved. Step. Splt tems to two sets: small ( s / ) ad large ( s > / ). Step. Hadle large tems as Clam 4. Step 3. Use FF to pack small tems to remag spaces of large tem bs. Whe all such space s used, ope ew bs usg FF. Tme 4 + Obvously Polyomal O ( ) Approxmato Factor Case : All large tem bs are flled, ad ew oes opeed. Ths s the same case as Clam, because we are usg FF to pack the small elemets of the set ( s / ). So the Approxmato Factor s A( I ) (+ ) OPT ( I ) + Case : Not all large tem bs are flled. Use cocluso of Clam 4, A( I ) = PA( I) (+ ) OPT ( I') + (+ ) OPT( I ) + 3.3 Cocluso For B-Packg problem, Gve, we could always propose a Polyomal Tme
Approxmato Scheme whose approxmato factor s ( + ) OPT ( I ), tme s O ( ). Ths cocluso also shows that f we wat to get more close to optmal umber of bs, we eed to pay more tme. For example, f we choose =/00, tme ( 4000 ) although t s polyomal. 4 + O would be awful