Advanced Algorithms COMS31900 Orthogonal Range Searching Rapha el - - PowerPoint PPT Presentation

advanced algorithms coms31900 orthogonal range searching
SMART_READER_LITE
LIVE PREVIEW

Advanced Algorithms COMS31900 Orthogonal Range Searching Rapha el - - PowerPoint PPT Presentation

Advanced Algorithms COMS31900 Orthogonal Range Searching Rapha el Clifford Slides by Benjamin Sach Orthogonal range searching A 2D range searching data structure stores n distinct ( x, y ) -pairs and supports: the lookup ( x 1 , x 2 ,


slide-1
SLIDE 1

Advanced Algorithms – COMS31900 Orthogonal Range Searching

Rapha¨ el Clifford Slides by Benjamin Sach

slide-2
SLIDE 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.

slide-3
SLIDE 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.

slide-4
SLIDE 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

slide-5
SLIDE 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.

slide-6
SLIDE 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.

slide-7
SLIDE 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

slide-8
SLIDE 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

slide-9
SLIDE 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

“ ”

slide-10
SLIDE 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

“ ”

slide-11
SLIDE 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.

slide-12
SLIDE 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

slide-13
SLIDE 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

slide-14
SLIDE 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

slide-15
SLIDE 15

Starting simple. . . 1D range searching

slide-16
SLIDE 16

Starting simple. . . 1D range searching

preprocess n points on a line

slide-17
SLIDE 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

slide-18
SLIDE 18

Starting simple. . . 1D range searching

x1 x2

slide-19
SLIDE 19

Starting simple. . . 1D range searching

x1 x2 3 7 11 19 23 27 35 43 53 61 67

slide-20
SLIDE 20

Starting simple. . . 1D range searching

3 7 11 19 23 27 35 43 53 61 67 x1 = 15 x2 = 64

slide-21
SLIDE 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

slide-22
SLIDE 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

slide-23
SLIDE 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

slide-24
SLIDE 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)

slide-25
SLIDE 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). . .

slide-26
SLIDE 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

slide-27
SLIDE 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

slide-28
SLIDE 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

slide-29
SLIDE 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

slide-30
SLIDE 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

slide-31
SLIDE 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

slide-32
SLIDE 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

slide-33
SLIDE 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

slide-34
SLIDE 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

slide-35
SLIDE 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

slide-36
SLIDE 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

slide-37
SLIDE 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

slide-38
SLIDE 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

slide-39
SLIDE 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

slide-40
SLIDE 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

slide-41
SLIDE 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

slide-42
SLIDE 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’

slide-43
SLIDE 43

Starting simple. . . 1D range searching

slide-44
SLIDE 44

Starting simple. . . 1D range searching

alternatively we could build a balanced tree. . .

slide-45
SLIDE 45

Starting simple. . . 1D range searching

find the point in the middle alternatively we could build a balanced tree. . .

slide-46
SLIDE 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

slide-47
SLIDE 47

Starting simple. . . 1D range searching

find the point in the middle alternatively we could build a balanced tree. . .

slide-48
SLIDE 48

Starting simple. . . 1D range searching

find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half

slide-49
SLIDE 49

Starting simple. . . 1D range searching

find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half

slide-50
SLIDE 50

Starting simple. . . 1D range searching

find the point in the middle alternatively we could build a balanced tree. . . . . . and recurse on each half

slide-51
SLIDE 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)

slide-52
SLIDE 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)

slide-53
SLIDE 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)

slide-54
SLIDE 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)

slide-55
SLIDE 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)

slide-56
SLIDE 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

slide-57
SLIDE 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)

slide-58
SLIDE 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)

slide-59
SLIDE 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)

slide-60
SLIDE 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)

slide-61
SLIDE 61

Starting simple. . . 1D range searching

how do we do a lookup?

slide-62
SLIDE 62

Starting simple. . . 1D range searching

x1 x2

how do we do a lookup?

slide-63
SLIDE 63

Starting simple. . . 1D range searching

x1 x2

Step 1: find the successor of x1 how do we do a lookup?

slide-64
SLIDE 64

Starting simple. . . 1D range searching

x1 x2

Step 1: find the successor of x1 how do we do a lookup?

slide-65
SLIDE 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

slide-66
SLIDE 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

slide-67
SLIDE 67

Starting simple. . . 1D range searching

x1 x2

Step 1: find the successor of x1 how do we do a lookup?

slide-68
SLIDE 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?

slide-69
SLIDE 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?

slide-70
SLIDE 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?

slide-71
SLIDE 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?

slide-72
SLIDE 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?

slide-73
SLIDE 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

slide-74
SLIDE 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?

slide-75
SLIDE 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?

slide-76
SLIDE 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

slide-77
SLIDE 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

  • ff-path edge
slide-78
SLIDE 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”

  • ff-path edge
slide-79
SLIDE 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”

  • ff-path edge
slide-80
SLIDE 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”

  • ff-path edge
slide-81
SLIDE 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”

  • ff-path edge
slide-82
SLIDE 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”

  • ff-path edge
  • ff-path edge
slide-83
SLIDE 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”

  • ff-path edge
  • ff-path edge
slide-84
SLIDE 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”

  • ff-path edge
  • ff-path edge
slide-85
SLIDE 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”

  • ff-path edge
slide-86
SLIDE 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”

  • ff-path edge
slide-87
SLIDE 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”

  • ff-path edge
slide-88
SLIDE 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”

  • ff-path edge
slide-89
SLIDE 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”

  • ff-path edge
slide-90
SLIDE 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”

  • ff-path edge
slide-91
SLIDE 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”

  • ff-path edge
slide-92
SLIDE 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”

  • ff-path edge
slide-93
SLIDE 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

  • ff-path edge
slide-94
SLIDE 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

  • ff-path edge
slide-95
SLIDE 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

  • ff-path edge
slide-96
SLIDE 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

  • ff-path edge
slide-97
SLIDE 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?

  • ff-path edge
slide-98
SLIDE 98

Subtree decomposition

root split

x1 x2

Warning: the root to split path isn’t to scale

  • ff-path edge
  • ff-path subtree

too small too big

slide-99
SLIDE 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. . .

  • ff-path edge
  • ff-path subtree

too small too big

slide-100
SLIDE 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

  • ff-path edge
  • ff-path subtree

too small too big

slide-101
SLIDE 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

  • ff-path edge
  • ff-path subtree

too small too big

slide-102
SLIDE 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

  • ff-path edge
  • ff-path subtree

too small too big

this will be useful for 2D range searching

slide-103
SLIDE 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

slide-104
SLIDE 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

slide-105
SLIDE 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:

slide-106
SLIDE 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
slide-107
SLIDE 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
slide-108
SLIDE 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
slide-109
SLIDE 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
slide-110
SLIDE 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
slide-111
SLIDE 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
slide-112
SLIDE 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
slide-113
SLIDE 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?

slide-114
SLIDE 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)

slide-115
SLIDE 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)

slide-116
SLIDE 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)

slide-117
SLIDE 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)

???

slide-118
SLIDE 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)

???

slide-119
SLIDE 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)

slide-120
SLIDE 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

slide-121
SLIDE 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

slide-122
SLIDE 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?

slide-123
SLIDE 123

Subtree decomposition in 2D

root split

x1 x2

Warning: the root to split path isn’t to scale

  • ff-path edge
  • ff-path subtree

x too small x too big

(during preprocessing) build a balanced binary tree using the x-coordinates

slide-124
SLIDE 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

  • ff-path edge
  • ff-path subtree

x too small x too big

(during preprocessing) build a balanced binary tree using the x-coordinates

slide-125
SLIDE 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

  • ff-path edge
  • ff-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

slide-126
SLIDE 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

  • ff-path edge
  • ff-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

slide-127
SLIDE 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

slide-128
SLIDE 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)

slide-129
SLIDE 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?

slide-130
SLIDE 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)

  • n the y-coordinates of the points in the subtree
slide-131
SLIDE 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)

  • n the y-coordinates of the points in the subtree

a 1D lookup takes O(log n + k′) time

k′

slide-132
SLIDE 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)

  • n 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

slide-133
SLIDE 133

Subtree decomposition in 2D

Query summary

x1 x2

slide-134
SLIDE 134

Subtree decomposition in 2D

Query summary

  • 1. Follow the paths to x1 and x2

x1 x2

slide-135
SLIDE 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

slide-136
SLIDE 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

slide-137
SLIDE 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

slide-138
SLIDE 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

slide-139
SLIDE 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

slide-140
SLIDE 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

slide-141
SLIDE 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

slide-142
SLIDE 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

slide-143
SLIDE 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

slide-144
SLIDE 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

slide-145
SLIDE 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

slide-146
SLIDE 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

slide-147
SLIDE 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

slide-148
SLIDE 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

slide-149
SLIDE 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

slide-150
SLIDE 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

slide-151
SLIDE 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

slide-152
SLIDE 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

slide-153
SLIDE 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

slide-154
SLIDE 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

slide-155
SLIDE 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

slide-156
SLIDE 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). . .

slide-157
SLIDE 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)

slide-158
SLIDE 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

slide-159
SLIDE 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

slide-160
SLIDE 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)

slide-161
SLIDE 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

slide-162
SLIDE 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 :)

slide-163
SLIDE 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)

slide-164
SLIDE 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

slide-165
SLIDE 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)

slide-166
SLIDE 166

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 67

The arrays of points at the children partition the array of the parent

slide-167
SLIDE 167

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 67

The arrays of points at the children partition the array of the parent

slide-168
SLIDE 168

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 67

The arrays of points at the children partition the array of the parent

slide-169
SLIDE 169

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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)

slide-170
SLIDE 170

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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. . .

slide-171
SLIDE 171

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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. . .

slide-172
SLIDE 172

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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. . .

slide-173
SLIDE 173

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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)

slide-174
SLIDE 174

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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)

slide-175
SLIDE 175

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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)

slide-176
SLIDE 176

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 67

slide-177
SLIDE 177

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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

slide-178
SLIDE 178

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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

slide-179
SLIDE 179

Improving the query time

7 3 7 11 19 23 27 35 43 53 61 67 3 11 19 23 27 35 43 53 61 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

slide-180
SLIDE 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?

slide-181
SLIDE 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)

slide-182
SLIDE 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

slide-183
SLIDE 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,

slide-184
SLIDE 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. . .

slide-185
SLIDE 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

slide-186
SLIDE 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)

slide-187
SLIDE 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