Algorithms for Dynamic Convex Hulls

Introduction
Merging Hulls
Intuition
Algorithms for Dynamic Convex Hulls
Algorithm
Applications
Bogdan Armaselu
K. Alex Mills
Frontiers in Algorithms - Spring 2016
The University of Texas at Dallas
April 5th, 2016
Introduction
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Dynamic Convex Hull Problem
Points are given one at at time
Goal is to update convex hull efficiently after adding /
removing query point
We present data structures to deal with insertions and
deletions
Related Work
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Preparata’s algorithm [Preparata, 1980]
Uses a dynamic CH data structure to handle insertions in
O(log n) time, based on binary searching the list of hull
points, stored in a concatenable queue
Ignores points inside the hull (for insertions)
Doesn’t handle deletions of points
Deletion may take O(n) time (see figure)
Related Work
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Chan’s algorithm [Chan, 2001]
O((log n)1+ ) amortized query / update time
Relatively complicated
Overview
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Overmars and Leeuwen [Overmars, 1981] design an algorithm
that handles insertions and deletions in O(log2 n) time per
query point. That is O(nlog 2 n) time to construct the whole
CH.
Preliminaries
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Let P be a set of points in the plane, CH(P) the convex hull of
P.
lc-hull
The lc-hull of P is the convex hull of P ∪ (+∞, 0).
rc-hull
The rc-hull of P is the convex hull of P ∪ (−∞, 0).
Figure: lc-hull
rc-hull
Divide-and-conquer for Convex Hulls
Introduction
Recall that there is a simple divide-and-conquer approach to
Convex Hull of point set P.
Merging Hulls
Intuition
Algorithm
Applications
Algorithm 1 Divide-and-conquer for Convex Hull
1: function DCHull(P)
. P := set of points.
2:
if |P| ≤ 2 then
3:
Use brute force...
4:
end if
5:
Evenly partition P into T top and B bottom halves.
6:
HL ← DCHull(L)
7:
HR ← DCHull(R)
8:
return Merge(HL , HR )
9: end function
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Divide and Conquer for Convex Hulls
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
l •
i •
h•
e•
m•
Maintaining the Hulls
Introduction
Merging Hulls
Intuition
Algorithm
Applications
The lc and rc hulls are maintained in concatenable queues
QL , QR which are implemented as 2-3-trees [Cisneros].
The points in the lc (rc) hull are sorted in increasing
(decreasing) order of Y-coordinate (i.e. in clockwise
order).
The concatenable queues support the following operations
in O(log n) time:
Search for an item
Concatenating two queues
Splitting two queues
Insertion of an item
Deletion of an item
Maintaining the hulls
Introduction
Merging Hulls
Intuition
Algorithm
Applications
From now on, we focus on the lc-hull representation, as the
rc-hull is symmetric.
Lemma (1)
Given the lc-hull C of P, one can determine the relative
position of a point p with respect to C (inside, on the hull or
outside) in O(log n) time.
Proof of Lemma (1)
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Let p = (xp , yp ).
Given p, one can find two consecutive points pi , pj such that
ypi ≤ yp ≤ ypj through a search on QL in O(log n) time.
If no such two points exist, then p is outside C .
Otherwise, p is inside if and only if (pi , pj , p) is a right turn.
Figure: p is inside the hull iff (pi , pj , p) is a right turn
Merging lc-hulls
Theorem (2)
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Given the lc-hulls L of the lower part {p1 , . . . , pi } of P and U
of the upper part {pi+1 , . . . , pn } of P, ∀1 ≤ i ≤ n, the lc-hull C
of P can be built in O(log n) time.
Proof of Theorem (2)
Introduction
Merging Hulls
Intuition
Algorithm
Applications
To build an lc-hull of P given lc-hulls U and L, we need to
find a bridge uv , u ∈ U, v ∈ L, that bounds both lc-hulls
from the left.
We find u, v by searching the concatenable queues storing
the points of U and L respectively in a binary search
fashion.
Given points p ∈ U, q ∈ L, we either find the bridge uv , or
discard the portions of U and/or L that cannot contain
u, v and then recurse on the remaining portions of U, L,
setting p, q to be the median points of U, L.
In the following, for any points p, q, we say that p is to
the left of q iff xp < xq .
9 cases may occur.
Proof of Theorem (2)
By neighbors of a point p we mean the predecessor and the
successor of p in its chain.
Introduction
Case 1
Merging Hulls
Intuition
Algorithm
Applications
p, q are both to the left of both their neighbors. In this case
u = p, v = q and we are done.
Proof of Theorem (2)
Case 2
Introduction
Merging Hulls
Intuition
Algorithm
Applications
p is to the left of both its neighbors, q is to the right of its
predecessor in L. In this case the part of L after q and the part
of U before p are discarded.
Proof of Theorem (2)
Case 3
Introduction
Merging Hulls
Intuition
Algorithm
Applications
p is to the left of both its neighbors, q is to the left of its
predecessor in L. In this case the part of L before q and the
part of U before p are discarded.
Proof of Theorem (2)
Case 4
Introduction
Merging Hulls
p is to the right of its predecessor in U, q is to the left of both
its neighbors. Same action as in Case 2.
Intuition
Algorithm
Applications
Figure: Case 4
Proof of Theorem (2)
Case 5
Introduction
Merging Hulls
Intuition
Algorithm
Applications
p is to the left of its predecessor in U, q is to the left of both
its neighbors. In this case the part of L after q and the part of
U after p are discarded.
Proof of Theorem (2)
Case 6
Introduction
Merging Hulls
p is to the right of its predecessor in U, q is to the left of its
predecessor in L. Same action as in Case 2.
Intuition
Algorithm
Applications
Figure: Case 6
Proof of Theorem (2)
Case 7
Introduction
Merging Hulls
p is to the left of its predecessor in U, q is to the left of its
predecessor in L. In this case the part of L after q is discarded.
Intuition
Algorithm
Applications
Figure: Case 7
Proof of Theorem (2)
Case 8
Introduction
Merging Hulls
p is to the right of its predecessor in U, q is to the right of its
predecessor in L. In this case the part of U after p is discarded.
Intuition
Algorithm
Applications
Figure: Case 8
Proof of Theorem (2)
Case 9
Introduction
Merging Hulls
Intuition
Algorithm
Applications
p is to the left of its predecessor in U, q is to the right of its
predecessor in L. Let m be the horizontal line dividing U, L, lp
the tangent through p, lq the tangent through q and s = lp ∩ lq .
Proof of Theorem (2)
Case 9.1
Introduction
Merging Hulls
Intuition
Algorithm
Applications
s is below or on m. In this case, u is between lines m, lp , pq, so
v must be to the left of q. Hence, the portion before q can be
discarded from L.
Proof of Theorem (2)
Case 9.2
Introduction
Merging Hulls
Intuition
Algorithm
Applications
s is above m. In this case, v is between lines m, lq , pq, so u
must be to the left of p. Hence, the portion after p can be
discarded from U.
Proof of Theorem (2)
Introduction
Merging Hulls
Intuition
Algorithm
Each case is treated in O(1) time.
Applications
Since these cases may occur O(log n) times (due to the
binary search of u, v ), it follows that uv can be found in
O(log n) time.
A Good Idea...
Idea
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Build a data structure that stores the subproblems encountered
during divide-and-conquer in a binary tree. To insert and delete
points, modify the inputs, then recompute only the
subproblems which changed.
To delete point p: Move down the tree until the smallest
subproblem containing p is encountered, remove it, then
recompute subproblems back up the tree to the root.
To insert point p: Move down the tree until we
encounter the subproblem which should contain p, add a
new subproblem containing p, then recompute
subproblems back up the tree to the root.
A Good Idea... With A Catch
Introduction
Merging Hulls
Problem: Implementing this directly is horribly inefficient.
Intuition
Algorithm
We get O(n) inserts and deletes (we shall see why).
Applications
Goal: Cleverly structure the data in our tree so as to
make inserts and deletes fast: O(log2 (n)).
We will first see a naı̈ve approach, to explain why the
improvement is needed, and to build intuition.
The Naı̈ve Data Structure
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
The Naı̈ve Data Structure
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
The Naı̈ve Data Structure
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
The Naı̈ve Data Structure
o•
Introduction
c•
Merging Hulls
Intuition
b•
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
Naı̈vely Inserting a Point
o•
Introduction
c•
Merging Hulls
bx••
Intuition
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
Naı̈vely Inserting a Point
o•
Introduction
c•
Merging Hulls
bx••
Intuition
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
Naı̈vely Inserting a Point
o•
Introduction
c•
Merging Hulls
bx••
Intuition
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
Naı̈vely Inserting a Point
o•
Introduction
c•
Merging Hulls
bx••
Intuition
Algorithm
Applications
a•
n•
k•
f •
g• j
•
d•
[e, d, g , i]
[a, b, c, o]
l •
i •
h•
e•
[e, d, a, b, c, o]
[e, h]
m•
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
Naı̈vely Inserting a Point
[e, d, a, b, c, o]
Introduction
o•
c•
Merging Hulls
Intuition
bx••
Algorithm
Applications
a•
n•
[e, d, g , i]
[a, b, c, o]
k•
f •
g• j
•
d•
l •
i •
h•
e•
[e, h]
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, n] [c, o]
m•
[b]
[x, n]
Naı̈vely Inserting a Point
[e, d, a, b, c, o]
Introduction
o•
c•
Merging Hulls
Intuition
bx••
Algorithm
Applications
a•
n•
[e, d, g , i]
[a, b, c, o]
k•
f •
g• j
•
d•
l •
i •
h•
e•
[e, h]
[d, g , i]
[a, f , k]
[b, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, x, n] [c, o]
m•
[b]
[x, n]
Naı̈vely Inserting a Point
[e, d, a, b, c, o]
Introduction
o•
c•
Merging Hulls
Intuition
bx••
Algorithm
Applications
a•
n•
[e, d, g , i]
[a, b, c, o]
k•
f •
g• j
•
d•
l •
i •
h•
e•
[e, h]
[d, g , i]
[a, f , k]
[b, x, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, x, n] [c, o]
m•
[b]
[x, n]
Naı̈vely Inserting a Point
[e, d, a, b, c, o]
Introduction
o•
c•
Merging Hulls
Intuition
bx••
Algorithm
Applications
a•
n•
[e, d, g , i]
[a, b, x, c, o]
k•
f •
g• j
•
d•
l •
i •
h•
e•
[e, h]
[d, g , i]
[a, f , k]
[b, x, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, x, n] [c, o]
m•
[b]
[x, n]
Naı̈vely Inserting a Point
[e, d, a, b, x, c, o]
o•
Introduction
c•
Merging Hulls
bx••
Intuition
Algorithm
Applications
a•
n•
[e, d, g , i]
[a, b, x, c, o]
k•
f •
g• j
•
d•
l •
i •
h•
e•
[e, h]
[d, g , i]
[a, f , k]
[b, x, c, o]
[e] [h, m] [d, j] [g , i] [a, l] [f , k] [b, x, n] [c, o]
m•
[b]
Deletes can be done in much the same way.
[x, n]
Running-time Analysis: Naı̈ve Approach
Introduction
Merging Hulls
Merging: Path has size O(log(n))... finding each bridge
takes O(log(n)) time... O(log2 (n)) so far.
Intuition
Algorithm
Applications
Inserting: O(log(n)) time to insert into a concatenable
queue... so (log2 (n)) to insert at every node in the tree.
Problem:during deletes we have to copy the entire queue
(O(n) time).
To get O(log2 (n)) time we must avoid copying these
queues.
Key Idea Behind O(log2 (n)) Inserts/Deletes
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Clever Idea
Instead of storing the entire subproblem at each node of the
tree, store just enough of it to reconstruct the subproblem we
need as we go down the tree.
If we can reconstruct each subproblem in O(log(n)) time,
as we go down we have a viable solution.
Saving Space (and Therefore Time)
Introduction
[e, d, a, b, c, o]
Merging Hulls
Intuition
Algorithm
[a, b, c, o]
[e, d,g , i]
Applications
[e,h]
[e]
[h, m]
[d,g , i]
[d,j]
[g , i]
[a,f , k]
[a,l]
[f , k]
[b, c, o]
[b,n]
[c, o]
Saving Space (and Therefore Time)
Introduction
[e, d, a, b, c, o]
Merging Hulls
Intuition
Algorithm
[a, b, c, o]
[e, d,g , i]
Applications
[e,h]
[e]
[h, m]
[d,g , i]
[d,j]
[g , i]
[a,f , k]
[a,l]
[f , k]
[b, c, o]
[b,n]
[c, o]
Saving Space (and Therefore Time)
Introduction
[e, d, a, b, c, o]
Merging Hulls
Intuition
Algorithm
[a, b, c, o]
[e, d,g , i]
Applications
[e,h]
[e]
[h, m]
[d,g , i]
[d,j]
[g , i]
[a,f , k]
[a,l]
[f , k]
[b, c, o]
[b,n]
[c, o]
Saving Space (and Therefore Time)
Introduction
[e, d, a, b, c, o]
Merging Hulls
Intuition
Algorithm
[a, b, c, o]
[e, d,g , i]
Applications
[e,h]
[e]
[h, m]
[d,g , i]
[d,j]
[g , i]
[a,f , k]
[a,l]
[f , k]
[b, c, o]
[b,n]
[c, o]
Saving Space (and Therefore Time)
[e, d, a, b, c, o]
Introduction
Merging Hulls
Intuition
[
Algorithm
[
]
[ f , k]
[
g , i]
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
]
[ l]
[
]
[ n]
]
[
]
Saving Space (and Therefore Time)
[e, d, a, b, c, o]
Introduction
Merging Hulls
Intuition
[
Algorithm
[
g , i] : 2
] : 4
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[
[ f , k]
]
[ l]
[
]
[ n]
]
[
]
Caveat: We must store enough information to reconstruct
child problems.
Performing the Reconstruction
[e, d,a, b, c, o]
Introduction
Merging Hulls
Intuition
[
Algorithm
[
g , i] :2
] :4
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[ f , k] :1
]
[ l]
[
]
[
[ n] :1 [
↑
x
] :3
] :2
Performing the Reconstruction
]
[
Introduction
Merging Hulls
Intuition
[a,b, c, o] :4
[e, d,g , i] :2
Algorithm
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[ f , k] :1
]
[ l]
[
]
[
[ n] :1 [
↑
x
] :3
] :2
Performing the Reconstruction
]
[
Introduction
Merging Hulls
Intuition
[a,b, c, o] :4
[e, d,g , i] :2
Algorithm
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[ f , k] :1
]
[ l]
[
]
[
[ n] :1 [
↑
x
] :3
] :2
Performing the Reconstruction
]
[
Introduction
Merging Hulls
Intuition
[
[e, d,g , i] :2
Algorithm
] :4
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[a,f , k] :1
]
[ l]
[
]
[b,c, o] :3
[ n] :1 [
↑
x
] :2
Performing the Reconstruction
]
[
Introduction
Merging Hulls
Intuition
[
[e, d,g , i] :2
Algorithm
] :4
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[a,f , k] :1
]
[ l]
[
]
[b,c, o] :3
[ n] :1 [
↑
x
] :2
Performing the Reconstruction
]
[
Introduction
Merging Hulls
Intuition
[
[e, d,g , i] :2
Algorithm
] :4
Applications
[ h]
[ ]
[ m]
[
[ j]
]
[
[a,f , k] :1
]
[ l]
[
]
[
] :3
[b,n] :1 [c, o] :2
↑
x
Data Structure
Introduction
Merging Hulls
Intuition
Algorithm
Applications
At each node store:
parent: pointer to parent node.
right: pointer to right child.
left: pointer to left child.
maxleft : largest y -value of left subtree (used for search).
queue: segment of my queue which is not stored at my
parent.
B: number of nodes in parent.queue which belong to my
subproblem.
Algorithm Overview
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Two subroutines for crawling the tree.
Down: Moves down the tree until a leaf is hit, splitting
queues to ensure the correct subproblems are available at
the child nodes.
Up: Moves back up the tree, concatenating queues to
ensure that Down will find everything the way it expects.
Also rebalances the tree! (More on this later.)
Down Subroutine
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Algorithm 2 Traverse tree to insert/delete point p
1: function Down(node, p)
2:
if location for p has not yet been reached then
3:
Q1 ← node.queue[1, ..., left.B]
4:
Q2 ← node.queue[left.B + 1, ..., 1]
5:
left.queue ← Concat(Q1 , left.queue)
6:
right.queue ← Concat(right.queue, Q2 ).
7:
if py < maxleft then
8:
Down(node.left, p)
9:
else
10:
Down(node.right, p)
11:
end if
12:
end if
13: end function
Running time for Down
Claim
Introduction
Down reaches its goal after O(log2 (n)) steps
Merging Hulls
Intuition
Proof.
Algorithm
Applications
Tree is kept balanced, so Down can only be called at
most O(log n) times before reaching its goal.
At each node:
Test to see if x has been reached: O(1) time comparison
of py and node.max
Perform some split/concatenate operations on
concatenable queues. O(log n) time per operation.
So we get O(log2 (n)) time overall.
Up subroutine
Introduction
When we call Down, we also reconstruct the full queue
for siblings along the search path.
Merging Hulls
]
[
Intuition
Algorithm
Applications
[ h]
[ ]
[ m]
[
[ j]
] :4
[
[e, d,g , i] :2
[a,f , k] :1
]
[
]
[ l]
[
]
[
] :3
[b,n] :1 [c, o] :2
↑
x
Up subroutine
Introduction
Merging Hulls
When we call Down, we also reconstruct the full queue
for siblings along the search path.
We need the sibling queues available so we can run our
merge operation to add/delete points.
Intuition
Algorithm
Applications
Up leaves the queue back the way we found it before we
ran Down, except the required insert/delete operation
has been performed.
It essentially runs the conquer step of divide-and-conquer
again, with the modified point-set.
We previously showed that the conquer step can be
implemented in O(log n) time.
Up Subroutine
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Algorithm 3 Add/remove points and rebalance
1: function Up(node, p)
2:
Determine bridge connecting left.queue and right.queue,
and therefore the numbers of points B1 and B2 they contribute to node.queue. (O(log n) time)
3:
left.B ← B1 ; right.B ← B2
4:
Q1 ← right.queue[1, ..., B1 ]
5:
Q2 ← left.queue[n − B2 , ..., n]
. n = |left.queue|
6:
node.queue ← Concat(Q1 , Q2 )
7:
Rebalance(node)
. rebalance if needed
8:
if node 6= root then
9:
Up(node.parent)
10:
end if
11: end function
Running Time for Up
Claim
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Up reaches the root after O(log2 (n) + R) steps, where R is the
time taken to rebalance the tree.
Proof.
Length of path bounded by O(log (n)) in a balanced tree
At each node:
O(log(n)) steps used to find the bridge, via the binary
search technique described earlier.
O(log(n)) steps to split and merge queues.
O(log2 (n)) overall, plus the time taken to rebalance...
Does Rebalancing Take Too Long?
Introduction
Recall AVL trees...
Merging Hulls
3
Intuition
balance factor = 2
Algorithm
2
Applications
2
D
=⇒
1
C
A
A
3
1
B
C
D
B
O(1) pointer operations per node that needs rebalancing.
Does Rebalancing Take Too Long?
[e, d, a, b]
Introduction
Merging Hulls
Intuition
[
[
[
g]
=⇒
Algorithm
Applications
[ h]
[d
g]
]
[ h]
[e, d, a, b]
]
[ ] [ m] [d
] [
]
[ ] [ m]
Clearly, rebalancing naı̈vely has some issues.
We can fix them by using the Up and Down routines!!!
Does Rebalancing Take Too Long?
Introduction
[e, d, a, b]
Merging Hulls
Intuition
Algorithm
Applications
Down
[e, d, a, b]
[e, d, g ]
Down
[e, h]
[a, b]
Up
=⇒
[d, g ]
[e, h]
[d, a, b]
Up
[ ] [ m] [d, g ] [a, b]
[ ] [ m]
Rebalancing takes O(log2 (n)) Time
Introduction
Merging Hulls
Intuition
Algorithm
Applications
We can perform rebalancing by using an AVL tree and
performing O(1) additional calls to Down and Up.
We only illustrated a single-rotation, but the double
rotation is essentially the same analysis.
Therefore we only have an extra O(1) calls to a O(log(n))
method in order to rebalance the tree.
AVL rebalancing only performs O(1) pointer swaps.
So R = O(log2 (n)) as well.
Note: AVL trees are not special. Any balanced search tree
which admits O(log(n)) inserts and deletes can be
modified to work.
Summary
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Dynamic data structure for maintaining a planar convex
hull, with
O(log2 n) insert and delete.
O(log n) access time for points on the hull.
O(log n) time for queries of the form:
“Does this point lie inside the convex hull?”
“Does this line intersect the convex hull?”
Peeling Off A Point Set
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Input: set S of n points
Goal: peel off a fraction p/q of S i.e. remove pn/q
outlying points from S
Peeling Off a Point Set
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Theorem (3)
S can be peeled in O(pn/q log2 (n)) time.
Proof
Construct the dynamic CH data structure for S in
O(n log n) time
Perform pn/q deletions, each of them in O(log2 (n)) time
using the dynamic CH algorithm
Determining Convex Layers Set
Introduction
Merging Hulls
Input: set S of n points
Goal: set T of layers T0 , T1 , . . . ,, where
T0 = CH(S), T1 = CH(S − CH(S)), . . . .
Intuition
Algorithm
Applications
Figure: Convex layers of a point set
Theorem (4)
The convex layers of a set S of n points can be determined in
O(n log2 n) time.
Convex Hull Queries
Introduction
Given a set S of n points given one at a time
Goal is to maintain CH(S) to answer queries of the form
”is q inside CH(S)?” and update the structure efficiently
Merging Hulls
Intuition
Algorithm
Applications
Figure: p is inside the hull iff (pi , pj , p) is a left turn
Theorem (5)
One can maintain a set S of n points in the plane such that
any query q can be answered in O(log n) time at the cost of
O(log2 n) update time per insertion or deletion.
Line Separability Of Two Point Sets
Introduction
Merging Hulls
Intuition
Algorithm
Given two dynamic sets A, B of planar points,
n = max(|A|, |B|) which are given one at a time
Goal is to answer the question ”Is there a line l such that
any two points of A, B lie on different sides of l?”
Applications
Figure: A set of red points A and a set of blue points B are separated
by a line
Line Separability Of Two Point Sets
Introduction
Theorem (6)
Merging Hulls
Intuition
Algorithm
Applications
One can maintain two sets A, B of planar points such that line
separability can be decided in O(log n) time, with O(log2 n)
update time per insertion or deletion.
Proof idea
Pre-process A, B to construct the convex hulls
CH(A), CH(B)
Using a binary search like approach, decide whether
CH(A), CH(B) intersect
Maintaining the Intersection of a Set of Halfspaces
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Given a set of n halfspaces, each halfspace hi being
defined by a supporting line li
Goal is to maintain all hi ’s in order to determine whether a
query point q lies inside or outside the intersection of all
hi ’s
Maintaining the Intersection of a Set of Halfspaces
Introduction
Merging Hulls
Intuition
Algorithm
Applications
Definition
The l-intersecction of a given set of halfspaces is the
intersection of all ”left” halfspaces in the set. The
r -intersection is the intersection of all ”right” halfspaces.
Theorem (7)
Given the l-intersection of a set of n halfspaces h1 , . . . , hn , one
can decide whether a given point q lies inside, on or outside
∩ni=1 hi in O(log n) time.
References
Introduction
Merging Hulls
F. P. Preparata (1979),
An optimal real-time algorithm for planar convex hulls
Comm. ACM 22: pgs. 402-405.
Intuition
Algorithm
Applications
M. H. Overmars, J. van Leeuwen (1981),
Maintenance of configurations in the plane
Journal of Computer and System Sciences 23: pgs. 166-204.
T. M. Chan (2001),
Dynamic planar convex hull operations in near-logarithmic amortized
time.
Journal of the ACM 48: pgs. 1-12.
J. A. Cisneros (2007),
Maintenance of the Convex Hull of a Dynamic Set,
M.S. Thesis, Univ. of Edinburgh.