4 of Algorithm Design by Kleinberg Tardos brPage 2br Finding closest pair of points Problem Given a set of points 64257nd the pair of points that are closest together brPage 3br Goal Brute force gives an algorithm just check ever pair of points Ca ID: 51364
Download Pdf The PPT/PDF document "CMSC Closest Pair of Points Slides By C..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Findingclosestpairofpoints Problem Givenasetofpointsfp1;:::;pngndthepairofpointsfpi;pjgthatareclosesttogether. GoalBruteforcegivesanO(n2)algorithm:justcheckeverpairofpoints.Canwedoitfaster?Seemslikeno:don'twehavetocheckeverypair?Infact,wecanndtheclosestpairinO(nlogn)time.What'sareasonablerststep? Merge:thehardcaseLetd=minfdleft;drightg. dwouldbetheanswer,exceptmaybeLsplitaclosepair! SlabMightContainAllPointsLetSybeanarrayofthepointsinthatregion,sortedbydecreasingy-coordinatevalue.Symightcontainallthepoints,sowecan'tjustcheckeverypairinsideit. Theorem SupposeSy=p1;:::;pm.Ifdist(pi;pj)dthenji15. Inotherwords,iftwopointsinSyarecloseenoughintheplane,theyarecloseinthearraySy. Proof,1Dividetheregionupintosquareswithsidesoflengthd=2: Howmanypointsineachbox? Atmost1becauseeachboxiscompletelycontainedinonehalfandnotwopointsinahalfarecloserthand. LinearTimeMergeTherefore,wecanscanSyforpairsofpointsseparatedbydinlineartime.ClosestPair(Px,Py):if|Px|==2:returndist(Px[1],Px[2])//based1=ClosestPair(FirstHalf(Px,Py))//divided2=ClosestPair(SecondHalf(Px,Py))d=min(d1,d2)Sy=pointsinPywithindofL//mergeFori=1,...,|Sy|:Forj=1,...,15:d=min(dist(Sy[i],Sy[j]),d)Returnd