Algorithms on grids
description
Transcript of Algorithms on grids
![Page 1: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/1.jpg)
10/2/2006 1
Algorithms on grids
Natasha GelfandGeometry Seminar
Fall 2006
![Page 2: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/2.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 2
Grids in computer science
![Page 3: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/3.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 3
Grids in computer science• Graphics and vision
• Collision detection, point location
• Simulation
![Page 4: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/4.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 4
Grids for geometric proximity• Isolate and localize interesting
events– Proximity is local
• “Uniform” grids– Closest pair, k-Minimum enclosing disk
• Adaptive grids– quadtrees
![Page 5: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/5.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 5
Closest pair
• Given: n points in the plane
• Return pair of pointsrealizing
![Page 6: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/6.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 6
• Computing the grid takes linear time
Grids for points
![Page 7: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/7.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 7
Sub-problem• Given a set P and a distance r, verify in
linear time if CP(P)<r or CP(P) > r
– Insert points sequentially
– If CP(P) < r, p, q are in the same orneighboring cells
– Can we search a cellin constant time?
r
![Page 8: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/8.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 8
Algorithm• If some cell contains more than 9 points,
then CP(P)<r
• Algorithm:– Insert points into the grid– If cell(p) contains more than
9 points, return CP(P) < r
![Page 9: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/9.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 9
Algorithm• If some cell contains more than 9 points,
then CP(P)<r
• Algorithm:– Insert points into the grid– If cell(p) contains more than
9 points, return CP(P) < r
– Otherwise, compute
• Constant time per point,running time O(n)
r
![Page 10: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/10.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 10
Closest pair• Permute points P=<p1, p1, … , pn>
• Let ri = CP({p1, …, pi})– Can check if ri<ri-1 in linear time
• Good case: ri = ri-1
– Grid is already built, check in O(1) time
• Bad case: ri < ri-1
– Rebuild grid, O(i) time
• Trivial bound: O(nk), when closest pair changes k times
![Page 11: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/11.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 11
Analysis• Let Xi = 1 if ri · ri-1, and 0 otherwise
• Running time:
![Page 12: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/12.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 12
Analysis• Bound Pr[Xi = 1] = Pr[ri < ri-1]
– Likelihood that pi realizes CP(Pi)
• Expected running time
![Page 13: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/13.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 13
k-Enclosing minimum disk• Disk of minimum radius that contains k
points
• Brute force O(nk)
• 2-Opt algorithm: r(P,k) · 2ropt(P,k)
k=3
k=4
![Page 14: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/14.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 14
Non-uniform grid• Partition P into horizontal strips with at most k/4
points in each strip– Recursive median partitioning – O(n/k) strips
G
Running time:
T(n) = n + 2T(n/2)Stop at n < k/4
O(nlog(n/k))
![Page 15: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/15.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 15
Finite centers• Claim: Dopt(P,k) contains at least one intersection
point of G• Pf: By contradiction:
At most k/2 points
Dopt(P,k)
k/4 points
k/4 pointsk points
![Page 16: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/16.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 16
Algorithm• For each grid intersection point g2G
– Compute smallest circle centered at p with k points– k-th order statistic of {||p, g||}
– Expected time O(n)
– Return the best of (n/k)2 candidates
• Running time: O(n(n/k)2)
![Page 17: Algorithms on grids](https://reader036.fdocuments.in/reader036/viewer/2022062723/56813bb1550346895da4e75a/html5/thumbnails/17.jpg)
10/2/2006 Geometry Seminar: Algorithms on Grids 17
Correctness
• 2-Opt: r(P,k) · 2ropt(P,k)