Professional Documents
Culture Documents
Rectangle operations.
minXinRectangle(xL,xR,yT)
Return element with min x-coordinate in the rectangle defined by the lines, x= xL, x= xR, y = 0, y = yT, xL <= xR, 0 <= yT. yT xL xR
I.e., return element with min x such that xL <= x <= xR and 0 <= y <= yT.
maxXinRectangle(xL,xR,yT)
Return element with max x-coordinate in the rectangle defined by the lines, x= xL, x= xR, y = 0, y = yT, xL <= xR, 0 <= yT. yT xL xR
I.e., return element with max x such that xL <= x <= xR and 0 <= y <= yT.
minYinXrange(xL,xR)
Return element with min y-coordinate in the rectangle defined by the lines, x= xL, x= xR, y = 0, y = infinity, xL <= xR.
xL
xR
I.e., return element with min y such that xL <= x <= xR.
enumerateRectangle(xL,xR,yT)
Return all elements in the rectangle defined by the lines, x= xL, x= xR, y = 0, y = yT, xL <= xR, 0 <= yT. yT xL xR
I.e., return all elements such that xL <= x <= xR and 0 <= y <= yT.
Complexity
O(log n) for each operation except for enumerateRectangle, where n is the number of elements in the tree. Complexity of enumerateRectangle is O(log n + s), where s is the number of elements in the rectangle.
Applications Visibility
Dynamic set of semi-infinite vertical line segments.
Vertical lines with end points (xi,infinity) and (xi,yi). (5,6) (3,4) (2,1) (4,2)
(6,3)
Opaque/translucent lines.
Translucent Lines
(5,6) (3,4) (2,1) (4,2) (6,3)
y
0 infinity
x Eye is at (x,y). Priority search tree of line end points. enumerateRectangle(x, infinity, y).
Opaque Lines
(5,6) (3,4) (2,1) (4,2) (6,3)
y
0 infinity
x Eye is at (x,y). Priority search tree of line end points. minXinRectangle(x, infinity, y).
Bin Packing
First fit. Best fit. Combination.
Some items packed using first fit. Others packed using best fit.
Memory allocation.
First Fit
minYinXrange(neededSize, infinity) neededSize
bin index
available capacity
Best Fit
minXinRectangle(neededSize, infinity, infinity) neededSize
bin index
available capacity
Example
1e 2
2
f
4 5
c
3
d
6
Machine a is busy from time 1 to time 3. Interval is [1,3]. Machines a, b, c, e, and f are busy at some time in the interval [2,4].
Example
d
1e 2
2
f
4 5
b f
7
c
3
d
6
ea
Interval [i,j] corresponds to the pair (x,y), where x = j and y = i. enumerateRectangle(u, infinity, v). enumerateRectangle(2, infinity, 4).
Interval Containment
List all intervals [i,j] that contain the interval [u,v].
[i,j] contains [u,v] iff i <= u <= v <= j. 1e 2 3
f
4
4
2
1
c
3
d
6
[u,v] = [5,6]
Interval Containment
d
1e 2
2
f
4 5
b f
7
c
3
d
6
ea
Interval [i,j] corresponds to the pair (x,y), where x = j and y = i. enumerateRectangle(v, infinity, u). enumerateRectangle(6, infinity, 5).
G B
C F
Algorithm
A D
G B
C F
Complexity
Examine edges in sorted order.
Bottom edge => insert interval into a priority search tree. Top edge => report intersecting segments and delete the top edges corresponding bottom edge.
IP Router Table
Longest-prefix matching
10*, 101*, 1001* Destination address d = 10100 Longest matching-prefix is 101*
Prefix is an interval
d is 5 bits => 101* = [10100, 10111] = [20,23]
IP Router Table
p(d) = prefixes that match d. Use online interval intersection mapping. p(d) = enumerateRectangle(d,infinity,d)
IP Router Table
lmp(d) = [maxStart(p(d)), minFinish(p(d))] minXinRectangle(d,infinity,d) finds lmp(d) except when >1 prefixes have same finish point.
IP Router Table
Remap finish points so that all prefixes have different finish point. f = 2wf s + 2w 1 , w = length of d f is smaller when s is bigger
IP Router Table