SlideShare a Scribd company logo
Advanced Algorithms – COMS31900
Orthogonal Range Searching
Benjamin Sach
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
n points in 2D space
|U|
|U|
The universe
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
find all employees aged between 21 and 48
with salaries between £23k and £36k
A classic database query
“
”
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
find all employees aged between 21 and 48
with salaries between £23k and £36k
A classic database query
x1 = 23 x2 = 36
y1 = 21
y2 = 48
“
”
Orthogonal range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
Orthogonal range searching
A d-dimensional range searching data structure stores n distinct points
for d = 1, the lookup(x1, x2) operation
returns every point with x1 x x2.
each point has d coordinates
for d = 3, the lookup(x1, x2, y1, y2, z1, z2) operation
returns every point with
for d = 2, the lookup(x1, x2, y1, y2) operation
returns every point with
x1 x x2 and y1 y y2.
(we assume d is a constant)
x1 x x2,
y1 y y2 and
z1 z z2.
x1 x2
y1
y2
x1 x2
z
x y
Orthogonal range searching
A d-dimensional range searching data structure stores n distinct points
for d = 1, the lookup(x1, x2) operation
returns every point with x1 x x2.
each point has d coordinates
for d = 3, the lookup(x1, x2, y1, y2, z1, z2) operation
returns every point with
for d = 2, the lookup(x1, x2, y1, y2) operation
returns every point with
x1 x x2 and y1 y y2.
(we assume d is a constant)
x1 x x2,
y1 y y2 and
z1 z z2.
x1 x2
y1
y2
x1 x2
z
x y
Orthogonal range searching
A d-dimensional range searching data structure stores n distinct points
for d = 1, the lookup(x1, x2) operation
returns every point with x1 x x2.
each point has d coordinates
for d = 3, the lookup(x1, x2, y1, y2, z1, z2) operation
returns every point with
for d = 2, the lookup(x1, x2, y1, y2) operation
returns every point with
x1 x x2 and y1 y y2.
(we assume d is a constant)
x1 x x2,
y1 y y2 and
z1 z z2.
x1 x2
y1
y2
x1 x2
z
x y
Starting simple. . . 1D range searching
Starting simple. . . 1D range searching
preprocess n points on a line
Starting simple. . . 1D range searching
x1 x2
preprocess n points on a line
lookup(x1, x2) should return all points between x1 and x2
Starting simple. . . 1D range searching
x1 x2
Starting simple. . . 1D range searching
x1 x2
3 7 11 19 23 27 35 43 53 61 67
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
x1 = 15 x2 = 64
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
(i.e. the closest point to the right)
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
(i.e. the closest point to the right)
find the successor of x1 by binary search and then ‘walk’ right
to perform lookup(x1, x2). . .
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
15 < 27
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
15 < 27
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
15 > 11
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
15 > 11
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
15 < 19
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
15 < 19
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
67 > 64 = x2
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
k
lookups take O(log n + k) time (k is the number of points reported)
3
Starting simple. . . 1D range searching
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
n
x1 = 15 x2 = 64
build a sorted array containing the x-coordinates
in O(n log n) preprocessing (prep.) time
and O(n) space
to perform lookup(x1, x2). . .
find the successor of x1 by binary search and then ‘walk’ right
k
lookups take O(log n + k) time (k is the number of points reported)
3
this is called being ‘output sensitive’
Starting simple. . . 1D range searching
Starting simple. . . 1D range searching
alternatively we could build a balanced tree. . .
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
half the points are to the left half the points are to the right
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
We can store the tree in O(n) space (it has one node per point)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
We can store the tree in O(n) space (it has one node per point)
It has O(log n) depth
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
We can store the tree in O(n) space (it has one node per point)
It has O(log n) depth
O(log n)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
We can store the tree in O(n) space (it has one node per point)
It has O(log n) depth and can be built in O(n log n) time
O(log n)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
We can store the tree in O(n) space (it has one node per point)
It has O(log n) depth and can be built in O(n log n) time
O(log n)
Starting simple. . . 1D range searching
find the point in the middle
alternatively we could build a balanced tree. . .
. . . and recurse on each half
(in a tie, pick the left)
We can store the tree in O(n) space (it has one node per point)
It has O(log n) depth (O(n) time if the points are sorted)and can be built in O(n log n) time
O(log n)
Starting simple. . . 1D range searching
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
how do we do a lookup?
x1 is to the left
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
how do we do a lookup?
x1 is to the right
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1 in O(log n) time
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
after the split
off-path edge
Starting simple. . . 1D range searching
x1 x2
Step 1: find the successor of x1
Step 2: find the predecessor of x2
in O(log n) time
how do we do a lookup?
in O(log n) time
which points in the tree should we output?
look at any node on the path
this is called an
“it’s all or
nothing”
after the split
those in the O(log n) selected subtrees on the path
off-path edge
Starting simple. . . 1D range searching
x1 x2
how do we do a lookup?
look at any node on the path
this is called an
“it’s all or
nothing”
after the split
off-path edge
Starting simple. . . 1D range searching
x1 x2
how do we do a lookup?
look at any node on the path
this is called an
“it’s all or
nothing”
after the split
lookups take O(log n + k) time (k is the number of points reported)
as before
off-path edge
Starting simple. . . 1D range searching
x1 x2
how do we do a lookup?
look at any node on the path
this is called an
“it’s all or
nothing”
after the split
lookups take O(log n + k) time (k is the number of points reported)
as before
so what have we gained?
off-path edge
Subtree decomposition root
split
x1 x2
Warning: the root to split path isn’t to scale
off-path edge
off-path subtree
too small
too big
Subtree decomposition root
split
x1 x2
Warning: the root to split path isn’t to scale
after the paths to x1 and x2 split. . .
off-path edge
off-path subtree
too small
too big
Subtree decomposition root
split
x1 x2
Warning: the root to split path isn’t to scale
after the paths to x1 and x2 split. . .
any off-path subtree is either in or out
off-path edge
off-path subtree
too small
too big
Subtree decomposition root
split
x1 x2
Warning: the root to split path isn’t to scale
after the paths to x1 and x2 split. . .
any off-path subtree is either in or out
i.e. every point in the subtree has x1 x x2 or none has
off-path edge
off-path subtree
too small
too big
Subtree decomposition root
split
x1 x2
Warning: the root to split path isn’t to scale
after the paths to x1 and x2 split. . .
any off-path subtree is either in or out
i.e. every point in the subtree has x1 x x2 or none has
off-path edge
off-path subtree
too small
too big
this will be useful for 2D range searching
1D range searching summary
O(n log n) prep time
O(n) space
O(log n + k) lookup time
where k is the number of points reported
(this is known as being output sensitive)
x1 x2
preprocess n points on a line
lookup(x1, x2) should report all points between x1 and x2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + k) + O(log n + k) + O(k)
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + k) + O(log n + k) + O(k)
= O(log n + k)
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + k) + O(log n + k) + O(k)
= O(log n + k)
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + k) + O(log n + k) + O(k)
= O(log n + k)
???
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + k) + O(log n + k) + O(k)
= O(log n + k)
???
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + kx) + O(log n + ky) + O(kx + ky)
= O(log n + kx + ky)
here kx is the number of points with x1 x x2 (respectively for ky)
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Attempt one:
• Find all the points with x1 x x2
• Find all the points with y1 y y2
• Find all the points in both lists
How long does this take?
O(log n + kx) + O(log n + ky) + O(kx + ky)
= O(log n + kx + ky)
here kx is the number of points with x1 x x2 (respectively for ky)
these could be huge in comparison with k
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
how can we do better?
Subtree decomposition in 2D root
split
x1 x2
Warning: the root to split path isn’t to scale
off-path edge
off-path subtree
x too small
x too big
(during preprocessing) build a balanced binary tree using the x-coordinates
Subtree decomposition in 2D root
split
x1 x2
Warning: the root to split path isn’t to scale
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
off-path edge
off-path subtree
x too small
x too big
(during preprocessing) build a balanced binary tree using the x-coordinates
Subtree decomposition in 2D root
split
x1 x2
Warning: the root to split path isn’t to scale
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
off-path edge
off-path subtree
x too small
x too big
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Subtree decomposition in 2D root
split
x1 x2
Warning: the root to split path isn’t to scale
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
off-path edge
off-path subtree
x too small
x too big
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
Subtree decomposition in 2D
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
Subtree decomposition in 2D
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
we want to find all points in here with y1 y y2
(they all have x1 x x2)
Subtree decomposition in 2D
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
we want to find all points in here with y1 y y2
(they all have x1 x x2)
how?
Subtree decomposition in 2D
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
we want to find all points in here with y1 y y2
(they all have x1 x x2)
how?
build a 1D range searching structure at every node
(during preprocessing)
on the y-coordinates of the points in the subtree
Subtree decomposition in 2D
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
we want to find all points in here with y1 y y2
(they all have x1 x x2)
how?
build a 1D range searching structure at every node
(during preprocessing)
on the y-coordinates of the points in the subtree
a 1D lookup takes O(log n + k ) time
k
Subtree decomposition in 2D
to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before
(during preprocessing) build a balanced binary tree using the x-coordinates
for any off-path subtree. . .
every point in the subtree has x1 x x2 or no point has
Idea: filter these subtrees by y-coordinate
we want to find all points in here with y1 y y2
(they all have x1 x x2)
how?
build a 1D range searching structure at every node
(during preprocessing)
on the y-coordinates of the points in the subtree
a 1D lookup takes O(log n + k ) time
k
and only returns points we want
Subtree decomposition in 2D
Query summary
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2 (inspecting the points on the path as you go)
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
(inspecting the points on the path as you go)
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
(inspecting the points on the path as you go)
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
perform lookup(y1, y2) on the
points in this subtree
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
perform lookup(y1, y2) on the
points in this subtree
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
perform lookup(y1, y2) on the
points in this subtree
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
perform lookup(y1, y2) on the
points in this subtree
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
perform lookup(y1, y2) on the
points in this subtree
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
Each takes O(log n + k ) time
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
Each takes O(log n + k ) time
This sums to. . .
O(log2 n + k)
x1 x2
Subtree decomposition in 2D
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(inspecting the points on the path as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
Each takes O(log n + k ) time
This sums to. . .
O(log2 n + k)
because the 1D lookups are disjoint
x1 x2
Space Usage
at each node we store an array
the array is sorted by y coordinate
(this gives us a 1D range data structure)
How much space does our 2D range structure use?
containing the points in its subtree
the original (1D) structure used O(n) space. . .
but we added some stuff
Space Usage
at each node we store an array
the array is sorted by y coordinate
(this gives us a 1D range data structure)
How much space does our 2D range structure use?
containing the points in its subtree
the original (1D) structure used O(n) space. . .
but we added some stuff
look at any level in the tree
i.e. all nodes at the same distance from the root
Space Usage
at each node we store an array
the array is sorted by y coordinate
(this gives us a 1D range data structure)
How much space does our 2D range structure use?
containing the points in its subtree
the original (1D) structure used O(n) space. . .
but we added some stuff
look at any level in the tree
i.e. all nodes at the same distance from the root
the points in these subtrees are disjoint
Space Usage
at each node we store an array
the array is sorted by y coordinate
(this gives us a 1D range data structure)
How much space does our 2D range structure use?
containing the points in its subtree
the original (1D) structure used O(n) space. . .
but we added some stuff
look at any level in the tree
i.e. all nodes at the same distance from the root
the points in these subtrees are disjoint
so the sizes of the arrays add up to n
Space Usage
at each node we store an array
the array is sorted by y coordinate
(this gives us a 1D range data structure)
How much space does our 2D range structure use?
containing the points in its subtree
the original (1D) structure used O(n) space. . .
but we added some stuff
look at any level in the tree
i.e. all nodes at the same distance from the root
the points in these subtrees are disjoint
so the sizes of the arrays add up to n
As the tree has depth O(log n). . .
Space Usage
at each node we store an array
the array is sorted by y coordinate
(this gives us a 1D range data structure)
How much space does our 2D range structure use?
containing the points in its subtree
the original (1D) structure used O(n) space. . .
but we added some stuff
look at any level in the tree
i.e. all nodes at the same distance from the root
the points in these subtrees are disjoint
so the sizes of the arrays add up to n
As the tree has depth O(log n). . .
the total space used is O(n log n)
Preprocessing time
How long does it take to build the arrays at the nodes?
How much prep time does our 2D range structure take?
the original (1D) structure used O(n log n) prep time. . .
but we added some stuff
Preprocessing time
How long does it take to build the arrays at the nodes?
How much prep time does our 2D range structure take?
the original (1D) structure used O(n log n) prep time. . .
but we added some stuff
Preprocessing time
How long does it take to build the arrays at the nodes?
How much prep time does our 2D range structure take?
the original (1D) structure used O(n log n) prep time. . .
but we added some stuff
is just merged with
as and are already sorted,
merging them takes O( ) time
Therefore the total time is O(n log n)
(which is the sum of the lengths of the arrays)
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Summary
O(n log n) prep time
O(n log n) space
O(log2 n + k) lookup time
where k is the number of points reported
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Summary
O(n log n) prep time
O(n log n) space
O(log2 n + k) lookup time
where k is the number of points reported
actually we can improve this :)
Improving the query time
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
y1 = 15 y2 = 64
when we do a 2D look-up we do O(log n) 1D lookups. . .
all with the same y1 and y2
(but on different point sets)
Improving the query time
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
y1 = 15 y2 = 64
when we do a 2D look-up we do O(log n) 1D lookups. . .
all with the same y1 and y2
(but on different point sets)
The slow part is finding the successor of y1
Improving the query time
3 7 11 19 23 27 35 43 53 61 67
3 7 11 19 23 27 35 43 53 61 67
y1 = 15 y2 = 64
when we do a 2D look-up we do O(log n) 1D lookups. . .
all with the same y1 and y2
(but on different point sets)
The slow part is finding the successor of y1
If I told you where this point was, a 1D lookup would only take O(k ) time
(where k is the number of points between y1 and y2)
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Consider a point in the parent array. . .
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Consider a point in the parent array. . .
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Consider a point in the parent array. . .
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Consider a point in the parent array. . .
we add a link to its successor in both child arrays
(we do this for every point during preprocessing)
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Consider a point in the parent array. . .
we add a link to its successor in both child arrays
(we do this for every point during preprocessing)
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
The arrays of points at the children
partition the array of the parent
The child arrays are sorted by y coordinate
(but have been partitioned by x coordinate)
Consider a point in the parent array. . .
we add a link to its successor in both child arrays
(we do this for every point during preprocessing)
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
Observation if we know where the successor of y1 is in the
parent, can find the successor in either child in O(1) time
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
Observation if we know where the successor of y1 is in the
parent, can find the successor in either child in O(1) time
y1 = 15
y1 = 15 y1 = 15
Improving the query time
7
3 7 11 19 23 27 35 43 53 61 67
311 19 23 2735 43 5361 67
Observation if we know where the successor of y1 is in the
parent, can find the successor in either child in O(1) time
y1 = 15
y1 = 15 y1 = 15
adding these links doesn’t increase the space or the prep time
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The paths have length O(log n)
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
Each takes O(k ) time
The improved query time
Query summary
1. Follow the paths to x1 and x2
2. Discard off-path subtrees where the x coordinates are too large or too small
3. For each off-path subtree where the x coordinates are in range. . .
use the 1D range structure for that subtree
to filter the y coordinates
(updating the successor to y1 as you go)
How long does a query take?
The paths have length O(log n)
So steps 1. and 2. take O(log n) time
As for step 3,
We do O(log n) 1D lookups. . .
Each takes O(k ) time
This sums to. . .
O(log n + k)
2D range searching
A 2D range searching data structure stores n distinct (x, y)-pairs and supports:
the lookup(x1, x2, y1, y2) operation
which returns every point in the rectangle [x1 : x2] × [y1 : y2]
i.e. every (x, y) with x1 x x2 and y1 y y2.
x1 x2
y1
y2
Summary
O(n log n) prep time
O(n log n) space
O(log n + k) lookup time
where k is the number of points reported
we improved this :)
using fractional cascading

More Related Content

What's hot

Activation function
Activation functionActivation function
Activation function
Astha Jain
 
Image processing fundamentals
Image processing fundamentalsImage processing fundamentals
Image processing fundamentals
A B Shinde
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
Yash Patel
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
MuhammadHamza401
 
Parallel Database
Parallel DatabaseParallel Database
Parallel Database
VESIT/University of Mumbai
 
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Mohammed Bennamoun
 
6.frequency domain image_processing
6.frequency domain image_processing6.frequency domain image_processing
6.frequency domain image_processing
Nashid Alam
 
Single instruction multiple data
Single instruction multiple dataSingle instruction multiple data
Single instruction multiple data
Syed Zaid Irshad
 
Artificial neural networks (2)
Artificial neural networks (2)Artificial neural networks (2)
Artificial neural networks (2)
sai anjaneya
 
I/O System
I/O SystemI/O System
I/O System
Nagarajan
 
backpropagation in neural networks
backpropagation in neural networksbackpropagation in neural networks
backpropagation in neural networks
Akash Goel
 
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
 
Pthread
PthreadPthread
Pthread
Gopi Saiteja
 
Forward Backward Chaining
Forward Backward ChainingForward Backward Chaining
Forward Backward Chaining
QAU ISLAMABAD,PAKISTAN
 
Computer Organization and Architecture.
Computer Organization and Architecture.Computer Organization and Architecture.
Computer Organization and Architecture.
CS_GDRCST
 
Hebbian Learning
Hebbian LearningHebbian Learning
Hebbian LearningESCOM
 
Max net
Max netMax net
Recurrent Neural Networks
Recurrent Neural NetworksRecurrent Neural Networks
Recurrent Neural Networks
Rakuten Group, Inc.
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Insertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityInsertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexity
Motaleb Hossen Manik
 

What's hot (20)

Activation function
Activation functionActivation function
Activation function
 
Image processing fundamentals
Image processing fundamentalsImage processing fundamentals
Image processing fundamentals
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
 
Parallel Database
Parallel DatabaseParallel Database
Parallel Database
 
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
 
6.frequency domain image_processing
6.frequency domain image_processing6.frequency domain image_processing
6.frequency domain image_processing
 
Single instruction multiple data
Single instruction multiple dataSingle instruction multiple data
Single instruction multiple data
 
Artificial neural networks (2)
Artificial neural networks (2)Artificial neural networks (2)
Artificial neural networks (2)
 
I/O System
I/O SystemI/O System
I/O System
 
backpropagation in neural networks
backpropagation in neural networksbackpropagation in neural networks
backpropagation in neural networks
 
NP completeness
NP completenessNP completeness
NP completeness
 
Pthread
PthreadPthread
Pthread
 
Forward Backward Chaining
Forward Backward ChainingForward Backward Chaining
Forward Backward Chaining
 
Computer Organization and Architecture.
Computer Organization and Architecture.Computer Organization and Architecture.
Computer Organization and Architecture.
 
Hebbian Learning
Hebbian LearningHebbian Learning
Hebbian Learning
 
Max net
Max netMax net
Max net
 
Recurrent Neural Networks
Recurrent Neural NetworksRecurrent Neural Networks
Recurrent Neural Networks
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Insertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityInsertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexity
 

Viewers also liked

Introduccion a las redes
Introduccion a las redesIntroduccion a las redes
Introduccion a las redes
Bryan Geovanny
 
Comunicato pallavolo N°10 del 14 dicembre 2016
Comunicato pallavolo N°10 del 14 dicembre 2016Comunicato pallavolo N°10 del 14 dicembre 2016
Comunicato pallavolo N°10 del 14 dicembre 2016
Giuliano Ganassi
 
Attività sportiva giovanile - Campionati under calcio
Attività sportiva giovanile - Campionati under calcioAttività sportiva giovanile - Campionati under calcio
Attività sportiva giovanile - Campionati under calcio
Giuliano Ganassi
 
Tg &amp; blr protect
Tg &amp; blr protectTg &amp; blr protect
Tg &amp; blr protect
Kattukolu Kishorereddy
 
Unit 5 -_storage_devices
Unit 5 -_storage_devicesUnit 5 -_storage_devices
Unit 5 -_storage_devicessaltashict
 
Evolution of Shilpa shetty
Evolution of Shilpa shettyEvolution of Shilpa shetty
Evolution of Shilpa shetty
sultanarun
 
Costs of the French PWR
Costs of the French PWRCosts of the French PWR
Costs of the French PWRmyatom
 
Video Mailer
Video MailerVideo Mailer
3ª sesion taller Google Maps
3ª sesion taller Google Maps3ª sesion taller Google Maps
3ª sesion taller Google Mapsescoitarteixo
 
Dhoom
DhoomDhoom
Dhoom
sultanarun
 
On Mathematics Learning Perspective Among Teachers And Students In China
On Mathematics Learning  Perspective Among Teachers And Students In ChinaOn Mathematics Learning  Perspective Among Teachers And Students In China
On Mathematics Learning Perspective Among Teachers And Students In China
Xu jiakon
 
Amsterdam
AmsterdamAmsterdam
Modulation & Multiple Access Schemes
Modulation & Multiple Access SchemesModulation & Multiple Access Schemes
Modulation & Multiple Access Schemesravi4s
 
শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬
শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬
শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬
Bangladesh University of Textiles (BUTEX)
 
CQM and PQRS Reporting with Practice Fusion
CQM and PQRS Reporting with Practice FusionCQM and PQRS Reporting with Practice Fusion
CQM and PQRS Reporting with Practice Fusion
Kimberly Hilton
 
Approximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsApproximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximations
Benjamin Sach
 
Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014
Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014
Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014
Practice Fusion
 
6.queue
6.queue6.queue
6.queue
Chandan Singh
 

Viewers also liked (20)

Introduccion a las redes
Introduccion a las redesIntroduccion a las redes
Introduccion a las redes
 
Comunicato pallavolo N°10 del 14 dicembre 2016
Comunicato pallavolo N°10 del 14 dicembre 2016Comunicato pallavolo N°10 del 14 dicembre 2016
Comunicato pallavolo N°10 del 14 dicembre 2016
 
Attività sportiva giovanile - Campionati under calcio
Attività sportiva giovanile - Campionati under calcioAttività sportiva giovanile - Campionati under calcio
Attività sportiva giovanile - Campionati under calcio
 
Tg &amp; blr protect
Tg &amp; blr protectTg &amp; blr protect
Tg &amp; blr protect
 
Unit 5 -_storage_devices
Unit 5 -_storage_devicesUnit 5 -_storage_devices
Unit 5 -_storage_devices
 
Evolution of Shilpa shetty
Evolution of Shilpa shettyEvolution of Shilpa shetty
Evolution of Shilpa shetty
 
Costs of the French PWR
Costs of the French PWRCosts of the French PWR
Costs of the French PWR
 
bcn
bcnbcn
bcn
 
Video Mailer
Video MailerVideo Mailer
Video Mailer
 
3ª sesion taller Google Maps
3ª sesion taller Google Maps3ª sesion taller Google Maps
3ª sesion taller Google Maps
 
Leituras do 7ºA
Leituras do 7ºALeituras do 7ºA
Leituras do 7ºA
 
Dhoom
DhoomDhoom
Dhoom
 
On Mathematics Learning Perspective Among Teachers And Students In China
On Mathematics Learning  Perspective Among Teachers And Students In ChinaOn Mathematics Learning  Perspective Among Teachers And Students In China
On Mathematics Learning Perspective Among Teachers And Students In China
 
Amsterdam
AmsterdamAmsterdam
Amsterdam
 
Modulation & Multiple Access Schemes
Modulation & Multiple Access SchemesModulation & Multiple Access Schemes
Modulation & Multiple Access Schemes
 
শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬
শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬
শাহাবাজপুর ইউ/সি উচ্চ বিদ্যালয়ের ১ম পুনর্মিলনী ৯ জুলাই, ২০১৬
 
CQM and PQRS Reporting with Practice Fusion
CQM and PQRS Reporting with Practice FusionCQM and PQRS Reporting with Practice Fusion
CQM and PQRS Reporting with Practice Fusion
 
Approximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximationsApproximation Algorithms Part Two: More Constant factor approximations
Approximation Algorithms Part Two: More Constant factor approximations
 
Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014
Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014
Understanding the Physician Quality Reporting System (PQRS) Requirements in 2014
 
6.queue
6.queue6.queue
6.queue
 

Similar to Orthogonal Range Searching

Calculo integral - Larson
Calculo integral - LarsonCalculo integral - Larson
Calculo integral - Larson
Juan Alejandro Alvarez Agudelo
 
Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012
Jacob_Evenson
 
Grph quad fncts
Grph quad fnctsGrph quad fncts
Grph quad fncts
Edrian Gustin Camacho
 
April 14, 2015
April 14, 2015April 14, 2015
April 14, 2015khyps13
 
Class 12 practice paper
Class 12 practice paperClass 12 practice paper
Class 12 practice paper
KarunaGupta1982
 
Assignment chapters 3 to 7
Assignment chapters 3 to 7Assignment chapters 3 to 7
Assignment chapters 3 to 7
KarunaGupta1982
 
Interpolation.pptx
Interpolation.pptxInterpolation.pptx
Interpolation.pptx
MinaSafwatMSR
 
Derivatives
DerivativesDerivatives
Derivatives
Nisarg Amin
 
Straight-Line-Graphs-Final -2.pptx
Straight-Line-Graphs-Final -2.pptxStraight-Line-Graphs-Final -2.pptx
Straight-Line-Graphs-Final -2.pptx
Kviskvis
 
Area between curves
Area between curvesArea between curves
Area between curves
Shaun Wilson
 
Module 3 quadratic functions
Module 3   quadratic functionsModule 3   quadratic functions
Module 3 quadratic functions
dionesioable
 
5 DimensionalityReduction.pdf
5 DimensionalityReduction.pdf5 DimensionalityReduction.pdf
5 DimensionalityReduction.pdf
Rahul926331
 
Area between curves
Area between curvesArea between curves
Area between curves
djfromal
 
C2 st lecture 4 handout
C2 st lecture 4 handoutC2 st lecture 4 handout
C2 st lecture 4 handoutfatima d
 
Properties of-graphs-2.5
Properties of-graphs-2.5Properties of-graphs-2.5
Properties of-graphs-2.5
International advisers
 
Module 2 exponential functions
Module 2   exponential functionsModule 2   exponential functions
Module 2 exponential functions
dionesioable
 

Similar to Orthogonal Range Searching (20)

Linear equations 2-2 a graphing and x-y intercepts
Linear equations   2-2 a graphing and x-y interceptsLinear equations   2-2 a graphing and x-y intercepts
Linear equations 2-2 a graphing and x-y intercepts
 
Calculo integral - Larson
Calculo integral - LarsonCalculo integral - Larson
Calculo integral - Larson
 
Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012
 
Grph quad fncts
Grph quad fnctsGrph quad fncts
Grph quad fncts
 
April 14, 2015
April 14, 2015April 14, 2015
April 14, 2015
 
Class 12 practice paper
Class 12 practice paperClass 12 practice paper
Class 12 practice paper
 
Numerical method
Numerical methodNumerical method
Numerical method
 
Math report
Math reportMath report
Math report
 
Assignment chapters 3 to 7
Assignment chapters 3 to 7Assignment chapters 3 to 7
Assignment chapters 3 to 7
 
Math is fun!
Math is fun!Math is fun!
Math is fun!
 
Interpolation.pptx
Interpolation.pptxInterpolation.pptx
Interpolation.pptx
 
Derivatives
DerivativesDerivatives
Derivatives
 
Straight-Line-Graphs-Final -2.pptx
Straight-Line-Graphs-Final -2.pptxStraight-Line-Graphs-Final -2.pptx
Straight-Line-Graphs-Final -2.pptx
 
Area between curves
Area between curvesArea between curves
Area between curves
 
Module 3 quadratic functions
Module 3   quadratic functionsModule 3   quadratic functions
Module 3 quadratic functions
 
5 DimensionalityReduction.pdf
5 DimensionalityReduction.pdf5 DimensionalityReduction.pdf
5 DimensionalityReduction.pdf
 
Area between curves
Area between curvesArea between curves
Area between curves
 
C2 st lecture 4 handout
C2 st lecture 4 handoutC2 st lecture 4 handout
C2 st lecture 4 handout
 
Properties of-graphs-2.5
Properties of-graphs-2.5Properties of-graphs-2.5
Properties of-graphs-2.5
 
Module 2 exponential functions
Module 2   exponential functionsModule 2   exponential functions
Module 2 exponential functions
 

More from Benjamin Sach

Approximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTASApproximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTAS
Benjamin Sach
 
Approximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTASApproximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTAS
Benjamin Sach
 
Approximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximationsApproximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximations
Benjamin Sach
 
van Emde Boas trees
van Emde Boas treesvan Emde Boas trees
van Emde Boas trees
Benjamin Sach
 
Pattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesPattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatches
Benjamin Sach
 
Pattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistancePattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming Distance
Benjamin Sach
 
Lowest Common Ancestor
Lowest Common AncestorLowest Common Ancestor
Lowest Common Ancestor
Benjamin Sach
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum Queries
Benjamin Sach
 
Pattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysPattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix Arrays
Benjamin Sach
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix Trees
Benjamin Sach
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo Hashing
Benjamin Sach
 
Hashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect HashingHashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect Hashing
Benjamin Sach
 
Hashing Part One
Hashing Part OneHashing Part One
Hashing Part One
Benjamin Sach
 
Probability Recap
Probability RecapProbability Recap
Probability Recap
Benjamin Sach
 
Bloom Filters
Bloom FiltersBloom Filters
Bloom Filters
Benjamin Sach
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
Benjamin Sach
 
Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)
Benjamin Sach
 
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmShortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Benjamin Sach
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
Benjamin Sach
 
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsShortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
Benjamin Sach
 

More from Benjamin Sach (20)

Approximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTASApproximation Algorithms Part Four: APTAS
Approximation Algorithms Part Four: APTAS
 
Approximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTASApproximation Algorithms Part Three: (F)PTAS
Approximation Algorithms Part Three: (F)PTAS
 
Approximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximationsApproximation Algorithms Part One: Constant factor approximations
Approximation Algorithms Part One: Constant factor approximations
 
van Emde Boas trees
van Emde Boas treesvan Emde Boas trees
van Emde Boas trees
 
Pattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesPattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatches
 
Pattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistancePattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming Distance
 
Lowest Common Ancestor
Lowest Common AncestorLowest Common Ancestor
Lowest Common Ancestor
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum Queries
 
Pattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysPattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix Arrays
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix Trees
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo Hashing
 
Hashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect HashingHashing Part Two: Static Perfect Hashing
Hashing Part Two: Static Perfect Hashing
 
Hashing Part One
Hashing Part OneHashing Part One
Hashing Part One
 
Probability Recap
Probability RecapProbability Recap
Probability Recap
 
Bloom Filters
Bloom FiltersBloom Filters
Bloom Filters
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)
 
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmShortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
 
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsShortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
 

Recently uploaded

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

Orthogonal Range Searching

  • 1. Advanced Algorithms – COMS31900 Orthogonal Range Searching Benjamin Sach
  • 2. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2.
  • 3. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2.
  • 4. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. n points in 2D space |U| |U| The universe
  • 5. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2.
  • 6. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2.
  • 7. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2
  • 8. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2
  • 9. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 find all employees aged between 21 and 48 with salaries between £23k and £36k A classic database query “ ”
  • 10. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. find all employees aged between 21 and 48 with salaries between £23k and £36k A classic database query x1 = 23 x2 = 36 y1 = 21 y2 = 48 “ ”
  • 11. Orthogonal range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2.
  • 12. Orthogonal range searching A d-dimensional range searching data structure stores n distinct points for d = 1, the lookup(x1, x2) operation returns every point with x1 x x2. each point has d coordinates for d = 3, the lookup(x1, x2, y1, y2, z1, z2) operation returns every point with for d = 2, the lookup(x1, x2, y1, y2) operation returns every point with x1 x x2 and y1 y y2. (we assume d is a constant) x1 x x2, y1 y y2 and z1 z z2. x1 x2 y1 y2 x1 x2 z x y
  • 13. Orthogonal range searching A d-dimensional range searching data structure stores n distinct points for d = 1, the lookup(x1, x2) operation returns every point with x1 x x2. each point has d coordinates for d = 3, the lookup(x1, x2, y1, y2, z1, z2) operation returns every point with for d = 2, the lookup(x1, x2, y1, y2) operation returns every point with x1 x x2 and y1 y y2. (we assume d is a constant) x1 x x2, y1 y y2 and z1 z z2. x1 x2 y1 y2 x1 x2 z x y
  • 14. Orthogonal range searching A d-dimensional range searching data structure stores n distinct points for d = 1, the lookup(x1, x2) operation returns every point with x1 x x2. each point has d coordinates for d = 3, the lookup(x1, x2, y1, y2, z1, z2) operation returns every point with for d = 2, the lookup(x1, x2, y1, y2) operation returns every point with x1 x x2 and y1 y y2. (we assume d is a constant) x1 x x2, y1 y y2 and z1 z z2. x1 x2 y1 y2 x1 x2 z x y
  • 15. Starting simple. . . 1D range searching
  • 16. Starting simple. . . 1D range searching preprocess n points on a line
  • 17. Starting simple. . . 1D range searching x1 x2 preprocess n points on a line lookup(x1, x2) should return all points between x1 and x2
  • 18. Starting simple. . . 1D range searching x1 x2
  • 19. Starting simple. . . 1D range searching x1 x2 3 7 11 19 23 27 35 43 53 61 67
  • 20. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 x1 = 15 x2 = 64
  • 21. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time
  • 22. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space
  • 23. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 24. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right (i.e. the closest point to the right)
  • 25. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space (i.e. the closest point to the right) find the successor of x1 by binary search and then ‘walk’ right to perform lookup(x1, x2). . .
  • 26. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 15 < 27
  • 27. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 15 < 27
  • 28. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 15 > 11
  • 29. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 15 > 11
  • 30. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 15 < 19
  • 31. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 15 < 19
  • 32. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 33. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 34. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 35. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 36. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 37. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 38. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 39. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right 67 > 64 = x2
  • 40. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right
  • 41. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right k lookups take O(log n + k) time (k is the number of points reported) 3
  • 42. Starting simple. . . 1D range searching 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 n x1 = 15 x2 = 64 build a sorted array containing the x-coordinates in O(n log n) preprocessing (prep.) time and O(n) space to perform lookup(x1, x2). . . find the successor of x1 by binary search and then ‘walk’ right k lookups take O(log n + k) time (k is the number of points reported) 3 this is called being ‘output sensitive’
  • 43. Starting simple. . . 1D range searching
  • 44. Starting simple. . . 1D range searching alternatively we could build a balanced tree. . .
  • 45. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . .
  • 46. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . half the points are to the left half the points are to the right
  • 47. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . .
  • 48. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half
  • 49. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half
  • 50. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half
  • 51. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left)
  • 52. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left)
  • 53. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left)
  • 54. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left)
  • 55. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left) We can store the tree in O(n) space (it has one node per point)
  • 56. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left) We can store the tree in O(n) space (it has one node per point) It has O(log n) depth
  • 57. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left) We can store the tree in O(n) space (it has one node per point) It has O(log n) depth O(log n)
  • 58. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left) We can store the tree in O(n) space (it has one node per point) It has O(log n) depth and can be built in O(n log n) time O(log n)
  • 59. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left) We can store the tree in O(n) space (it has one node per point) It has O(log n) depth and can be built in O(n log n) time O(log n)
  • 60. Starting simple. . . 1D range searching find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half (in a tie, pick the left) We can store the tree in O(n) space (it has one node per point) It has O(log n) depth (O(n) time if the points are sorted)and can be built in O(n log n) time O(log n)
  • 61. Starting simple. . . 1D range searching how do we do a lookup?
  • 62. Starting simple. . . 1D range searching x1 x2 how do we do a lookup?
  • 63. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 how do we do a lookup?
  • 64. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 how do we do a lookup?
  • 65. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 how do we do a lookup? x1 is to the left
  • 66. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 how do we do a lookup? x1 is to the right
  • 67. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 how do we do a lookup?
  • 68. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 in O(log n) time how do we do a lookup?
  • 69. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup?
  • 70. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup?
  • 71. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup?
  • 72. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup?
  • 73. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time
  • 74. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output?
  • 75. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output?
  • 76. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path
  • 77. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an off-path edge
  • 78. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 79. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 80. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 81. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 82. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge off-path edge
  • 83. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge off-path edge
  • 84. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge off-path edge
  • 85. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 86. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 87. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 88. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 89. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 90. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 91. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 92. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” off-path edge
  • 93. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” after the split off-path edge
  • 94. Starting simple. . . 1D range searching x1 x2 Step 1: find the successor of x1 Step 2: find the predecessor of x2 in O(log n) time how do we do a lookup? in O(log n) time which points in the tree should we output? look at any node on the path this is called an “it’s all or nothing” after the split those in the O(log n) selected subtrees on the path off-path edge
  • 95. Starting simple. . . 1D range searching x1 x2 how do we do a lookup? look at any node on the path this is called an “it’s all or nothing” after the split off-path edge
  • 96. Starting simple. . . 1D range searching x1 x2 how do we do a lookup? look at any node on the path this is called an “it’s all or nothing” after the split lookups take O(log n + k) time (k is the number of points reported) as before off-path edge
  • 97. Starting simple. . . 1D range searching x1 x2 how do we do a lookup? look at any node on the path this is called an “it’s all or nothing” after the split lookups take O(log n + k) time (k is the number of points reported) as before so what have we gained? off-path edge
  • 98. Subtree decomposition root split x1 x2 Warning: the root to split path isn’t to scale off-path edge off-path subtree too small too big
  • 99. Subtree decomposition root split x1 x2 Warning: the root to split path isn’t to scale after the paths to x1 and x2 split. . . off-path edge off-path subtree too small too big
  • 100. Subtree decomposition root split x1 x2 Warning: the root to split path isn’t to scale after the paths to x1 and x2 split. . . any off-path subtree is either in or out off-path edge off-path subtree too small too big
  • 101. Subtree decomposition root split x1 x2 Warning: the root to split path isn’t to scale after the paths to x1 and x2 split. . . any off-path subtree is either in or out i.e. every point in the subtree has x1 x x2 or none has off-path edge off-path subtree too small too big
  • 102. Subtree decomposition root split x1 x2 Warning: the root to split path isn’t to scale after the paths to x1 and x2 split. . . any off-path subtree is either in or out i.e. every point in the subtree has x1 x x2 or none has off-path edge off-path subtree too small too big this will be useful for 2D range searching
  • 103. 1D range searching summary O(n log n) prep time O(n) space O(log n + k) lookup time where k is the number of points reported (this is known as being output sensitive) x1 x2 preprocess n points on a line lookup(x1, x2) should report all points between x1 and x2
  • 104. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2
  • 105. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one:
  • 106. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2
  • 107. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2
  • 108. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2
  • 109. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2
  • 110. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2
  • 111. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists
  • 112. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists
  • 113. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take?
  • 114. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + k) + O(log n + k) + O(k)
  • 115. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + k) + O(log n + k) + O(k) = O(log n + k)
  • 116. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + k) + O(log n + k) + O(k) = O(log n + k)
  • 117. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + k) + O(log n + k) + O(k) = O(log n + k) ???
  • 118. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + k) + O(log n + k) + O(k) = O(log n + k) ???
  • 119. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + kx) + O(log n + ky) + O(kx + ky) = O(log n + kx + ky) here kx is the number of points with x1 x x2 (respectively for ky)
  • 120. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Attempt one: • Find all the points with x1 x x2 • Find all the points with y1 y y2 • Find all the points in both lists How long does this take? O(log n + kx) + O(log n + ky) + O(kx + ky) = O(log n + kx + ky) here kx is the number of points with x1 x x2 (respectively for ky) these could be huge in comparison with k
  • 121. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2
  • 122. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 how can we do better?
  • 123. Subtree decomposition in 2D root split x1 x2 Warning: the root to split path isn’t to scale off-path edge off-path subtree x too small x too big (during preprocessing) build a balanced binary tree using the x-coordinates
  • 124. Subtree decomposition in 2D root split x1 x2 Warning: the root to split path isn’t to scale to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before off-path edge off-path subtree x too small x too big (during preprocessing) build a balanced binary tree using the x-coordinates
  • 125. Subtree decomposition in 2D root split x1 x2 Warning: the root to split path isn’t to scale to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before off-path edge off-path subtree x too small x too big (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has
  • 126. Subtree decomposition in 2D root split x1 x2 Warning: the root to split path isn’t to scale to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before off-path edge off-path subtree x too small x too big (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate
  • 127. Subtree decomposition in 2D to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate
  • 128. Subtree decomposition in 2D to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate we want to find all points in here with y1 y y2 (they all have x1 x x2)
  • 129. Subtree decomposition in 2D to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate we want to find all points in here with y1 y y2 (they all have x1 x x2) how?
  • 130. Subtree decomposition in 2D to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate we want to find all points in here with y1 y y2 (they all have x1 x x2) how? build a 1D range searching structure at every node (during preprocessing) on the y-coordinates of the points in the subtree
  • 131. Subtree decomposition in 2D to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate we want to find all points in here with y1 y y2 (they all have x1 x x2) how? build a 1D range searching structure at every node (during preprocessing) on the y-coordinates of the points in the subtree a 1D lookup takes O(log n + k ) time k
  • 132. Subtree decomposition in 2D to perform a lookup(x1, x2, y1, y2) follow the paths to x1 and x2 as before (during preprocessing) build a balanced binary tree using the x-coordinates for any off-path subtree. . . every point in the subtree has x1 x x2 or no point has Idea: filter these subtrees by y-coordinate we want to find all points in here with y1 y y2 (they all have x1 x x2) how? build a 1D range searching structure at every node (during preprocessing) on the y-coordinates of the points in the subtree a 1D lookup takes O(log n + k ) time k and only returns points we want
  • 133. Subtree decomposition in 2D Query summary x1 x2
  • 134. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 x1 x2
  • 135. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 (inspecting the points on the path as you go) x1 x2
  • 136. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small (inspecting the points on the path as you go) x1 x2
  • 137. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small (inspecting the points on the path as you go) x1 x2
  • 138. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) x1 x2
  • 139. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) perform lookup(y1, y2) on the points in this subtree x1 x2
  • 140. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) perform lookup(y1, y2) on the points in this subtree x1 x2
  • 141. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) perform lookup(y1, y2) on the points in this subtree x1 x2
  • 142. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) perform lookup(y1, y2) on the points in this subtree x1 x2
  • 143. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) perform lookup(y1, y2) on the points in this subtree x1 x2
  • 144. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? x1 x2
  • 145. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) x1 x2
  • 146. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time x1 x2
  • 147. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, x1 x2
  • 148. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . . x1 x2
  • 149. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . . Each takes O(log n + k ) time x1 x2
  • 150. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . . Each takes O(log n + k ) time This sums to. . . O(log2 n + k) x1 x2
  • 151. Subtree decomposition in 2D Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (inspecting the points on the path as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . . Each takes O(log n + k ) time This sums to. . . O(log2 n + k) because the 1D lookups are disjoint x1 x2
  • 152. Space Usage at each node we store an array the array is sorted by y coordinate (this gives us a 1D range data structure) How much space does our 2D range structure use? containing the points in its subtree the original (1D) structure used O(n) space. . . but we added some stuff
  • 153. Space Usage at each node we store an array the array is sorted by y coordinate (this gives us a 1D range data structure) How much space does our 2D range structure use? containing the points in its subtree the original (1D) structure used O(n) space. . . but we added some stuff look at any level in the tree i.e. all nodes at the same distance from the root
  • 154. Space Usage at each node we store an array the array is sorted by y coordinate (this gives us a 1D range data structure) How much space does our 2D range structure use? containing the points in its subtree the original (1D) structure used O(n) space. . . but we added some stuff look at any level in the tree i.e. all nodes at the same distance from the root the points in these subtrees are disjoint
  • 155. Space Usage at each node we store an array the array is sorted by y coordinate (this gives us a 1D range data structure) How much space does our 2D range structure use? containing the points in its subtree the original (1D) structure used O(n) space. . . but we added some stuff look at any level in the tree i.e. all nodes at the same distance from the root the points in these subtrees are disjoint so the sizes of the arrays add up to n
  • 156. Space Usage at each node we store an array the array is sorted by y coordinate (this gives us a 1D range data structure) How much space does our 2D range structure use? containing the points in its subtree the original (1D) structure used O(n) space. . . but we added some stuff look at any level in the tree i.e. all nodes at the same distance from the root the points in these subtrees are disjoint so the sizes of the arrays add up to n As the tree has depth O(log n). . .
  • 157. Space Usage at each node we store an array the array is sorted by y coordinate (this gives us a 1D range data structure) How much space does our 2D range structure use? containing the points in its subtree the original (1D) structure used O(n) space. . . but we added some stuff look at any level in the tree i.e. all nodes at the same distance from the root the points in these subtrees are disjoint so the sizes of the arrays add up to n As the tree has depth O(log n). . . the total space used is O(n log n)
  • 158. Preprocessing time How long does it take to build the arrays at the nodes? How much prep time does our 2D range structure take? the original (1D) structure used O(n log n) prep time. . . but we added some stuff
  • 159. Preprocessing time How long does it take to build the arrays at the nodes? How much prep time does our 2D range structure take? the original (1D) structure used O(n log n) prep time. . . but we added some stuff
  • 160. Preprocessing time How long does it take to build the arrays at the nodes? How much prep time does our 2D range structure take? the original (1D) structure used O(n log n) prep time. . . but we added some stuff is just merged with as and are already sorted, merging them takes O( ) time Therefore the total time is O(n log n) (which is the sum of the lengths of the arrays)
  • 161. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Summary O(n log n) prep time O(n log n) space O(log2 n + k) lookup time where k is the number of points reported
  • 162. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Summary O(n log n) prep time O(n log n) space O(log2 n + k) lookup time where k is the number of points reported actually we can improve this :)
  • 163. Improving the query time 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 y1 = 15 y2 = 64 when we do a 2D look-up we do O(log n) 1D lookups. . . all with the same y1 and y2 (but on different point sets)
  • 164. Improving the query time 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 y1 = 15 y2 = 64 when we do a 2D look-up we do O(log n) 1D lookups. . . all with the same y1 and y2 (but on different point sets) The slow part is finding the successor of y1
  • 165. Improving the query time 3 7 11 19 23 27 35 43 53 61 67 3 7 11 19 23 27 35 43 53 61 67 y1 = 15 y2 = 64 when we do a 2D look-up we do O(log n) 1D lookups. . . all with the same y1 and y2 (but on different point sets) The slow part is finding the successor of y1 If I told you where this point was, a 1D lookup would only take O(k ) time (where k is the number of points between y1 and y2)
  • 166. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent
  • 167. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent
  • 168. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent
  • 169. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate)
  • 170. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate) Consider a point in the parent array. . .
  • 171. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate) Consider a point in the parent array. . .
  • 172. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate) Consider a point in the parent array. . .
  • 173. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate) Consider a point in the parent array. . . we add a link to its successor in both child arrays (we do this for every point during preprocessing)
  • 174. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate) Consider a point in the parent array. . . we add a link to its successor in both child arrays (we do this for every point during preprocessing)
  • 175. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 The arrays of points at the children partition the array of the parent The child arrays are sorted by y coordinate (but have been partitioned by x coordinate) Consider a point in the parent array. . . we add a link to its successor in both child arrays (we do this for every point during preprocessing)
  • 176. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67
  • 177. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 Observation if we know where the successor of y1 is in the parent, can find the successor in either child in O(1) time
  • 178. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 Observation if we know where the successor of y1 is in the parent, can find the successor in either child in O(1) time y1 = 15 y1 = 15 y1 = 15
  • 179. Improving the query time 7 3 7 11 19 23 27 35 43 53 61 67 311 19 23 2735 43 5361 67 Observation if we know where the successor of y1 is in the parent, can find the successor in either child in O(1) time y1 = 15 y1 = 15 y1 = 15 adding these links doesn’t increase the space or the prep time
  • 180. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take?
  • 181. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take? The paths have length O(log n)
  • 182. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time
  • 183. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3,
  • 184. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . .
  • 185. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . . Each takes O(k ) time
  • 186. The improved query time Query summary 1. Follow the paths to x1 and x2 2. Discard off-path subtrees where the x coordinates are too large or too small 3. For each off-path subtree where the x coordinates are in range. . . use the 1D range structure for that subtree to filter the y coordinates (updating the successor to y1 as you go) How long does a query take? The paths have length O(log n) So steps 1. and 2. take O(log n) time As for step 3, We do O(log n) 1D lookups. . . Each takes O(k ) time This sums to. . . O(log n + k)
  • 187. 2D range searching A 2D range searching data structure stores n distinct (x, y)-pairs and supports: the lookup(x1, x2, y1, y2) operation which returns every point in the rectangle [x1 : x2] × [y1 : y2] i.e. every (x, y) with x1 x x2 and y1 y y2. x1 x2 y1 y2 Summary O(n log n) prep time O(n log n) space O(log n + k) lookup time where k is the number of points reported we improved this :) using fractional cascading