/
CMSC  Closest Pair of Points Slides By Carl Kingsford CMSC  Closest Pair of Points Slides By Carl Kingsford

CMSC Closest Pair of Points Slides By Carl Kingsford - PDF document

pamella-moone
pamella-moone . @pamella-moone
Follow
461 views
Uploaded On 2015-04-18

CMSC Closest Pair of Points Slides By Carl Kingsford - PPT Presentation

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

Algorithm Design

Share:

Link:

Embed:

Download Presentation from below link

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.


Presentation Transcript

Findingclosestpairofpoints Problem Givenasetofpointsfp1;:::;png ndthepairofpointsfpi;pjgthatareclosesttogether. GoalBruteforcegivesanO(n2)algorithm:justcheckeverpairofpoints.Canwedoitfaster?Seemslikeno:don'twehavetocheckeverypair?Infact,wecan ndtheclosestpairinO(nlogn)time.What'sareasonable rststep? Merge:thehardcaseLetd=minfdleft;drightg. dwouldbetheanswer,exceptmaybeLsplitaclosepair! SlabMightContainAllPointsLetSybeanarrayofthepointsinthatregion,sortedbydecreasingy-coordinatevalue.Symightcontainallthepoints,sowecan'tjustcheckeverypairinsideit. Theorem SupposeSy=p1;:::;pm.Ifdist(pi;pj)dthenj�i15. 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