Upload
shivam-atri
View
212
Download
0
Embed Size (px)
DESCRIPTION
lecture
Citation preview
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 1/46
UMass Lowell Computer Science 91.503
Graduate Algorithmsro!. "aren #aniels
Spring$ %005
Computational GeometryComputational Geometry
Overview from Cormen, et al.Overview from Cormen, et al.
Chapter 33Chapter 33
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 2/46
&'er'iew
Computational Geometr( )ntroductionComputational Geometr( )ntroduction
Line Segment )ntersectionLine Segment )ntersection
Con'e* +ull AlgorithmsCon'e* +ull Algorithms
,earest ,eigh-orsClosest oints ,earest ,eigh-orsClosest oints
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 3/46
)ntroduction
/hat is/hat is
Computational Geometr(Computational Geometr(
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 4/46
Computational Geometry
TelecommunicationsTelecommunications
VisualizationVisualization
ManufacturingManufacturing
ComputerComputer
GraphicsGraphics
Design Analyze
Apply
CADCAD
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 5/46
Sample Application Areas
Computer GraphicsComputer Graphics
GeographicGeographic
Information SystemsInformation Systems
RoboticsRobotics
BioinformaticsBioinformatics
Astrophysics Astrophysics
MeicalMeical
ImagingImaging
TelecommunicationsTelecommunications
Data Mining !Data Mining !
VisualizationVisualization
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 6/46
(pical ro-lems
-in pac2ing -in pac2ing
oronoi diagramoronoi diagram
simpli!(ingsimpli!(ing pol(gons pol(gons
shape similarit(shape similarit(
con'e* hullcon'e* hull
maintaining linemaintaining line
arrangementsarrangements
pol(gon partitioning pol(gon partitioning
nearest neigh-or searchnearest neigh-or search
2d4trees2d4trees
S&UC6S&UC6: Steve Skiena’s Algorithm Design Manual: Steve Skiena’s Algorithm Design Manual
(for problem descriptions see graphics gallery at(for problem descriptions see graphics gallery at http7www.cs.sun(s-.edu8algorith ! !
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 7/46
Common Computational
Geometr( Structures
Voronoi DiagramVoronoi DiagramCon"e# $ullCon"e# $ull
%e& 'oint%e& 'oint
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
Delaunay TriangulationDelaunay Triangulation
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 8/46
Sample ools o! the rade
Algorithm #esign atternsechniues7Algorithm #esign atternsechniues7 -inar( search -inar( search di'ide4and4conuer di'ide4and4conuer dualit(dualit(
randomi:ationrandomi:ation sweep4linesweep4line
derandomi:ationderandomi:ation parallelism parallelismAlgorithm Anal(sis echniues7Algorithm Anal(sis echniues7
as(mptotic anal(sis$ amorti:ed anal(sisas(mptotic anal(sis$ amorti:ed anal(sis
#ata Structures7#ata Structures7
winged4edge$ uad4edge$winged4edge$ uad4edge$ range tree$ 2d4treerange tree$ 2d4treeheoretical Computer Scienceheoretical Computer Science principles7 principles7
,4completeness$ hardness ,4completeness$ hardness
Gro&th of (unctionsGro&th of (unctions
SummationsSummations
RecurrencesRecurrences
SetsSets
'robability'robability
MATHMATH 'roofs'roofs GeometryGeometry
Graph TheoryGraph TheoryCombinatoricsCombinatorics
)inear Algebra)inear Algebra
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 9/46
Computational Geometr(in Conte*t
TheoreticalTheoretical
Computer Computer
ScienceScience
Applie Computer Science Applie Computer Science
Applie Applie
MathMath
GeometryGeometry
ComputationalComputational
GeometryGeometry
EfficientEfficientGeometric AlgorithmsGeometric Algorithms
DesignAnalyze
Apply
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 10/46
Sample o! Supporting Algorithmic ;
Math Areas ; echniues
ComputationalComputationalGeometr(Geometr( Con'e* hullsCon'e* hulls
isi-ilit( pol(gonsisi-ilit( pol(gons ArrangementsArrangements
MathematicalMathematicalrogrammingrogramming Linear programmingLinear programming
)nteger programming)nteger programming Lagrangian rela*ationLagrangian rela*ation Upper$ lower -oundingUpper$ lower -ounding
#(namic #ata#(namic #ataStructuresStructures
Algorithm #esign atternsAlgorithm #esign atterns search space su-di'isionsearch space su-di'ision -inar( search -inar( search di'ide4and4conuer di'ide4and4conuer sweep4linesweep4line discrete4e'ent simulationdiscrete4e'ent simulation
Algorithm Anal(sisAlgorithm Anal(sisechniuesechniues
Comple*it( heor(Comple*it( heor( ,4completeness$ hardness ,4completeness$ hardness
#iscrete Math#iscrete Math Min2ows2i sumMin2ows2i sum Monotone matricesMonotone matrices LatticesLattices Set operations7 union$Set operations7 union$
intersection di!!erence
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 11/46
Line Segment )ntersections
<%#=
)ntersection o! % Line Segments)ntersection o! % Line Segments
)ntersection o! > %Line Segments)ntersection o! > %Line Segments
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 12/46
Cross4roduct4?ased
Geometric rimiti'es
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
pp**
pp++
pp,,
-,.-,.
pp,,
pp//
pp++
-+.-+.
pp++
pp,,
pp//
pp00
-/.-/.
Some funamental geometric 1uestions2Some funamental geometric 1uestions2
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 13/46
Cross4roduct4?ased
Geometric rimiti'es7 <1=
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al. A"antage A"antage2 less sensiti"e to accumulate roun3off error 2 less sensiti"e to accumulate roun3off error
1%%1
%1
%1
%1 det y " y " y y
" " p p −=
=×
pp**
pp++
pp,,
-,.-,.
//4,
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 14/46
Cross4roduct4?ased
Geometric rimiti'es7 <%=
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
pp**
pp++
pp,,
-+.-+.
//4+
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 15/46
)ntersection o! % Line Segments
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
pp++
pp,,
pp//
pp00
-/.-/.
Step 1Step 1::
Bounding BoxBounding Box
TestTest
Step 2Step 2: Does eac: Does eac
segment straddlesegment straddle
te line containingte line containing
te oter!te oter!
//4/
p/ an p0 on opposite sies of p,p+p/ an p0 on opposite sies of p,p+
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 16/46
Segment#Segment $ntersection
@inding the@inding the actual intersection point actual intersection point Approach7 parametric 's. slopeinterceptApproach7 parametric 's. slopeintercept
parametric generali:es to more comple* intersections parametric generali:es to more comple* intersections e.g. segmenttrianglee.g. segmenttriangle
arameteri:e each segmentarameteri:e each segment
Intersection2 "alues ofIntersection2 "alues of ss55 tt such thatsuch that p-s.p-s. 661-t.1-t. 22 a7sAa7sA66c7tCc7tC
aa
bb
cc
))abab))cc
aa
bbcc
))abab))cc
A6b3a A6b3a
p-s.6a7sAp-s.6a7sA
1-t.6c7tC1-t.6c7tCC63cC63c
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C + e1uations in un8no&ns+ e1uations in un8no&ns ss55 tt 2 , for #5 , for y2 , for #5 , for y
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 17/46
#emo
Segment%Segment $ntersectionSegment%Segment $ntersectionhttp7cs.smith.edu8orour2e-oo2sCompGeomCompGeom.htmlhttp7cs.smith.edu8orour2e-oo2sCompGeomCompGeom.html
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 18/46
)ntersection o! >% Line Segment
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
S&eep3)ine Algorithmic 'araigm2S&eep3)ine Algorithmic 'araigm2
//40
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 19/46
)ntersection o! >% Line Segment
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
S&eep3)ine Algorithmic 'araigm2S&eep3)ine Algorithmic 'araigm2
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 20/46
)ntersection o! >% Line Segment
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
Time toTime to detect detect if any +if any +
segments intersect2segments intersect2"#n lg n$"#n lg n$
source: 91.!" te#t$ook Cormen et al.
//49
%ote that it e#its as soon as%ote that it e#its as soon as oneone intersection is etecte4intersection is etecte4
Balance BST stores segments in orerBalance BST stores segments in orer
of intersection &ith s&eep line4of intersection &ith s&eep line4
Associate operations ta8e :-lgn. time4 Associate operations ta8e :-lgn. time4
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 21/46
$ntersection of Segments
GoalGoal7 &utput4si:e sensiti'eB line segment intersection algorithm7 &utput4si:e sensiti'eB line segment intersection algorithmthat actually computesthat actually computes all all intersection pointsintersection points
?entle(4&ttmann plane sweep7?entle(4&ttmann plane sweep7 &<<n2=log<n2==D &<<n2=logn=&<<n2=log<n2==D &<<n2=logn= timetime
2 D num-er o! intersection points in output2 D num-er o! intersection points in output
)ntuition7 sweep hori:ontal line downwards)ntuition7 sweep hori:ontal line downwards Eust -e!ore intersection$ % segments are adEacent in sweep4line intersection structure Eust -e!ore intersection$ % segments are adEacent in sweep4line intersection structure chec2 !or intersectionchec2 !or intersection onlyonly adEacent segmentsadEacent segments insert intersection e'ent into sweep4line structureinsert intersection e'ent into sweep4line structure e'ent t(pes7e'ent t(pes7
top endpoint o! a segmenttop endpoint o! a segment -ottom endpoint o! a segment -ottom endpoint o! a segment intersection bet&een ' segmentsintersection bet&een ' segments
s&ap order s&ap order
Impro"e to :-nlogn78. ;Chazelle<=elsbrunner>Impro"e to :-nlogn78. ;Chazelle<=elsbrunner>source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 22/46
Con'e* +ull Algorithms
#e!initions#e!initionsGi!t /rappingGi!t /rapping
Graham ScanGraham ScanFuic2+ullFuic2+ull
)ncremental)ncremental#i'ide4and4Conuer #i'ide4and4Conuer
Lower ?ound inLower ?ound in ΩΩ<nlgn=<nlgn=
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 23/46
Con'e*it( ; Con'e* +ulls
A con'e* com-ination o! pointsA con'e* com-ination o! points
**11$ ...$ *$ ...$ *2 2 is a sum o! the !ormis a sum o! the !orm
αα11**11...... αα2 2 **2 2 wherewhere
Con'e* hull o! a set o! points is theCon'e* hull o! a set o! points is the
set o! all con'e* com-inations o!set o! all con'e* com-inations o!
points in the set. points in the set.
noncon"e# polygonnoncon"e# polygon
con"e# hull of a point setcon"e# hull of a point set
10 1 =++∀≥ k i and i α α α
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
source: 91.!" te# t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 24/46
,ai'e Algorithms
!or 6*treme oints
AlgoritmAlgoritm2 I%T=RI:R ':I%TS2 I%T=RI:R ':I%TS
for each i ofor each i o
for each ? 6 i ofor each ? 6 i o
for each 8 6 ? 6 i ofor each 8 6 ? 6 i o for each ) 6 8 6 ? 6 i ofor each ) 6 8 6 ? 6 i o
if pif p)) in triangle-pin triangle-p
ii5 p5 p ? ?5 p5 p
88..
then pthen p)) is none#tremeis none#treme "#n"#n%%$$
AlgoritmAlgoritm2 =@TR=M= =DG=S2 =@TR=M= =DG=Sfor each i ofor each i o
for each ? 6 i ofor each ? 6 i o
for each 8 6 ? 6 i ofor each 8 6 ? 6 i o
if pif p88 is not left or on -pis not left or on -p
ii5 p5 p ? ?..
then -pthen -pii 5 p5 p ? ?. is not e#treme. is not e#treme "#n"#n&&
$$source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 25/46
Algorithms: %# Gi!t /rapping
Use one e*treme edge as anUse one e*treme edge as an
anchor !or !inding the ne*tanchor !or !inding the ne*t
θθ
"#n"#n22$$
AlgoritmAlgoritm2 GI(T RA''I%G2 GI(T RA''I%G
ii** ine# of the lo&est point ine# of the lo&est point
i ii i**repeatrepeat for each ? 6 ifor each ? 6 i Compute countercloc8&ise angleCompute countercloc8&ise angle θθ from pre"ious hull egefrom pre"ious hull ege 8 ine# of point &ith smallest8 ine# of point &ith smallest θθ :utput -p:utput -p
ii 5 p5 p88. as a hull ege. as a hull ege
i 8i 866 source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 26/46
Gi!t /rapping source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
//4
"utput Sensiti'ity"utput Sensiti'ity: "#n: "#n22$ run(time is actually "#n$$ run(time is actually "#n$
)ere is te num*er o+ 'ertices o+ te con'ex ull,)ere is te num*er o+ 'ertices o+ te con'ex ull,
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 27/46
Algorithms: 3# Gi!t /rapping
C#%ull AnimationsC#%ull Animations2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html
"#n"#n22$$ timetime
;output sensiti"e2 :-n(. for ( faces on hull>;output sensiti"e2 :-n(. for ( faces on hull>
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 28/46
Algorithms: %# Fuic2+ull
Concentrate on points close toConcentrate on points close tohull -oundar(hull -oundar(
,amed !or similarit( to ,amed !or similarit( toFuic2sortFuic2sort
aa
bb
"#n"#n22
$$
AlgoritmAlgoritm2 EICF $E))2 EICF $E))
function uic8$ull-a5b5S.function uic8$ull-a5b5S. if S 6 * return-.if S 6 * return-. elseelse c ine# of point &ith ma# istance from abc ine# of point &ith ma# istance from ab A points strictly right of -a5c. A points strictly right of -a5c. B points strictly right of -c5b.B points strictly right of -c5b.
return uic8$ull-a5c5A. 7 -c. 7 uic8$ull-c5b5B.return uic8$ull-a5c5A. 7 -c. 7 uic8$ull-c5b5B.source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
fin&s one of upper or lo'er hull fin&s one of upper or lo'er hull
cc
A A
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 29/46
Algorithms: 3# Fuic2+ull
C#%ull AnimationsC#%ull Animations2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 30/46
Algorithms: >D %#
hull2 http2<<&&&4geom4umn4eu<soft&are<1hull<hull2 http2<<&&&4geom4umn4eu<soft&are<1hull<
Con"e# $ullCon"e# $ull
bounary isbounary is
intersection ofintersection of
hyperplanes5 sohyperplanes5 so
&orst3case&orst3casecombinatorial sizecombinatorial size-not necessarily running-not necessarily running
time.time. comple#ity iscomple#ity is
in2in2 =< %d nΘ
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 31/46
Grahams Algorithm
oints sorted angularl( pro'ideoints sorted angularl( pro'idestar4shapedB starting pointstar4shapedB starting point
re'ent dentsB as (ou go 'iare'ent dentsB as (ou go 'ia
con'e*it( testingcon'e*it( testing
"#nlgn$"#nlgn$
AlgoritmAlgoritm2 GRA$AM SCA%5 Version B2 GRA$AM SCA%5 Version B
(in rightmost lo&est point label it p(in rightmost lo&est point label it p**44
Sort all other points angularly about pSort all other points angularly about p**44 In case of tie5 elete point-s. closer to pIn case of tie5 elete point-s. closer to p
**44
Stac8 S -pStac8 S -p,,5 p5 p
**. 6 -p. 6 -ptt5 p5 p
t3,t3,. t ine#es top. t ine#es top
i +i +&hile i H n o&hile i H n o
if pif pii is strictly left of pis strictly left of p
t3,t3,pptt
then 'ush-pthen 'ush-pii5 S. an set i i 7,5 S. an set i i 7,
θθ
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
( ( multipop) multipop)
pp**
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 32/46
Graham Scan
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 33/46
Graham Scan
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
//4
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 34/46
Graham Scan
source: 91.!" te#t$ook Cormen et al source: 91.!" te#t$ook Cormen et al.
//4
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 35/46
Graham Scan
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 36/46
Graham Scan
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 37/46
Algorithms: %# )ncremental
Add points$ one at a timeAdd points$ one at a time update hull !or each new pointupdate hull !or each new point
"e( step -ecomes adding a single point to"e( step -ecomes adding a single point toan e*isting hull.an e*isting hull. @ind % tangents@ind % tangents
esults o! % consecuti'e L6@ tests di!!er esults o! % consecuti'e L6@ tests di!!er
)dea can -e e*tended to 3#.)dea can -e e*tended to 3#.
"#n"#n22$$
AlgoritmAlgoritm2 I%CR=M=%TA) A)G:RIT$M2 I%CR=M=%TA) A)G:RIT$M
)et $)et $++ Con"e#$ullJp Con"e#$ullJp
** 5 p5 p,, 5 p5 p
++ KK
for 8 / to n 3 , ofor 8 / to n 3 , o
$$88 Con"e#$ullJ $ Con"e#$ullJ $83,83, E pE p88 KK can $e impro*e& to O+nlgncan $e impro*e& to O+nlgn
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 38/46
Algorithms: 3# )ncremental
C#%ull AnimationsC#%ull Animations2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html
"#n"#n22$$ timetime
Al h
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 39/46
Algorithms:
%# #i'ide4and4Conuer #i'ide4and4Conuer in a geometric setting#i'ide4and4Conuer in a geometric setting
&<n= merge step is the challenge&<n= merge step is the challenge @ind upper and lower tangents@ind upper and lower tangents
Lower tangent7 !ind rightmost pt o! A ;Lower tangent7 !ind rightmost pt o! A ;
le!tmost pt o! ?H then wal2 it downwardsBle!tmost pt o! ?H then wal2 it downwardsB )dea can -e e*tended to 3#.)dea can -e e*tended to 3#.
AlgoritmAlgoritm2 DIVID=3an3C:%E=R2 DIVID=3an3C:%E=R
Sort points by # coorinateSort points by # coorinate
Di"ie points into + sets A an B2Di"ie points into + sets A an B2
A contains left n<+ points A contains left n<+ points
B contains right n<+ pointsB contains right n<+ points
Compute Con"e#$ull-A. an Con"e#$ull-B. recursi"elyCompute Con"e#$ull-A. an Con"e#$ull-B. recursi"ely
Merge Con"e#$ull-A. an Con"e#$ull-B.Merge Con"e#$ull-A. an Con"e#$ull-B. "#nlgn$"#nlgn$
A ABB
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
Al h
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 40/46
Algorithms:
3# #i'ide and Conuer
C#%ull AnimationsC#%ull Animations2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html2 http2<<&&&4cse4uns&4eu4au<lambert<?a"a</<hull4html
"#n log n$"#n log n$ time Ltime L
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 41/46
Lower ?ound o! &<nlgn=
/orst4case time to !ind con'e* hull o! n points/orst4case time to !ind con'e* hull o! n pointsin alge-raic decision tree model is inin alge-raic decision tree model is in ΩΩ<nlgn=<nlgn=
roo! uses sorting reduction7roo! uses sorting reduction7
Gi'en unsorted list o! n num-ers7 <*Gi'en unsorted list o! n num-ers7 <*11$*$*%% $I$ *$I$ *nn== @orm unsorted set o! points7 <*@orm unsorted set o! points7 <*ii$ *$ *ii
%%= !or each *= !or each *ii
Con'e* hull o! points producesCon'e* hull o! points produces sorted list sorted list JJ ara-ola7 e'er( point is on con'e* hullara-ola7 e'er( point is on con'e* hull
eduction is &<n= <which is in o<nlgn==eduction is &<n= <which is in o<nlgn==
@inding con'e* hull o! n points is there!ore at least@inding con'e* hull o! n points is there!ore at leastas hard as sorting n points$ so worst4case time is inas hard as sorting n points$ so worst4case time is inΩΩ<nlgn=<nlgn=
'arabola for sorting +5,5/'arabola for sorting +5,5/
source: O’Rourke, Computational Geometry in C source: O’Rourke, Computational Geometry in C
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 42/46
,earest ,eigh-orClosest air o! oints
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 43/46
Closest air
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
GoalGoal2 Gi"en n -+D. points in a set 5 fin the closest pair2 Gi"en n -+D. points in a set 5 fin the closest pair
uner the =ucliean metric inuner the =ucliean metric in :-n lgn.:-n lgn. time4time4
Di'ide(and(Con-uer Strategy:
3. / points sorted *y increasing x3 0 / points sorted *y increasing y
3Di'ide: partition )it 'ertical line L into 3 4
3Con-uer: recursi'ely +ind closest pair in 3 4
3 δ3 δ4 are closest(pair distances
3 δ
min# δ
3δ
4 $3Com*ine: closest(pair is eiter δ or pair straddles partition line L
3 Cec5 +or pair straddling partition line L
3 *ot points must *e )itinδ
o+ L- create array 06 / 0 )it only points in 2δ strip3 +or eac point p in 06
3 +ind #7/ 8$ points in 06 )itinδ
o+ p
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 44/46
Closest air
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.
Correctness
//4,,
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 45/46
Closest air
4unning Time:
Fey 'ointFey 'oint2 'resort points5 then at each step form2 'resort points5 then at each step form
sorte subset of sorte array in linear timesorte subset of sorte array in linear time
=lg<3i! =1<3i! =<=%<%=< nn
nnnn) n) =
≤>+=
-ike opposite of ERGE step in ERGE/OR0-ike opposite of ERGE step in ERGE/OR0
source: 91.!" te#t$ook Cormen et al.source: 91.!" te#t$ook Cormen et al.RR
))
Additi l C t ti l G t
7/17/2019 503_lecture8
http://slidepdf.com/reader/full/503lecture8 46/46
Additional Computational Geometr
esources
Computational Geometry in C Computational Geometry in C second edition second edition -( Koseph &our2e -( Koseph &our2eCam-ridge Uni'ersit( ressCam-ridge Uni'ersit( ress199199
*eb Site: http:%%cs+smith+edu%,orourke%books%compgeom+html
See also -.+/01 Course *eb Site:
http:%%&&&+cs+uml+edu%,kdaniels%courses%A2G3/01+html