ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST...

135
ONE DIMENSIONAL RANGE SEARCH

Transcript of ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST...

Page 1: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

O N E D I M E N S I O N A L R A N G E S E A R C H

Page 2: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

2

1d range search

Extension of ordered Binary Search Tree.

・Insert key-value pair.

・Search for key k.

・Delete key k.

・Range search: find all keys between k1 and k2.

・Range count: number of keys between k1 and k2.

Application. Database queries.

Geometric interpretation.

・Keys are point on a line.

・Find/count points in a given 1d interval.

insert B B

insert D B D

insert A A B D

insert I A B D I

insert H A B D H I

insert F A B D F H I

insert P A B D F H I P

search G to K H I

count G to K 2

Page 3: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

3

1d range search: elementary implementations

Unordered list. Fast insert, slow range search.

Ordered array. Slow insert, binary search for k1 and k2 to do range search.

data structure insert range count range search

unordered list 1 N N

ordered array N log N R + log N

goal log N log N R + log N

order of growth of running time for 1d range search

N = number of keys

R = number of keys that match

Page 4: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

L E T ’ S F O C U S O N R A N G E C O U N T I N G・Range count: number of keys between k1 and k2.

Page 5: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range count: BST implementation

Calculate the rank each node in the BST

5

・The Rank of a Node: is number of keys that are less than it

・Question: How do we determine the number of keys between k1 and k2

・Step1: Figure how many items less than k1

AC

E

HM

R

SX0

2

6

7

4

1

5

3

rank

・Step2: Subtract the rank(k2) from rank(k1)

Page 6: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

H O W W O U L D W E D O S E A R C H

・Range search: find all keys between k1 and k2.

Page 7: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range search. Find all keys between lo and hi.

・Recursively find all keys in left subtree (if any could fall in range).

・Check key in current node.

・Recursively find all keys in right subtree (if any could fall in range).

Proposition. Running time proportional to R + log N.Pf. Nodes examined = search path to lo + search path to hi + matches.

7

1d range search: BST implementation

black keys arein the range

red keys are used in comparesbut are not in the range

AC

E

H

LM

P

R

SX

searching in the range [F..T]

Range search in a BST

Page 8: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range search: BST implementation

8

black keys arein the range

red keys are used in comparesbut are not in the range

AC

E

H

LM

P

R

SX

searching in the range [F..T]

Range search in a BST

1d range search. Find all keys between lo and hi.

・Recursively find all keys in left subtree (if any could fall in range).

・Check key in current node.

・Recursively find all keys in right subtree (if any could fall in rang

Start at root S

Page 9: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range search: BST implementation

9

black keys arein the range

red keys are used in comparesbut are not in the range

AC

E

H

LM

P

R

SX

searching in the range [F..T]

Range search in a BST

1d range search. Find all keys between lo and hi.

・Recursively find all keys in left subtree (if any could fall in range).

・Check key in current node.

・Recursively find all keys in right subtree (if any could fall in rang

Start at root S

Check E 1) E is not the range 2) is less than smallest key F 3)Only need to recurse right

Page 10: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range search: BST implementation

10

black keys arein the range

red keys are used in comparesbut are not in the range

AC

E

H

LM

P

R

SX

searching in the range [F..T]

Range search in a BST

1d range search. Find all keys between lo and hi.

・Recursively find all keys in left subtree (if any could fall in range).

・Check key in current node.

・Recursively find all keys in right subtree (if any could fall in rang

Start at root S

Check R 1) R is range [F … T] 2) Recurse left

Page 11: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range search: BST implementation

11

black keys arein the range

red keys are used in comparesbut are not in the range

AC

E

H

LM

P

R

SX

searching in the range [F..T]

Range search in a BST

1d range search. Find all keys between lo and hi.

・Recursively find all keys in left subtree (if any could fall in range).

・Check key in current node.

・Recursively find all keys in right subtree (if any could fall in rang

Start at root S

Check H 1) H is range [F … T] 2) Recurse left (null) 3) Recurse right

Same process for M, L, P

Page 12: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

1d range search: BST implementation

12

black keys arein the range

red keys are used in comparesbut are not in the range

AC

E

H

LM

P

R

SX

searching in the range [F..T]

Range search in a BST

1d range search. Find all keys between lo and hi.

・Recursively find all keys in left subtree (if any could fall in range).

・Check key in current node.

・Recursively find all keys in right subtree (if any could fall in rang

Start at root S

Check X 1) X is not range [F … T] 2) end recursion

Page 13: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

L E T S E X T E N D T H I S I D E A T O T H E 2 D C A S E

Page 14: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

14

Orthogonal line segment intersection

Given N horizontal and vertical line segments, find all intersections.

Quadratic algorithm. Check all pairs of line segments for intersection.

Nondegeneracy assumption. All x- and y-coordinates are distinct.

・Remove all the lines that touch with intersecting.

Page 15: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Sweep vertical line from left to right.

・x-coordinates define events.

・h-segment (left endpoint): insert y-coordinate into BST.

15

Orthogonal line segment intersection: sweep-line algorithm

y-coordinates

0

1

2

3

0

1

3

2

4

Page 16: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Sweep vertical line from left to right.

・x-coordinates define events.

・h-segment (left endpoint): insert y-coordinate into BST.

・h-segment (right endpoint): remove y-coordinate from BST.

16

Orthogonal line segment intersection: sweep-line algorithm

y-coordinates

0

1

2

3

4

0

1

3

Page 17: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Sweep vertical line from left to right.

・x-coordinates define events.

・h-segment (left endpoint): insert y-coordinate into BST.

・h-segment (right endpoint): remove y-coordinate from BST.

・v-segment: range search for interval of y-endpoints.

17

Orthogonal line segment intersection: sweep-line algorithm

1d rangesearch

y-coordinates

0

1

2

3

4

0

1

3

Page 18: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

18

Orthogonal line segment intersection: sweep-line analysis

Proposition. The sweep-line algorithm takes time proportional to N log N + R

to find all R intersections among N orthogonal line segments.

Pf.

・Put x-coordinates on a PQ (or sort).

・Insert y-coordinates into BST.

・Delete y-coordinates from BST.

・Range searches in BST.

Bottom line. Sweep line reduces 2d orthogonal line segment intersection

search to 1d range search.

N log N

N log N

N log N

N log N + R

Page 19: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

L E T S E X T E N D T H E A L G O R I T H M T O 2 D S PA C E

Page 20: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

20

2-d orthogonal range search

Extension to 2d keys.

・Insert a 2d key. (Points)

・Delete a 2d key.

・Search for a 2d key.

・Range search: find all keys that lie in a 2d range.

・Range count: number of keys that lie in a 2d range.

Geometric interpretation.

・Keys are point in the plane.

・Find/count points in a given rectangle

Page 21: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

21

2d orthogonal range search: grid implementation

Grid implementation.

・Divide space into M-by-M grid of squares.

・Create list of points contained in each square.

・Use 2d array to directly index relevant square.

・Insert: add (x, y) to list for corresponding square.

・Range search: examine only squares that intersect 2d range query.

LB

RT

RT = Right Top LB = Left Bottom

・M-by-M grid

Cell ID 1 2 MxMPoint ID 5 6 7

Page 22: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

22

2d orthogonal range search: grid implementation analysis

Choose grid square size to tune performance.

・Too small: wastes space.

– (Searching square that don’t contain anything)

・Too large: too many points per square.

– (Can’t distinguish between points)

LB

RT

Page 23: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

H O W E V E R , P O I N T S A R E A LW AY S E V E N I N G D I S T R I B U T E D

Page 24: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Grid implementation. Fast, simple solution for evenly-distributed points.

Problem. Clustering a well-known phenomenon in geometric data.

Ex. USA map data.

24

Clustering

half the squares are empty half the points arein 10% of the squares

13,000 points, 1000 grid squares

Page 25: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Grid implementation. Fast, simple solution for evenly-distributed points.

Problem. Clustering a well-known phenomenon in geometric data.

・Need data structure that adapts gracefully to data.

25

Clustering

Page 26: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

N E E D PA R T I T I O N I N G A P P R O A C H T H AT F I T S T H E D I S T R I B U T I O N O F T H E D ATA

Page 27: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Use a tree to represent a recursive subdivision of 2d space.

Grid. Divide space uniformly into squares.

2d tree. Recursively divide space into two halfplanes.

27

Space-partitioning trees

Grid 2d tree

Page 28: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

C O N S T R U C T I N G A 2 D T R E E

Page 29: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Recursively partition plane into two halfplanes.

29

2d tree construction

1

2

3

4

6

7

8

9

10

5

1

2

87

10 9

3

4 6

5

Alternative between And at each level in the tree

Page 30: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Data structure. BST, but alternate using x- and y-coordinates as key.

・Search gives rectangle containing point.

・Insert further subdivides the plane.

30

2d tree implementation

even levelsof the tree

p

pointsleft of p

pointsright of p

p

q

pointsbelow q

pointsabove q

odd levelsof the tree

q

1

2

87

1 9

3

4 6

5

1 2

3

4

6

7

8

9

10

5

Page 31: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

S O W H AT A B O U T R A N G E S E A R C H

Page 32: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left (if any points could fall in rectangle).

・Recursively search right (if any points could fall in rectangle).

32

2d tree demo: range search

1

2

3

4

6

7

8

9

10

5

1

2

87

10 9

3

4 6

5

Page 33: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

33

2d tree demo: range search

2

3

4

6

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

search root nodecheck if query rectangle contains point 1

Page 34: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

34

2d tree demo: range search

2

3

4

6

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

query rectangle to left of splitting linesearch only in left subtree

Page 35: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

35

2d tree demo: range search

2

4

6

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

3

search left subtreecheck if query rectangle contains point 3

Page 36: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

36

2d tree demo: range search

2

3

4

6

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

query rectangle intersects splitting linesearch bottom and top subtrees

Page 37: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

37

2d tree demo: range search

2

3

4

6

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

search left subtreecheck if query rectangle contains point 4

Page 38: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

38

2d tree demo: range search

2

3

6

7

8

9

10

5

2

87

10 9

3

6

5

1

1

4

4

query rectangle to left of splitting linesearch only in left subtree

Page 39: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

39

2d tree demo: range search

2

3

6

7

8

9

10

5

2

87

10 9

3

6

5

1

1

4

4

search left subtreecheck if query rectangle contains point 5

(search hit)

Page 40: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

40

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

query rectangle intersects splitting linesearch bottom and top subtrees

Page 41: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

41

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

search bottom subtreestop since empty

Page 42: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

42

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

search top subtreestop since empty

Page 43: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

43

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

return from function call

Page 44: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

44

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

return from function call

Page 45: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

45

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

return from function call

Page 46: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

46

2d tree demo: range search

2

3

6

7

8

9

10

2

87

10 9

3

6

1

1

4

4

5 5

search top subtreecheck if query rectangle contains point 6

Page 47: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

47

2d tree demo: range search

2

3

7

8

9

10

2

87

10 9

3

1

1

4

4

5 5

6

6

query rectangle to left of splitting linesearch only in left subtree

Page 48: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

48

2d tree demo: range search

2

3

7

8

9

10

2

87

10 9

3

1

1

4

4

5 5

6

6

search left subtreestop since empty

Page 49: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

49

2d tree demo: range search

2

3

7

8

9

10

2

87

10 9

3

1

1

4

4

5 5

6

return from function call

6

Page 50: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

50

2d tree demo: range search

2

3

7

8

9

10

2

87

10 9

3

1

1

4

4

5 5

6

6

return from function call

Page 51: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

51

2d tree demo: range search

2

3

7

8

9

10

2

87

10 9

3

1

1

4

4

5 5

6

6

return from function call

Page 52: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find all points in a query axis-aligned rectangle.

・Check if point in node lies in given rectangle.

・Recursively search left/bottom (if any could fall in rectangle).

・Recursively search right/top (if any could fall in rectangle).

52

2d tree demo: range search

2

3

7

8

9

10

2

87

10 9

3

1

1

4

4

5 5

6

6

done

Page 53: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

N E A R E S T N E I G H B O R

Page 54: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Goal. Find closest point to query point.

54

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

1

2

87

10 9

3

4 6

5

query point

1

6

Page 55: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

55

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search root nodecompute distance from query point to 1

(update champion nearest neighbor)

1

6

Page 56: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

56

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

query point is to the left of splitting linesearch left subtree first

6

Page 57: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

57

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

3

search left subtreecompute distance from query point to 3

(update champion)

1

6

Page 58: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

58

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

query point is above splitting linesearch top subtree first

1

6

Page 59: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

59

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search top subtreecompute distance from query point to 6

6

1

Page 60: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

60

2d tree demo: nearest neighbor

2

3

4

6

7

8

9

10

5

2

87

10 9

3

4 6

5

1

query point is to left of splitting linesearch left subtree first

1

Page 61: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

61

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search left subtreereturn since empty

1

6

Page 62: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

62

2d tree demo: nearest neighbor

2

3

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search right subtreeprune since nearest neighbor

can't be here

1

6

Page 63: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

63

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

return from function callsearch bottom subtree next

1

3

6

Page 64: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

64

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search bottom subtreecompute distance from query point to 4

1

3

6

Page 65: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

65

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

query point is to left of splitting linesearch left subtree first

1

3

6

Page 66: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

66

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search left subtreecompute distance from query point to 5

(update champion)

1

3

6

Page 67: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

67

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

query point is above splitting linesearch top subtree first

1

3

6

Page 68: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

68

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search top subtreereturn since empty

1

3

6

Page 69: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

69

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search bottom subtreereturn since empty

1

3

6

Page 70: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

70

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

return from function callsearch right subtree next

1

3

6

Page 71: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

71

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search right subtreeprune since nearest neighbor

can't be here(drawing not quite to scale)

1

3

6

Distancelarger

Page 72: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

72

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

return from function call

1

3

6

Page 73: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

73

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

return from function callsearch right subtree next

1

3

6

Page 74: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

74

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

search right subtreeprune since nearest neighbor

can't be here

1

3

6

Page 75: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

・Check distance from point in node to query point.

・Recursively search left/bottom (if it could contain a closer point).

・Recursively search right/top (if it could contain a closer point).

75

2d tree demo: nearest neighbor

2

4

7

8

9

10

5

2

87

10 9

3

4 6

5

1

1

3

6

nearest neighbor = 5

Page 76: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

76

Flocking birds

Q. What "natural algorithm" do starlings, migrating geese, starlings,

cranes, bait balls of fish, and flashing fireflies use to flock?

http://www.youtube.com/watch?v=XH-groCeKbE

Page 77: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

77

Flocking boids [Craig Reynolds, 1986]

Boids. Three simple rules lead to complex emergent flocking behavior:

・Collision avoidance: point away from k nearest boids.

・Flock centering: point towards the center of mass of k nearest boids.

・Velocity matching: update velocity to the average of k nearest boids.

https://www.youtube.com/watch?v=SJyRkeq4Mgw

Page 78: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

K - D T R E E K D I M E N S I O N S

Page 79: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

79

Kd tree

Kd tree. Recursively partition k-dimensional space into 2 halfspaces.

・Just cycle through each dimension at each level of there tree

Implementation. BST, but cycle through dimensions ala 2d trees.

Efficient, simple data structure for processing k-dimensional data.

・Widely used.

・Adapts well to high-dimensional and clustered data.

level ≡ i (mod k)

points

whose ithcoordinate

is less than p’s

points

whose ithcoordinate

is greater than p’s

p

Jon Bentley

Page 80: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

I N T E R VA L S E A R C H T R E E S

Page 81: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

81

1d interval search. Data structure to hold set of (overlapping) intervals.

・Insert an interval ( lo, hi ).

・Search for an interval ( lo, hi ).

・Delete an interval ( lo, hi ).

・Interval intersection query: given an interval ( lo, hi ), find all intervals

(or one interval) in data structure that intersects ( lo, hi ). Q. Which intervals intersect ( 9, 16 ) ? A. ( 7, 10 ) and ( 15, 18 ).

1d interval search

(7, 10)

(5, 8)

(4, 8) (15, 18)

(17, 19)

(21, 24)

Page 82: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Create BST, where each node stores an interval ( lo, hi ).

・Use left endpoint as BST key.

・Store max endpoint in subtree rooted at node.

82

Interval search trees

binary search tree (left endpoint is key)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

max endpoint insubtree rooted at node

24

18

8 18

10

24

Page 83: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

83

Interval search tree demo: insertion

insert interval (16, 22)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

18

8 18

10

24

Page 84: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

84

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

24

18

8 18

10

24

Page 85: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

85

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

compare 16 and 17 (go left)

(16, 22)

insert interval (16, 22)

24

18

8 18

10

24

Page 86: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

86

Interval search tree demo: insertion

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

(16, 22)

insert interval (16, 22)

24

18

8 18

10

24

(17, 19)

Page 87: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

87

Interval search tree demo: insertion

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

(16, 22)

compare 16 and 5 (go right)

insert interval (16, 22)

24

18

8 18

10

24(5, 8)

Page 88: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

88

Interval search tree demo: insertion

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

(16, 22)

24

18

8 18

10

24(5, 8)

Page 89: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

89

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

(16, 22)

insert interval (16, 22)

compare 16 and 15 (go right)

24

18

8 18

10

24

(15, 18)

Page 90: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

90

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

insert interval (16, 22)

24

18

8 18

10

24

(15, 18)

(16, 22)

Page 91: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

91

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

(16, 22) no more tree (insert here)

24

18

8 18

10

24

Page 92: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

92

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

no more tree (insert here)

24

18

8 18

10

24

(16, 22)(16, 22)

Page 93: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

93

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

update max in each node on search path

24

18

8 18

10

24

(16, 22)(16, 22)

Page 94: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

94

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

update max in each node on search path

24

18

8 18

10

24

22

22

22(16, 22)(16, 22)

Page 95: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

To insert an interval ( lo, hi ) :

・Insert into BST, using lo as the key.

・Update max in each node on search path.

95

Interval search tree demo: insertion

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

insert interval (16, 22)

24

22

8 22

10

24

22(16, 22)

Page 96: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

I N T E R VA L S E A R C H

Page 97: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

97

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (23, 25)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

Page 98: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

98

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (23, 25)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

compare (23, 25) to (17, 19) (no intersection)

(23, 25) (17, 19)

Page 99: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

99

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (23, 25)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

compare 22 to 23 (no intersection in left, go right)

(23, 25) (17, 19)

Page 100: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

100

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (23, 25)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(23, 25)

(17, 19)

Page 101: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

101

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (23, 25)

(17, 19)

(5, 8)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(23, 25)

compare (23, 25) to (21, 24) (intersection!)

(21, 24)

Page 102: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

102

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

Page 103: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

103

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14)

compare (12, 14) to (17, 19) (no intersection)

(17, 19)

Page 104: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

104

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14)

compare 22 to 12 (go left)

(17, 19)

Page 105: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

105

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14)

(17, 19)

Page 106: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

106

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14)

compare (12, 14) to (5, 8) (no intersection)

(5, 8)

Page 107: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

107

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14)

compare 8 to 12 (go right)

(5, 8)

Page 108: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

108

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14)

(5, 8)

Page 109: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

109

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14) compare (12, 14) to (15, 18) (no intersection)

(15, 18)

Page 110: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

110

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(12, 14) compare 10 to 12 (go right)

(15, 18)

Page 111: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

111

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

24

22

8 22

10

24

22(16, 22) (12, 14)

(15, 18)

Page 112: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

112

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22 (12, 14)(16, 22)

Page 113: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

113

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22 (12, 14)

compare (12, 14) to (16, 22) (no intersection)

(16, 22)

Page 114: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

114

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22 (12, 14)

left subtree is null (go right)

(16, 22)

Page 115: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

115

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (12, 14)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22

node is null (no intersection)

(16, 22)

Page 116: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

116

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

interval intersectionsearch for (21, 23)

Page 117: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

117

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23)

compare (21, 23) to (17, 19) (no intersection)

interval intersectionsearch for (21, 23)

(17, 19)

Page 118: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

118

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23)

compare 22 to 21 (go left)

interval intersectionsearch for (21, 23)

(17, 19)

Page 119: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

119

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23)

interval intersectionsearch for (21, 23)

(17, 19)

Page 120: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

120

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23)

compare (21, 23) to (5, 8) (no intersection)

interval intersectionsearch for (21, 23)

(5, 8)

Page 121: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

121

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23)

compare 8 to 21 (go right)

interval intersectionsearch for (21, 23)

(5, 8)

Page 122: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

122

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(17, 19)

(21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23)

interval intersectionsearch for (21, 23)

(5, 8)

Page 123: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

123

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23) compare (21, 23) to (15, 18) (no intersection)

interval intersectionsearch for (21, 23)

(15, 18)

Page 124: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

124

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (21, 23)

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

24

22

8 22

10

24

22(16, 22)

(21, 23) compare 10 to 21 (go right)

(15, 18)

Page 125: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

125

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (21, 23)

(17, 19)

(5, 8) (21, 24)

(4, 8)

(7, 10)

24

22

8 22

10

24

22(16, 22) (21, 23)

(15, 18)

Page 126: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

126

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (21, 23)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22 (21, 23)(16, 22)

Page 127: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

127

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (21, 23)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22 (21, 23)

compare (21, 23) to (16, 22) (intersection!)

(16, 22)

Page 128: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

128

Interval search tree demo: intersection

To search for any one interval that intersects query interval ( lo, hi ) :

・If interval in node intersects query interval, return it.

・Else if left subtree is null, go right.

・Else if max endpoint in left subtree is less than lo, go right.

・Else go left.

interval intersectionsearch for (21, 23)

(17, 19)

(5, 8) (21, 24)

(4, 8) (15, 18)

(7, 10)

24

22

8 22

10

24

22 (21, 23)

compare (21, 23) to (16, 22) (intersection!)

(16, 22)

Page 129: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

129

Orthogonal rectangle intersection

Goal. Find all intersections among a set of N orthogonal rectangles.

Quadratic algorithm. Check all pairs of rectangles for intersection.

Non-degeneracy assumption. All x- and y-coordinates are distinct.

0

1

2

3

Page 130: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

I N T E R S E C T I O N R E C TA N G L E S

Page 131: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

131

Microprocessors and geometry

Early 1970s. microprocessor design became a geometric problem.

・Very Large Scale Integration (VLSI).

・Computer-Aided Design (CAD).

Design-rule checking.

・Certain wires cannot intersect.

・Certain spacing needed between different types of wires.

・Debugging = orthogonal rectangle intersection search.

Page 132: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

Sweep vertical line from left to right.

・x-coordinates of left and right endpoints define events.

・Maintain set of rectangles that intersect the sweep line in an interval

search tree (using y-intervals of rectangle).

・Left endpoint: interval search for y-interval of rectangle; insert y-interval.

・Right endpoint: remove y-interval.

132

Orthogonal rectangle intersection: sweep-line algorithm

y-coordinates

0

1

2

3

0

1

23

Page 133: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

133

Orthogonal rectangle intersection: sweep-line analysis

Proposition. Sweep line algorithm takes time proportional to N log N + R log Nto find R intersections among a set of N rectangles.

Pf.

・Put x-coordinates on a PQ (or sort).

・Insert y-intervals into ST.

・Delete y-intervals from ST.

・Interval searches for y-intervals.

Bottom line. Sweep line reduces 2d orthogonal rectangle intersection

search to 1d interval search.

N log N

N log N

N log N

N log N + R log N

Page 134: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

problem example solution

1d range search BST

2d orthogonal linesegment intersection

sweep line reduces to 1d range search

kd range search kd tree

1d interval search interval search tree

2d orthogonalrectangle intersection

sweep line reduces to 1d interval search

Geometric applications of BSTs

134

Page 135: ONE DIMENSIONAL RANGE SEARCH - Daniel G. Graham PhD · 2019. 2. 13. · 1d range search: BST implementation 8 black keys are in the range red keys are used in compares but are not

http://algs4.cs.princeton.edu

Algorithms ROBERT SEDGEWICK | KEVIN WAYNE

ROBERT SEDGEWICK | KEVIN WAYNE

F O U R T H E D I T I O N

Algorithms

GEOMETRIC APPLICATIONS OF

‣ 1d range search‣ line segment intersection‣ kd trees‣ interval search trees‣ rectangle intersection