umass lowell computer science 91.503 analysis of algorithms prof. karen daniels fall, 2002

43
UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Tuesday, 11/5/02 Tuesday, 11/5/02 Computational Geometry Computational Geometry Chapter 33 Chapter 33

Upload: dora-sellers

Post on 31-Dec-2015

30 views

Category:

Documents


0 download

DESCRIPTION

UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002. Tuesday, 11/5/02 Computational Geometry Chapter 33. Relevant Sections of Chapter 33. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

UMass Lowell Computer Science 91.503

Analysis of Algorithms Prof. Karen Daniels

Fall, 2002

UMass Lowell Computer Science 91.503

Analysis of Algorithms Prof. Karen Daniels

Fall, 2002

Tuesday, 11/5/02Tuesday, 11/5/02

Computational GeometryComputational GeometryChapter 33Chapter 33

Page 2: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Relevant Sections of Chapter 33Relevant Sections of Chapter 33

Ch33 Computational Geometry

You’re responsible for material in this chapter that we discuss in lecture. (Note that this includes all sections.)

Page 3: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

OverviewOverview

Computational Geometry IntroductionComputational Geometry Introduction

Line Segment Intersection Line Segment Intersection

Convex Hull AlgorithmsConvex Hull Algorithms

Nearest Neighbors/Closest PointsNearest Neighbors/Closest Points

Page 4: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Computational GeometryComputational Geometry

TelecommunicationsTelecommunications

Visualization & Visualization & BioinformaticsBioinformatics

ManufacturingManufacturing

Computer Computer GraphicsGraphics

Design Analyze

Apply

Page 5: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Typical ProblemsTypical Problems

bin packingbin packing

Voronoi diagramVoronoi diagram simplifying polygonssimplifying polygons

shape similarityshape similarity

convex hullconvex hull

maintaining line maintaining line arrangementsarrangements

polygon partitioningpolygon partitioning nearest neighbor nearest neighbor

searchsearch

kd-treeskd-trees

SOURCESOURCE: 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 http://www.cs.sunysb.edu/~algorith))

Page 6: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Common Computational Geometry StructuresCommon Computational Geometry Structures

Voronoi DiagramVoronoi Diagram

Delaunay TriangulationDelaunay Triangulation

Convex HullConvex Hull

New PointNew Point

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 7: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Sample Tools of the TradeSample Tools of the Trade

Algorithm Design Patterns/Techniques:Algorithm Design Patterns/Techniques:binary searchbinary search divide-and-conquerdivide-and-conquer dualitydualityrandomizationrandomization sweep-linesweep-linederandomizationderandomization parallelismparallelism

Algorithm Analysis Techniques:Algorithm Analysis Techniques:asymptotic analysis, amortized analysisasymptotic analysis, amortized analysis

Data Structures:Data Structures:winged-edge, quad-edge, winged-edge, quad-edge, range tree, kd-treerange tree, kd-tree

Theoretical Computer ScienceTheoretical Computer Science principles:principles:NP-completeness, hardnessNP-completeness, hardness

Growth of FunctionsGrowth of Functions

SummationsSummations

RecurrencesRecurrences

SetsSets

ProbabilityProbability

MATHMATH ProofsProofs GeometryGeometry

Graph TheoryGraph TheoryCombinatoricsCombinatorics

Linear AlgebraLinear Algebra

Page 8: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Computational Geometryin Context

Computational Geometryin Context

TheoreticalTheoreticalComputerComputer

ScienceScience

Applied Computer ScienceApplied Computer Science

AppliedAppliedMathMath

GeometryGeometry

ComputationalComputationalGeometryGeometry

Efficient Efficient Geometric AlgorithmsGeometric Algorithms

Design Analyze

Apply

Page 9: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Line Segment Intersections(2D)

Line Segment Intersections(2D)

Intersection of 2 Line SegmentsIntersection of 2 Line SegmentsIntersection of > 2Line SegmentsIntersection of > 2Line Segments

Page 10: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Cross-Product-Based Geometric PrimitivesCross-Product-Based Geometric Primitives

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

pp00

pp22

pp11

(1)(1)

pp00

pp22

pp22

(2)(2)

pp22

pp11

pp33

pp44

(3)(3)

Some fundamental geometric questions:Some fundamental geometric questions:

Page 11: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Cross-Product-Based Geometric Primitives: (1)Cross-Product-Based Geometric Primitives: (1)

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.AdvantageAdvantage: less sensitive to accumulated round-off error: less sensitive to accumulated round-off error

122121

2121 det yxyx

yy

xxpp

pp00

pp22

pp11

(1)(1)

33.1

Page 12: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Cross-Product-Based Geometric Primitives: (2)Cross-Product-Based Geometric Primitives: (2)

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

pp00

pp22

pp11

(2)(2)

33.2

Page 13: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Intersection of 2 Line SegmentsIntersection of 2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

pp22

pp11

pp33

pp44

(3)(3)

Step 1Step 1: : Bounding Box Bounding Box TestTest

Step 2Step 2: Does each : Does each segment straddle segment straddle the line containing the line containing the other?the other?

33.3

p3 and p4 on opposite sides of p1p2p3 and p4 on opposite sides of p1p2

Page 14: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Segment-Segment IntersectionSegment-Segment Intersection

Finding the Finding the actual intersection pointactual intersection point Approach: parametric vs. slope/interceptApproach: parametric vs. slope/intercept

parametric generalizes to more complex parametric generalizes to more complex intersectionsintersections

Parameterize each segmentParameterize each segment

aa

bbcc

dd

LLababLLcdcd

aa

bbcc

dd

LLababLLcdcd

A=b-aA=b-a

p(s)=a+sAp(s)=a+sA

Intersection: values of Intersection: values of ss, , tt such that such that p(s)p(s) = =q(t)q(t) : : a+sAa+sA==c+tCc+tC

q(t)=c+tCq(t)=c+tCC=d-cC=d-c

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 15: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

DemoDemo

Segment/Segment IntersectionSegment/Segment Intersectionhttp:/cs.smith.edu/~orourke/books/CompGeom/CompGeom.htmlhttp:/cs.smith.edu/~orourke/books/CompGeom/CompGeom.html

Page 16: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Intersection of >2 Line SegmentsIntersection of >2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Sweep-Line Algorithmic Paradigm:Sweep-Line Algorithmic Paradigm:

33.4

Page 17: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Intersection of >2 Line SegmentsIntersection of >2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Sweep-Line Algorithmic Paradigm:Sweep-Line Algorithmic Paradigm:

Page 18: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Intersection of >2 Line SegmentsIntersection of >2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

O(n lg n)O(n lg n)

Time to Time to detectdetect if any 2 if any 2 segments intersect:segments intersect:

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.5

Note that it exits as soon as Note that it exits as soon as oneone intersection is detected. intersection is detected.

Page 19: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Intersection of SegmentsIntersection of Segments

GoalGoal: “Output-size sensitive” line segment intersection : “Output-size sensitive” line segment intersection algorithm algorithm that actually computes that actually computes allall intersection points intersection points

Bentley-Ottmann plane sweep: Bentley-Ottmann plane sweep: O((n+k)logn) O((n+k)logn) timetime k = number of intersection points in outputk = number of intersection points in output Intuition: sweep horizontal line downwardsIntuition: sweep horizontal line downwards

just before intersection, 2 segments are adjacent in sweep-line intersection just before intersection, 2 segments are adjacent in sweep-line intersection structurestructure

check for intersection check for intersection onlyonly segments that adjacent segments that adjacent event types:event types:

top endpoint of a segmenttop endpoint of a segment bottom endpoint of a segmentbottom endpoint of a segment intersection between 2 segmentsintersection between 2 segments

Improved to O(nlogn+k) [Chazelle/Edelsbrunner]Improved to O(nlogn+k) [Chazelle/Edelsbrunner]source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 20: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Convex Hull AlgorithmsConvex Hull Algorithms

DefinitionsDefinitionsGift WrappingGift WrappingGraham ScanGraham Scan

QuickHullQuickHullIncrementalIncremental

Divide-and-ConquerDivide-and-ConquerLower Bound in Lower Bound in (nlgn)(nlgn)

Page 21: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Convexity & Convex HullsConvexity & Convex Hulls

A convex combination of points A convex combination of points xx11, ..., x, ..., xkk is a sum of the form is a sum of the form

11xx11+...+ +...+ kkxxkk where where

Convex hull of a set of points is the Convex hull of a set of points is the set of all convex combinations of set of all convex combinations of points in the set.points in the set.

nonconvex polygonnonconvex polygon

convex hull of a point setconvex hull of a point set

10 1 ki andi

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 22: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Naive Algorithms for Extreme PointsNaive Algorithms for Extreme Points

AlgorithmAlgorithm: INTERIOR POINTS: INTERIOR POINTSfor each i dofor each i do for each j = i dofor each j = i do for each k = j = i dofor each k = j = i do

for each L = k = j = i do for each L = k = j = i do if pif pL L in triangle(pin triangle(pii, p, pjj, p, pkk))

then pthen pLL is nonextreme is nonextreme O(nO(n44))

AlgorithmAlgorithm: EXTREME EDGES: EXTREME EDGESfor each i dofor each i do for each j = i dofor each j = i do for each k = j = i dofor each k = j = i do

if pif pk k is not left or on (pis not left or on (pii, p, pjj))

then (pthen (pi i , p, pjj) is not extreme) is not extreme O(nO(n33))source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 23: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 2D Gift WrappingAlgorithms: 2D Gift Wrapping

Use one extreme edge as an Use one extreme edge as an anchor for finding the nextanchor for finding the next

O(nO(n22))

AlgorithmAlgorithm: GIFT WRAPPING: GIFT WRAPPING

ii00 index of the lowest point index of the lowest point

i ii i00repeatrepeat for each j = ifor each j = i Compute counterclockwise angle Compute counterclockwise angle from previous hull edge from previous hull edge k index of point with smallest k index of point with smallest Output (pOutput (pi i , p, pkk) as a hull edge) as a hull edge i ki kuntil i = iuntil i = i00

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 24: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Gift WrappingGift Wrapping

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.9

Page 25: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 3D Gift Wrapping Algorithms: 3D Gift Wrapping

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

O(nO(n22)) time time

[output sensitive: O(nF) for F faces on hull][output sensitive: O(nF) for F faces on hull]

Page 26: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 2D QuickHullAlgorithms: 2D QuickHull

Concentrate on points close to Concentrate on points close to hull boundaryhull boundary

Named for similarity to Named for similarity to Quicksort Quicksort

aa

bb

O(nO(n22))

AlgorithmAlgorithm: QUICK HULL: QUICK HULL

function QuickHull(a,b,S)function QuickHull(a,b,S)

if S = 0 return()if S = 0 return() elseelse c index of point with max distance from abc index of point with max distance from ab A points strictly right of (a,c)A points strictly right of (a,c) B points strictly right of (c,b)B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B)return QuickHull(a,c,A) + (c) + QuickHull(c,b,B)

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

finds one of upper or lower hullfinds one of upper or lower hull

Page 27: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 3D QuickHullAlgorithms: 3D QuickHull

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

Page 28: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: Qhull (>= 2D )Algorithms: Qhull (>= 2D )

http://www.geom.umn.edu/software/qhull/http://www.geom.umn.edu/software/qhull/

Page 29: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Graham’s AlgorithmGraham’s Algorithm

Points sorted angularly provide Points sorted angularly provide “star-shaped” starting point“star-shaped” starting point

Prevent “dents” as you go via Prevent “dents” as you go via convexity testingconvexity testing

O(nlgn)O(nlgn)

AlgorithmAlgorithm: GRAHAM SCAN, Version B: GRAHAM SCAN, Version B

Find rightmost lowest point; label it pFind rightmost lowest point; label it p00..

Sort all other points angularly about pSort all other points angularly about p00.. In case of tie, delete point(s) closer to pIn case of tie, delete point(s) closer to p00..Stack S (pStack S (p11, p, p00) = (p) = (ptt, p, pt-1t-1); t indexes top); t indexes topi 2i 2while i < n dowhile i < n do

if pif pii is strictly left of p is strictly left of pt-1t-1pptt

then Push(pthen Push(pii, S) and set i i +1, S) and set i i +1else Pop(S)else Pop(S)

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

““multipop”multipop”

Page 30: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 31: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.7

Page 32: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.7

Page 33: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 34: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 35: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 2D IncrementalAlgorithms: 2D Incremental

Add points, one at a timeAdd points, one at a time update hull for each new pointupdate hull for each new point

Key step becomes adding a Key step becomes adding a single point to an existing hull.single point to an existing hull.

Idea can be extended to 3D.Idea can be extended to 3D.

O(nO(n22))

AlgorithmAlgorithm: INCREMENTAL ALGORITHM: INCREMENTAL ALGORITHM

Let HLet H22 ConvexHull{p ConvexHull{p0 0 , p, p1 1 , p, p2 2 }}

for k 3 to n - 1 dofor k 3 to n - 1 do HHkk ConvexHull{ H ConvexHull{ Hk-1 k-1 U pU pk k }}

can be improved to O(nlgn)can be improved to O(nlgn)

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 36: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 3D Incremental Algorithms: 3D Incremental

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

O(nO(n22)) time time

Page 37: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 2D Divide-and-ConquerAlgorithms: 2D Divide-and-Conquer

Divide-and-Conquer in a geometric settingDivide-and-Conquer in a geometric setting O(n) merge step is the challengeO(n) merge step is the challenge

Find upper and lower tangentsFind upper and lower tangents Lower tangent: find rightmost pt of A & Lower tangent: find rightmost pt of A &

leftmost pt of B; then “walk it downwards”leftmost pt of B; then “walk it downwards” Idea can be extended to 3D.Idea can be extended to 3D.

AlgorithmAlgorithm: DIVIDE-and-CONQUER: DIVIDE-and-CONQUER

Sort points by x coordinateSort points by x coordinate

Divide points into 2 sets A and B:Divide points into 2 sets A and B:

A contains left n/2 pointsA contains left n/2 points

B contains right n/2 pointsB contains right n/2 points

Compute ConvexHull(A) and ConvexHull(B) recursivelyCompute ConvexHull(A) and ConvexHull(B) recursively

Merge ConvexHull(A) and ConvexHull(B) Merge ConvexHull(A) and ConvexHull(B) O(nlgn)O(nlgn)

AABB

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 38: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Algorithms: 3D Divide and Conquer Algorithms: 3D Divide and Conquer

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

O(n log n)O(n log n) time ! time !

Page 39: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Lower Bound of O(nlgn)Lower Bound of O(nlgn)

Worst-case time to find convex hull of n points Worst-case time to find convex hull of n points in algebraic decision tree model is in in algebraic decision tree model is in (nlgn)(nlgn)

Proof uses sorting reduction:Proof uses sorting reduction: Given unsorted list of n numbers: (xGiven unsorted list of n numbers: (x11,x,x2 2 ,…, x,…, xnn)) Form unsorted set of points: (xForm unsorted set of points: (xii, x, xii

22) for each x) for each xii

Convex hull of points produces Convex hull of points produces sorted listsorted list!! Parabola: every point is on convex hullParabola: every point is on convex hull

Reduction is O(n) (which is o(nlgn))Reduction is O(n) (which is o(nlgn)) Finding convex hull of n points is therefore at least Finding convex hull of n points is therefore at least

as hard as sorting n points, so worst-case time is in as hard as sorting n points, so worst-case time is in (nlgn)(nlgn)

Parabola for sorting 2,1,3Parabola for sorting 2,1,3

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 40: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Nearest Neighbor/Closest Pair of Points

Nearest Neighbor/Closest Pair of Points

Page 41: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Closest PairClosest Pair

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

GoalGoal: Given n (2D) points in a set Q, find the closest pair : Given n (2D) points in a set Q, find the closest pair under the Euclidean metric in under the Euclidean metric in O(n lgn)O(n lgn) time. time.

Divide-and-Conquer Strategy:-X = points sorted by increasing x-Y = points sorted by increasing y-Divide: partition with vertical line L into PL, PR

-Conquer: recursively find closest pair in PL, PR

- L, R are closest-pair distances- min( L, R )-Combine: closest-pair is either or pair straddles partition line L- Check for pair straddling partition line L- both points must be within of L- create array Y’ = Y with only points in 2 strip- for each point p in Y’- find (<= 7) points in Y’ within of p

Page 42: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Closest PairClosest Pair

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Correctness

33.11

Page 43: UMass Lowell Computer Science 91.503 Analysis of Algorithms Prof. Karen Daniels Fall, 2002

Closest PairClosest Pair

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Running Time:

Key PointKey Point: Presort points, then at each step form : Presort points, then at each step form sorted subset of sorted array in linear timesorted subset of sorted array in linear time

)lg(3 if)1(

3 if)()2/(2)( nnO

nO

nnOnTnT

Like opposite of MERGE step in MERGESORT…Like opposite of MERGE step in MERGESORT…