Algorithms

# Algorithms - C SC I H om ew ork#So lu t ion P ro f.M ing-D...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C SC I H om ew ork#So lu t ion P ro f.M ing-D ehH uang TA s :Ift ikharBu rhanudd in ,C han sookL im // G au ss ,K ar lF r ied r ich(- ) Itisno tknow ledge ,bu ttheac to f learn ing ,no tpossess ionbu ttheac to fge ttingthere ,wh ichgran tsthegrea test en joym en t.W henIhavec lar iedandexhaustedasub jec t,thenIturnaway from it,inordertogoin todarknessaga in ;thenever-sa tisedm an isso strangeifhehascom p le tedastruc ture ,then itisno tinordertodw e llin itpeace fu lly ,bu tinordertobeg inano ther .Iim ag inethewor ldconqueror m ustfee lthus ,who ,a fteronek ingdom isscarce lyconquered ,stre tchesou t h isarm sforo thers . C orrect ion s G ramm at ica ltyposhavebeenxed . Q.- P k + i = >W hasbeen in serted . Q-c m akechangefor hasbeenchangedto m akechangefor . Q.-thew ord ca ll hasbeenrep lacedby opera tion Q-bthew ord list hasbeenrep lacedby array ).- A lgor ithm : Sorttheitem sby increas ingw e igh t .C hoosetherst k item s suchthat P k i = w i W and P k + i = >W ,w here W isthea llow edw e igh t . G reedy-cho icep roperty : Suppose S theop t im a lso lu t iondoesn 'tcon- ta in a theitemw iththeleastw e igh t ,then ,byrem ov inganyo ftheitem s from thelisto fitem sin S andrep lac ing itw ith a w eob ta in S anew so- lu t ionw h ich ism orep rotab lethantheop t im a lso lu t ion S (s incetheva lue o ftheligh testitem isa lsothegreatest) .T h isisacon trad ict ion !H encethe op t im a lso lu t ionm u stcon ta inthegreedycho ice(theligh testitem ) . O p t im a lsub structu re : L et f a ;a ;:::;a k g betheitem sintheop t im a l so lu t ion( in increas ingordero fw e igh t)and T betheseto fa llthe item s .O u r a lgor ithmw ou ldchoose a asitsrstcho ice .W ec la im that O = f a ;:::;a k g form sanop t im a lso lu t iontothesubp rob lemw herethesetis T ? f a g and therequ iredw e igh tis W ? w ( a ) .Ifnot ,bysuppos ing O istheop t im a l so lu t ion , O [f a g betterstheop t im a lso lu t ion O [f a g .A con trad ict ion ! H enceu s ingas im p leR ep lacem en tstrategyargum en tw ehavep rovedthat anop t im a lso lu t iontotheor ig ina lp rob lem con ta in sanop t im a lso lu t ionto thesubp rob lem . T im eC om p lex ity : Sort ingtakes O ( n log n )t im eandatm ost n check s havetobem adeto k .H encew orstcaserunn ingt im eis O ( n log n ) . ) .- A lgor ithm : L et S = f x ;x ;:::;x n g .Sort S .C hoosetherstun it-length c losed in terva las[ x ;x + ].R em ovea llthepo in tsw h icharecoveredw ith inth isin terva ltoget S andrepeat . G reedy-cho icep roperty : L ettheun it-length in terva l[ y...
View Full Document

## This note was uploaded on 10/02/2011 for the course CS 7300 taught by Professor R during the Spring '11 term at LSU.

### Page1 / 6

Algorithms - C SC I H om ew ork#So lu t ion P ro f.M ing-D...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online