//0 CSE, Wntr 0 Grdy Algorthms Chaptr Grdy Algorthms Bn Brnbaum Wdad Machmouch Slds by Kvn Wayn. Copyrght 00 Parson-Addson Wsly. All rghts rsrvd. Slds adaptd rom Larry Ruzzo, Stv Tanmoto, and Kvn Wayn Intrval Schdulng. Intrval Schdulng Intrval schdulng. Job starts at s and nshs at. Two obs compatbl thy don't ovrlap. Goal: nd maxmum subst o mutually compatbl obs. a b c d g 0 0 h Tm
//0 Intrval Schdulng: Grdy Algorthms Intrval Schdulng: Grdy Algorthms Grdy tmplat. Consdr obs n som natural ordr. Tak ach ob provdd t's compatbl wth th ons alrady takn. Grdy tmplat. Consdr obs n som natural ordr. Tak ach ob provdd t's compatbl wth th ons alrady takn. [Earlst start tm] Consdr obs n ascndng ordr o s. [Earlst nsh tm] Consdr obs n ascndng ordr o. countrxampl or arlst start tm [Shortst ntrval] Consdr obs n ascndng ordr o - s. [Fwst conlcts] For ach ob, count th numbr o conlctng obs c. Schdul n ascndng ordr o c. countrxampl or shortst ntrval countrxampl or wst conlcts Intrval Schdulng: Grdy Algorthm Intrval Schdulng: Analyss Grdy algorthm. Consdr obs n ncrasng ordr o nsh tm. Tak ach ob provdd t's compatbl wth th ons alrady takn. Sort obs by nsh tms so that... n. st o obs slctd A φ or = to n { (ob compatbl wth A) A A {} } rturn A Grdy: Thorm. Grdy algorthm s optmal. P. (by contradcton) Assum grdy s not optmal, and lt's s what happns. Lt,,... k dnot st o obs slctd by grdy. Lt,,... m dnot st o obs n th optmal soluton wth =, =,..., r = r or th largst possbl valu o r. r r+ ob r+ nshs bor r+ Implmntaton. O(n log n). Rmmbr ob * that was addd last to A. Job s compatbl wth A s *. OPT: r r+ why not rplac ob r+ wth ob r+?...
//0 Intrval Schdulng: Analyss Thorm. Grdy algorthm s optmal.. Intrval Parttonng P. (by contradcton) Assum grdy s not optmal, and lt's s what happns. Lt,,... k dnot st o obs slctd by grdy. Lt,,... m dnot st o obs n th optmal soluton wth =, =,..., r = r or th largst possbl valu o r. ob r+ nshs bor r+ Grdy: r r+ OPT: r r+... soluton stll asbl and optmal, but contradcts maxmalty o r. Intrval Parttonng Intrval Parttonng Intrval parttonng. Lctur starts at s and nshs at. Goal: nd mnmum numbr o classrooms to schdul all lcturs so that no two occur at th sam tm n th sam room. Intrval parttonng. Lctur starts at s and nshs at. Goal: nd mnmum numbr o classrooms to schdul all lcturs so that no two occur at th sam tm n th sam room. Ex: Ths schdul uss classrooms to schdul 0 lcturs. Ex: Ths schdul uss only. c d g c d b h b g a a h :0 0 0:0 :0 :0 :0 :0 :0 :0 Tm :0 0 0:0 :0 :0 :0 :0 :0 :0 Tm
//0 Intrval Parttonng: Lowr Bound on Optmal Soluton Intrval Parttonng: Grdy Algorthm D. Th dpth o a st o opn ntrvals s th maxmum numbr that contan any gvn tm. Grdy algorthm. Consdr lcturs n ncrasng ordr o start tm: assgn lctur to any compatbl classroom. Ky obsrvaton. Numbr o classrooms ndd dpth. Ex: Dpth o schdul blow = schdul blow s optmal. a, b, c all contan :0 Q. Dos thr always xst a schdul qual to dpth o ntrvals? c d Sort ntrvals by startng tm so that s s... s n. d 0 numbr o allocatd classrooms or = to n { (lctur s compatbl wth som classroom k) schdul lctur n classroom k ls allocat a nw classroom d + schdul lctur n classroom d + d d + } b g a :0 :0 0 0:0 :0 :0 :0 h :0 :0 Tm Implmntaton. O(n log n). For ach classroom k, mantan th nsh tm o th last ob addd. Kp th classrooms n a prorty quu. Intrval Parttonng: Grdy Analyss Obsrvaton. Grdy algorthm nvr schduls two ncompatbl lcturs n th sam classroom.. Schdulng to Mnmz Latnss Thorm. Grdy algorthm s optmal. P. Lt d = numbr o classrooms that th grdy algorthm allocats. Classroom d s opnd bcaus w ndd to schdul a ob, say, that s ncompatbl wth all d- othr classrooms. Ths d obs ach nd atr s. Snc w sortd by start tm, all ths ncompatblts ar causd by lcturs that start no latr than s. Thus, w hav d lcturs ovrlappng at tm s + ε. Ky obsrvaton all schduls us d classrooms.
//0 Schdulng to Mnmzng Latnss Mnmzng Latnss: Grdy Algorthms Mnmzng latnss problm. Sngl rsourc procsss on ob at a tm. Job rqurs t unts o procssng tm and s du at tm d. I starts at tm s, t nshs at tm = s + t. Latnss: l = max { 0, - d }. Goal: schdul all obs to mnmz maxmum latnss L = max l. Ex: t Grdy tmplat. Consdr obs n som ordr. [Shortst procssng tm rst] Consdr obs n ascndng ordr o procssng tm t. [Earlst dadln rst] Consdr obs n ascndng ordr o dadln d. d [Smallst slack] Consdr obs n ascndng ordr o slack d - t. latnss = latnss = 0 max latnss = d = d = d = d = d = d = 0 0 Mnmzng Latnss: Grdy Algorthms Mnmzng Latnss: Grdy Algorthm Grdy tmplat. Consdr obs n som ordr. Grdy algorthm. Earlst dadln rst. [Shortst procssng tm rst] Consdr obs n ascndng ordr o procssng tm t. Sort n obs by dadln so that d d d n t 00 d countrxampl [Smallst slack] Consdr obs n ascndng ordr o slack d - t. 0 0 t 0 or = to n Assgn ob to ntrval [t, t + t ] s t, t + t t t + t output ntrvals [s, ] max latnss = t d 0 0 countrxampl d = d = d = d = d = d = 0 0 0
//0 Mnmzng Latnss: No Idl Tm Mnmzng Latnss: Invrsons Obsrvaton. Thr xsts an optmal schdul wth no dl tm. d = d = d = 0 0 D. Gvn a schdul S, an nvrson s a par o obs and such that: < but schduld bor. nvrson bor swap d = d = d = 0 0 [ as bor, w assum obs ar numbrd so that d d d n ] Obsrvaton. Th grdy schdul has no dl tm. Obsrvaton. Grdy schdul has no nvrsons. Obsrvaton. I a schdul (wth no dl tm) has an nvrson, t has on wth a par o nvrtd obs schduld conscutvly. Mnmzng Latnss: Invrsons Mnmzng Latnss: Analyss o Grdy Algorthm D. Gvn a schdul S, an nvrson s a par o obs and such that: < but schduld bor. nvrson bor swap atr swap Clam. Swappng two conscutv, nvrtd obs rducs th numbr o nvrsons by on and dos not ncras th max latnss. ' Thorm. Grdy schdul S s optmal. P. Dn S* to b an optmal schdul that has th wst numbr o nvrsons, and lt's s what happns. Can assum S* has no dl tm. I S* has no nvrsons, thn S = S*. I S* has an nvrson, lt - b an adacnt nvrson. swappng and dos not ncras th maxmum latnss and strctly dcrass th numbr o nvrsons ths contradcts dnton o S* P. Lt l b th latnss bor th swap, and lt l ' b t atrwards. l ' k = l k or all k, l ' l I ob s lat: l = = d d (dnton) ( nshs at tm ) d ( < ) l (dnton)
//0 Grdy Analyss Stratgs Grdy algorthm stays ahad. Show that atr ach stp o th grdy algorthm, ts soluton s at last as good as any othr algorthm's.. Mnmum Spannng Tr Structural. Dscovr a smpl "structural" bound assrtng that vry possbl soluton must hav a crtan valu. Thn show that your algorthm always achvs ths bound. Exchang argumnt. Gradually transorm any soluton to th on ound by th grdy algorthm wthout hurtng ts qualty. Othr grdy algorthms. Kruskal, Prm, Dkstra, Human, Mnmum Spannng Tr Applcatons Mnmum spannng tr. Gvn a connctd graph G = (V, E) wth ralvalud dg wghts c, an MST s a subst o th dgs T E such that T s a spannng tr whos sum o dg wghts s mnmzd. MST s undamntal problm wth dvrs applcatons. Ntwork dsgn. tlphon, lctrcal, hydraulc, TV cabl, computr, road 0 G = (V, E) T, Σ T c = 0 Cayly's Thorm. Thr ar n n- spannng trs o K n. Approxmaton algorthms or NP-hard problms. travlng salsprson problm, Stnr tr Indrct applcatons. max bottlnck paths LDPC cods or rror corrcton mag rgstraton wth Rny ntropy larnng salnt aturs or ral-tm ac vrcaton rducng data storag n squncng amno acds n a protn modl localty o partcl ntractons n turbulnt lud lows autocong protocol or Ethrnt brdgng to avod cycls n a ntwork can't solv by brut orc
//0 Grdy Algorthms Grdy Algorthms Kruskal's algorthm. Start wth T = φ. Consdr dgs n ascndng ordr o cost. Insrt dg n T unlss dong so would crat a cycl. Smplyng assumpton. All dg costs c ar dstnct. Cut proprty. Lt S b any subst o nods, and lt b th mn cost dg wth xactly on ndpont n S. Thn th MST contans. Prm's algorthm. Start wth som root nod s and grdly grow a tr T rom s outward. At ach stp, add th chapst dg to T that has xactly on ndpont n T. Uss th sam approach as Dkstra s algorthm that you v sn bor. Cycl proprty. Lt C b any cycl, and lt b th max cost dg blongng to C. Thn th MST dos not contan. C S Rmark. All ths algorthms produc an MST. s n th MST s not n th MST 0 Cycls and Cuts Cycl-Cut Intrscton Cycl. St o dgs th orm a-b, b-c, c-d,, y-z, z-a. Clam. A cycl and a cutst ntrsct n an vn numbr o dgs. Cycl C = -, -, -, -, -, - Cycl C = -, -, -, -, -, - Cutst D = -, -, -, -, - Intrscton = -, - Cutst. A cut s a subst o nods S. Th corrspondng cutst D s th subst o dgs wth xactly on ndpont n S. Cut S = {,, } Cutst D = -, -, -, -, - P. (by pctur) S C V - S
//0 Grdy Algorthms Grdy Algorthms Smplyng assumpton. All dg costs c ar dstnct. Smplyng assumpton. All dg costs c ar dstnct. Cut proprty. Lt S b any subst o nods, and lt b th mn cost dg wth xactly on ndpont n S. Thn th MST T* contans. Cycl proprty. Lt C b any cycl n G, and lt b th max cost dg blongng to C. Thn th MST T* dos not contan. P. (xchang argumnt) Suppos dos not blong to T*, and lt's s what happns. Addng to T* crats a cycl C n T*. Edg s both n th cycl C and n th cutst D corrspondng to S thr xsts anothr dg, say, that s n both C and D. T' = T* { } - { } s also a spannng tr. Snc c < c, cost(t') < cost(t*). Ths s a contradcton. S P. (xchang argumnt) Suppos blongs to T*, and lt's s what happns. Dltng rom T* crats a cut S n T*. Edg s both n th cycl C and n th cutst D corrspondng to S thr xsts anothr dg, say, that s n both C and D. T' = T* { } - { } s also a spannng tr. Snc c < c, cost(t') < cost(t*). Ths s a contradcton. S T* T* Kruskal's Algorthm: Proo o Corrctnss Lxcographc Tbrakng Kruskal's algorthm. [Kruskal, ] Consdr dgs n ascndng ordr o wght. Cas : I addng to T crats a cycl, dscard accordng to cycl proprty. Cas : Othrws, nsrt = (u, v) nto T accordng to cut proprty whr S = st o nods n u's connctd componnt. To rmov th assumpton that all dg costs ar dstnct: prturb all dg costs by tny amounts to brak any ts. Impact. Kruskal and Prm only ntract wth costs va parws comparsons. I prturbatons ar sucntly small, MST wth prturbd costs s MST wth orgnal costs..g., all dg costs ar ntgrs, prturbng cost o dg by / n v S Implmntaton. Can handl arbtrarly small prturbatons mplctly by brakng ts lxcographcally, accordng to ndx. u Runnng Tm: O(m log n) Cas Cas
//0 MST Algorthms: Thory Dtrmnstc comparson basd algorthms. O(m log n) [Jarník, Prm, Dkstra, Kruskal, Boruvka] O(m log log n). [Chrton-Taran, Yao ] O(m β(m, n)). [Frdman-Taran ] O(m log β(m, n)). [Gabow-Gall-Spncr-Taran ] O(m α (m, n)). [Chazll 000] Holy gral. O(m). Notabl. O(m) randomzd. [Kargr-Kln-Taran ] O(m) vrcaton. [Dxon-Rauch-Taran ] Eucldan. -d: O(n log n). k-d: O(k n ). comput MST o dgs n Dlaunay dns Prm 0