123
evenalogarithmictimesearchforeachdeletionfound.Intheworstcase,manyintervals
mayhavetobeexaminedwithoutevennecessarilyadvancinginthesequence.
Figure6.4showsonepatternthatcausesinefficiencyinenumeratingdeletions.Changes
1,2,and3alloverlapinsuchawaythateachmustbeexaminedindividually,requiringthat
3deletionsbefoundandtested,eventhoughtheentireregionU1isinfactdeleted.
1
234
U1 U2
F F F F iii ig g g gu u u ur r r re e e e 6666....4444:::: OOOOvvvveeeerrrrllllaaaappppppppiiiinnnngggg ddddeeeelllleeeettttiiiioooonnnnssss aaaannnndddd uuuunnnniiiioooonnnn rrrreeeeggggiiiioooonnnnssss
Inpractice,thecostofcheckingmultipledeletionsisprobablynottoobad,butanalter-
nativeapproachispossible,whichmakesdeletionandenumerationofdeletedintervalsfast,
attheexpenseofspeedfor(themuchmoreinfrequent)undooperation.Thebasicideaisto
retainafullintervaltreeofallactivedeletionsinaversion,buttoaugmentthiswithan
indexedlistofdisjointunionsegments,likeU1andU2.Sincethesesegmentsaredisjoint,
logarithmicupdateandsearchtimecanbeguaranteedbyindexingthembystartingpoint,
withoutanyneedforfanciersearchstructures.Newdeletionscanbeaddedinlogarithmic
timebyfindingtheuniquesegment,ifany,thatoverlapsthestartingpointofthenewseg-
mentaswellastheonethatoverlapsitsendingpoint.Ifthesesegmentsexist,thenthey
aredeletedinlogarithmictime,andanewsegmentrepresentingtheunionofallthreeis
insertedinlogarithmictime.
Whenadeletionisundone,itwillshortenorsplitaunionsegment.Thesectionofthe
disjointdeletionlistcoveredbythedeletionbeingundonewillbecomeinvalidbecauseof
theunknownnumberofoverlappingdeletionsintheintervalitcovered.Theindexcouldbe
rebuiltimmediately,orincrementally.ExecutiontimeforrebuildingthefromscratchisO(n
logn)foranactiveversionwithndeletions.
124
However,sincethetypicaldeletionwillbesmallcomparedtothetotalsizeofthese-
quence,anincrementalrebuildingstrategyismoresensible.Eachsegmentinthecomplete
deletiondatabasethatoverlapstheundoneoperationissimplyre-insertedintounionseg-
mentindex.Forshortdeletionsthisismuchfaster,butintheworstcase,theruntimefor
theincrementalstrategyisstillO(nlogn).Upton 1segmentsmighthavetobeinserted,
eachatacostofO(log n)time,ifthedeletionbeingundoneoverlapsallotherdeletions,and
theyaretotallydisjoint.
6.6 Indexingmoveoperations
Moveoperationsverysimilartodeletionoperations,butbuildinganefficientindexof
movesourcerangesistrickierproblem,sincemoveoperationsneedtobecomparedwith
eachotherforpriority.Whendeterminingifaregionhasbeenmovedelsewhere(sothatit
shouldbeignoredinthecurrentcontext),weneedtoperformamorecomplexquerythan
simplesegmentintersection.Whenexamininganaddressthatispartoftheresultofamove
operation,weneedtoknownotifthesourcerangeisquestionhasbeenmovedbyanyop-
eration,butifithasbeenmovedbyanyoperationwithahigherpriority.Theuseofpriori-
tiesensuresthatsourceregionsare“greedy,”witheachaddressinoverlappingmovescopes
beingclaimedbyonlyonemoveoperation.
Ifmoveprioritiesarecompletelyarbitrary(astheywereinthemodeldefinitions),then
thisisadifficultmultidimensionalsearchproblemonthestart,endandpriorityofthemove
operation.However,weobservedinSection3.3.3thatthechoiceofpriorityfunctionisal-
mostcompletelyarbitrary,exceptthatmovesourcesthatarecompletelycontainedwithin
anothermovesourcetoshouldtakepriorityoverthecontainingregion.Thisallowsthe
preservationofinternalrearrangementsevenwhenalargermoveshiftsalongsubsequence.
Givingprioritytoinnerregionsinnestedsourcescopescanbeassuredbygivingpriorityto
thosesourceregionswhoserightendpointissmaller.Whileoverlappingregionsthatarenot
Previous Page Next Page