Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company...

211
1 Computational Geometry Lecture #5 Orthogonal Range Queries or Fast Access to Data Bases Dr. Philipp Kindermann Winter Semester 2018/19

Transcript of Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company...

Page 1: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

1

Computational Geometry

Lecture #5

Orthogonal Range Queriesor

Fast Access to Data Bases

Dr. Philipp Kindermann Winter Semester 2018/19

Page 2: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 1

Orthogonal Range QueriesExample: Personnel management in a company

2.000

3.000e

19.559.99919.500.000

1.000

Page 3: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 2

Orthogonal Range QueriesExample: Personnel management in a company

2.000

3.000e

19.559.99919.500.000

G. Ometerborn:salary: 2.500e

1.000

1953-08-20

Page 4: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 3

Orthogonal Range QueriesExample: Personnel management in a company

2.000

3.000e

19.559.99919.500.000

G. Ometerborn:salary: 2.500e

1.000

1953-08-20

Page 5: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 4

Orthogonal Range QueriesExample: Personnel management in a company

2.000

3.000e

19.559.99919.500.000

G. Ometerborn:salary: 2.500e

1.000

1953-08-20

Page 6: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 5

Orthogonal Range QueriesExample: Personnel management in a company

2.000

3.000e

19.559.99919.500.000

G. Ometerborn:salary: 2.500e

1.000

1953-08-20

Page 7: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 6

Orthogonal Range QueriesExample: Personnel management in a company

19,500,000 19,559,999

3,000

4,000

2

4

e

Page 8: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

2 - 7

Orthogonal Range QueriesExample: Personnel management in a company

19,500,000 19,559,999

3,000

4,000

2

4

Typical queries for data bases!

e

Page 9: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 1

1D Range SearchingTask: Preprocess a finite set P ⊂ R such that for any

interval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 10: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 2

1D Range Searching

Solution:

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 11: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 3

1D Range Searching

Solution: balanced binary search trees. . .

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 12: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 4

1D Range Searching

Solution: balanced binary search trees. . .

4 8 11 13 17 21 27

Small changes: – keys only in leaves

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 13: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 5

1D Range Searching

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 14: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 6

1D Range Searching

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 15: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 7

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 16: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 8

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

1. Search x = 6.

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 17: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 9

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

1. Search x = 6.

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 18: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 10

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

1. Search x = 6.

2. Search x′ = 21.

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 19: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 11

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

1. Search x = 6.

2. Search x′ = 21.

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 20: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 12

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

vsplit1. Search x = 6.

2. Search x′ = 21.

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 21: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

3 - 13

1D Range Searching

6 21

Solution: balanced binary search trees. . .

11

4 8 11 13 17 21 27

4 17

8 13 21

Small changes: – keys only in leaves– inner nodes store max. of their left subtrees

27

query

Returnall leaves‘inbetween”.

3.

vsplit1. Search x = 6.

2. Search x′ = 21.

Task: Preprocess a finite set P ⊂ R such that for anyinterval [x, x′] the set P ∩ [x, x′] can be reportedquickly. [2 min]

Page 22: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 1

1D Range Searching11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 23: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 2

1D Range Searching11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 24: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 3

1D Range Searching

Observe: The result of a query is the disjoint union of at most 2hcanonical subsets

11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 25: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 4

1D Range Searching

Observe: The result of a query is the disjoint union of at most 2hcanonical subsets– h ∈ O(log n) is the tree height,

, where

11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 26: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 5

1D Range Searching

Observe: The result of a query is the disjoint union of at most 2hcanonical subsets– h ∈ O(log n) is the tree height,– a canonical subset is an interval that contains all points

stored in a subtree.

, where

11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 27: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 6

1D Range Searching

Observe: The result of a query is the disjoint union of at most 2hcanonical subsets– h ∈ O(log n) is the tree height,– a canonical subset is an interval that contains all points

stored in a subtree.

, where

Theorem. A set of n real numbers can be preprocessed in O(n log n)time and O(n) space such that 1D range queries take

time.

11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 28: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 7

1D Range Searching

Observe: The result of a query is the disjoint union of at most 2hcanonical subsets– h ∈ O(log n) is the tree height,– a canonical subset is an interval that contains all points

stored in a subtree.

, where

Theorem. A set of n real numbers can be preprocessed in O(n log n)time and O(n) space such that 1D range queries take

time.O(k + log n) , where k = |output|.

11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

Page 29: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

4 - 8

1D Range Searching

Observe: The result of a query is the disjoint union of at most 2hcanonical subsets– h ∈ O(log n) is the tree height,– a canonical subset is an interval that contains all points

stored in a subtree.

, where

Theorem. A set of n real numbers can be preprocessed in O(n log n)time and O(n) space such that 1D range queries take

time.O(k + log n) , where k = |output|.

11

4 8 11 13 17 21 27

4 17

8 13 21

27

vsplit

outputsensitive!

Page 30: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 1

Extensions to 2DThink... [3 min]

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Page 31: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 2

Extensions to 2DThink... [3 min]

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

Page 32: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 3

Extensions to 2DThink... [3 min]

• one tree;query path alternates between x- and y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

Page 33: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 4

Extensions to 2DThink... [3 min]

• one tree;query path alternates between x- and y-coord.

• first-level tree for x-coordinates;many second-level trees for y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

Page 34: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 5

Extensions to 2DThink... [3 min]

• one tree;query path alternates between x- and y-coord.

• first-level tree for x-coordinates;many second-level trees for y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

kd-tree

range tree

}}

Page 35: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 6

Extensions to 2DThink... [3 min]

• one tree;query path alternates between x- and y-coord.

• first-level tree for x-coordinates;many second-level trees for y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

kd-tree

range tree

}}

Assume: General position!

Page 36: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 7

Extensions to 2DThink... [3 min]

• one tree;query path alternates between x- and y-coord.

• first-level tree for x-coordinates;many second-level trees for y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

kd-tree

range tree

}}

Assume: General position!Here: no two points have the same x- or y-coordinate.

Page 37: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

5 - 8

Extensions to 2DThink... [3 min]

• one tree;query path alternates between x- and y-coord.

• first-level tree for x-coordinates;many second-level trees for y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

kd-tree

range tree

}}

Assume: General position!Here: no two points have the same x- or y-coordinate.

Page 38: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 1

Kd-Trees: Example

p4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Page 39: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 2

Kd-Trees: Example

p

`1

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Page 40: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 3

Kd-Trees: Example

p

`1 `1

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 41: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 4

Kd-Trees: Example

p

`1

`2

`1

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 42: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 5

Kd-Trees: Example

p

`1

`2

`1

`24

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 43: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 6

Kd-Trees: Example

p

`1

`2

`4

`1

`24

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 44: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 7

Kd-Trees: Example

p

`1

`2

`4

`1

`2

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 45: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 8

Kd-Trees: Example

p

`1

`2

`8

`4

`1

`2

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 46: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 9

Kd-Trees: Example

p

`1

`2

`8

`4

`1

`2

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.

Page 47: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 10

Kd-Trees: Example

p

`1

`2

p1

`8

`4

`1

`2

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 48: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 11

Kd-Trees: Example

p

`1

`2

p1 p2

`8

`4

`1

`2

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 49: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 12

Kd-Trees: Example

p

`1

`2

p1 p2

p3

`8

`4

`1

`2

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 50: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 13

Kd-Trees: Example

p

`1`5

`2

p1 p2

p3

`8

`4

`1

`2

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 51: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 14

Kd-Trees: Example

p

`1`5

`2

p1 p2

p3

`8

`4

`1

`2

`5

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 52: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 15

Kd-Trees: Example

p

`1`5

`2

p1 p2

p3 p4

`8

`4

`1

`2

`5

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 53: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 16

Kd-Trees: Example

p

`1`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2

`5

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 54: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 17

Kd-Trees: Example

p

`1

`3

`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2

`5

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 55: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 18

Kd-Trees: Example

p

`1

`3

`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2 `3

`5

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 56: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 19

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2 `3

`5

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 57: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 20

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2 `3

`5 `6

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 58: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 21

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2 `3

`5 `6

`8

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 59: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 22

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

`8

`4

`1

`2 `3

`5 `6

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 60: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 23

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6

`8

`4

`1

`2 `3

`5 `6

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 61: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 24

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

`8

`4

`1

`2 `3

`5 `6

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 62: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 25

Kd-Trees: Example

p

`1

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

p8

`8

`4

`1

`2 `3

`5 `6

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 63: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 26

Kd-Trees: Example

p

`1`7

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

p8

`8

`4

`1

`2 `3

`5 `6

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 64: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 27

Kd-Trees: Example

p

`1`7

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

p8

`8

`4

`1

`2 `3

`5 `6 `7

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 65: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 28

Kd-Trees: Example

p

`1`7

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

p8 p9

`8

`4

`1

`2 `3

`5 `6 `7

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 66: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 29

Kd-Trees: Example

p

`1`7

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

p8 p9 p10

`8

`4

`1

`2 `3

`5 `6 `7

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 67: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

6 - 30

Kd-Trees: Example

p

`1`7

`3

`6

`5

`2

p1 p2

p3 p4 p5

p6 p7

p8 p9 p10

`8

`4

`1

`2 `3

`5 `6 `7

`8 `9

`4

4

p1

p5

p3

p2

p7

p9

p10

p6

p8

`9

[dBCvKO’08]

Vertical left.

• Split any region that contains more than one point.• Horizontal split lines/segm. belong to the region below.

Page 68: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 1

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

2

p

p

p

p

p

p

p

p

p

p

Page 69: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 2

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

2

p

p

p

p

p

p

p

p

p

p

Page 70: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 3

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)

2

p

p

p

p

p

p

p

p

p

p

Page 71: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 4

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

p

p

p

p

p

p

p

p

p

p

Page 72: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 5

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

p

p

p

p

p

p

p

p

p

p

Page 73: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 6

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

p

p

p

p

p

p

p

p

p

p

Page 74: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 7

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

`′ 2

p

p

p

p

p

p

p

p

p

p

Page 75: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 8

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

p

p

p

p

p

p

p

p

p

p

Page 76: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 9

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

vleft vright

p

p

p

p

p

p

p

p

p

p

Page 77: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 10

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

vleft vright

p

p

p

p

p

p

p

p

p

p

Page 78: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 11

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

vleft vright

v`

p

p

p

p

p

p

p

p

p

p

Page 79: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 12

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

vleft vright

v`

p

p

p

p

p

p

p

p

p

p

Page 80: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 13

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

vleft vright

v`

p

p

p

p

p

p

p

p

p

p

Page 81: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

7 - 14

Kd-Trees: Construction`

4

1

5

3

7

9

10

6

8

Pseudo-code:

BuildKdTree(points P, int depth)if |P| = 1 then

return (leaf storing the pt in P)else

if depth is even thensplit P with the vertical line` : x = xmedian(P) intoP1 (pts left of or on `) andP2 = P \ P1

elsesplit P horizontally...

vleft ← BuildKdTree(P1, depth + 1)vright ← BuildKdTree(P2, depth + 1)create a node v storing `make vleft and vright the children of vreturn (v)

2

vleft vright

v`

p

p

p

p

p

p

p

p

p

p

Page 82: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

8 - 1

Kd-Trees: AnalysisConstruction time?

Page 83: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

8 - 2

Kd-Trees: AnalysisConstruction time?

T(n) =

{O(1) if n = 1O(n) + 2T(dn/2e) else.

Page 84: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

8 - 3

Kd-Trees: AnalysisConstruction time?

T(n) =

{O(1) if n = 1O(n) + 2T(dn/2e) else.

}= O(n log n)

Page 85: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

8 - 4

Kd-Trees: AnalysisConstruction time?

T(n) =

{O(1) if n = 1O(n) + 2T(dn/2e) else.

}= O(n log n)

see Mergesort!

Page 86: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

8 - 5

Kd-Trees: AnalysisConstruction time?

T(n) =

{O(1) if n = 1O(n) + 2T(dn/2e) else.

}= O(n log n)

Lemma: A kd-tree for a set of n pts in the plane takesO(n log n) time to construct and usesO(n) storage.

see Mergesort!

Page 87: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

8 - 6

Kd-Trees: AnalysisConstruction time?

T(n) =

{O(1) if n = 1O(n) + 2T(dn/2e) else.

}= O(n log n)

Lemma: A kd-tree for a set of n pts in the plane takesO(n log n) time to construct and usesO(n) storage.

see Mergesort!

Page 88: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 1

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 89: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 2

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 90: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 3

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 91: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 4

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 92: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 5

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 93: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 6

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 94: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 7

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 95: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 8

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 96: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 9

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 97: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 10

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 98: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 11

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 99: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 12

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 100: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 13

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 101: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 14

Kd-Trees: Querying

p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 102: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 15

Kd-Trees: Querying

*p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Page 103: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 16

Kd-Trees: Querying

*p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Lemma. Querying a kd-tree for n pts in the plane withan axis-parallel rectangle R takes O(k +

√n )

time, where k = |output|.

Page 104: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 17

Kd-Trees: Querying

*p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Lemma. Querying a kd-tree for n pts in the plane withan axis-parallel rectangle R takes O(k +

√n )

time, where k = |output|.Idea: O(

√n) regions of the kd-tree

intersect a vertical/horizontal line.

Page 105: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 18

Kd-Trees: Querying

*p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Lemma. Querying a kd-tree for n pts in the plane withan axis-parallel rectangle R takes O(k +

√n )

time, where k = |output|. in Rd

Idea: O(√

n) regions of the kd-treeintersect a vertical/horizontal line.

Page 106: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

9 - 19

Kd-Trees: Querying

*p1 p2

p2

p1

p3

p3 p4

p4 p5

p5

p6

p6

p7

p7 p8

p8

p9

p9

p10

p10

p11

p11

p12

p12 p13

p13

Lemma. Querying a kd-tree for n pts in the plane withan axis-parallel rectangle R takes O(k +

√n )

time, where k = |output|.

O(k + n1−1/d)

in Rd

Idea: O(√

n) regions of the kd-treeintersect a vertical/horizontal line.

Page 107: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

10

Extensions to 2D

• one tree;query path alternates between x- and y-coord.

• first-level tree for x-coordinates;many second-level trees for y-coord.

Task: Preprocess a finite set P ⊂ R2 such that for anyrange query R = [x, x′]× [y, y′] the set P ∩ R canbe reported quickly.

Solutions:

kd-tree

range tree

}}

Assume: General position!Here: no two points have the same x- or y-coordinate.

Page 108: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 1

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

µ µ′

vsplit

Page 109: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 2

Range Trees: Query Algorithm1. Search in main tree for x-coordinate2. For each node u

on the path from vsplit to µ:

µ µ′

vsplit

Page 110: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 3

Range Trees: Query Algorithm1. Search in main tree for x-coordinate2. For each node u

on the path from vsplit to µ:

u

µ µ′

vsplit

Page 111: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 4

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

v

2. For each node uon the path from vsplit to µ:

For the right child v of u:

u

µ µ′

vsplit

Page 112: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 5

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

v

2. For each node uon the path from vsplit to µ:

For the right child v of u:

u

Search in auxiliary tree Tvfor points withy-coordinate ∈ [y, y′]

µ µ′

vsplit

Page 113: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 6

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

v

2. For each node uon the path from vsplit to µ:

For the right child v of u:

u

Search in auxiliary tree Tvfor points withy-coordinate ∈ [y, y′]

µ µ′

vsplit

Page 114: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 7

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

v

2. For each node uon the path from vsplit to µ:

For the right child v of u:

uTv

Search in auxiliary tree Tvfor points withy-coordinate ∈ [y, y′]

µ µ′

vsplit

Page 115: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 8

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

v

︸ ︷︷ ︸P(v) = canonical subset of Tv

︸ ︷︷ ︸P(v)

2. For each node uon the path from vsplit to µ:

For the right child v of u:

uTv

Search in auxiliary tree Tvfor points withy-coordinate ∈ [y, y′]

µ µ′

vsplit

Page 116: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

11 - 9

Range Trees: Query Algorithm1. Search in main tree for x-coordinate

v

︸ ︷︷ ︸P(v) = canonical subset of Tv

︸ ︷︷ ︸P(v)

2. For each node uon the path from vsplit to µ:

For the right child v of u:

u

3. Symmetrically for thepath from vsplit to µ′.

Tv

Search in auxiliary tree Tvfor points withy-coordinate ∈ [y, y′]

µ µ′

vsplit

Page 117: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 1

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

Page 118: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 2

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TP

Page 119: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 3

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TP

Page 120: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 4

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

Page 121: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 5

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

Page 122: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 6

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

Page 123: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 7

Range Trees: Construction

>

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

Page 124: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 8

Range Trees: Construction

>

xmidv

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

Page 125: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 9

Range Trees: Construction

>

vleft

Pleft Pright

xmidv

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

vright

Page 126: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 10

Range Trees: Construction

>

vleft TPPleft Pright

xmidv

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

vright

Page 127: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 11

Range Trees: Construction

>

vleft TPPleft Pright

xmidv

Running time?

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

vright

Page 128: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 12

Range Trees: Construction

>

vleft TPPleft Pright

xmidv

Running time?

O(n log n) :-(

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

vright

Page 129: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 13

Range Trees: Construction

>

vleft TPPleft Pright

xmidv

Running time?

O(n log n) :-(

Better:Pre-sort once,then build treebottom-upin linear time.

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

vright

Page 130: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

12 - 14

Range Trees: Construction

>

vleft TPPleft Pright

xmidv

Running time?

O(n log n) :-(

Better:Pre-sort once,then build treebottom-upin linear time.

⇓Total

constructiontime O(n log n)

Build2DRangeTree(point[ ] P)construct 2nd-level tree TP on P (y-order)if P = {p} then

create leaf v:else

xmid = median x-coordinate of PPleft = pts in P with x-coordinate ≤ xmidPright =

vleft = Build2DRangeTree(Pleft)vright = Build2DRangeTree(Pright)

create node v:

return v

TPpv

vright

Page 131: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

13 - 1

Range Trees: Space ConsumptionEach node v of the 1st-level tree has apointer to a 2nd-level tree Tv with|Tv| = Θ(|P(v)|).

Page 132: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

13 - 2

Range Trees: Space ConsumptionEach node v of the 1st-level tree has apointer to a 2nd-level tree Tv with|Tv| = Θ(|P(v)|).

Q: What’s the total space consumptionof all 2nd-level trees?

Page 133: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

13 - 3

Range Trees: Space ConsumptionEach node v of the 1st-level tree has apointer to a 2nd-level tree Tv with|Tv| = Θ(|P(v)|).

Q: What’s the total space consumption

What’s your guess:• Θ(n2),• Θ(n log n),• Θ(n log2 n), or• Θ(n)?

of all 2nd-level trees?

Page 134: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

13 - 4

Range Trees: Space ConsumptionEach node v of the 1st-level tree has apointer to a 2nd-level tree Tv with|Tv| = Θ(|P(v)|).

Q: What’s the total space consumption

What’s your guess:• Θ(n2),• Θ(n log n),• Θ(n log2 n), or• Θ(n)?

of all 2nd-level trees?

How many treeswill contain agiven point?

Page 135: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

13 - 5

Range Trees: Space Consumption

A: Each p ∈ P is stored in h = Θ(log n) 2nd-level trees.

p

p

p

p

Each node v of the 1st-level tree has apointer to a 2nd-level tree Tv with|Tv| = Θ(|P(v)|).

Q: What’s the total space consumption

What’s your guess:• Θ(n2),• Θ(n log n),• Θ(n log2 n), or• Θ(n)?

of all 2nd-level trees?

How many treeswill contain agiven point?

Page 136: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

13 - 6

Range Trees: Space Consumption

A: Each p ∈ P is stored in h = Θ(log n) 2nd-level trees.⇒ Θ(n log n) space

p

p

p

p

Each node v of the 1st-level tree has apointer to a 2nd-level tree Tv with|Tv| = Θ(|P(v)|).

Q: What’s the total space consumption

What’s your guess:• Θ(n2),• Θ(n log n),• Θ(n log2 n), or• Θ(n)?

of all 2nd-level trees?

How many treeswill contain agiven point?

Page 137: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 1

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)T(n, k) =

vu

µ µ′

vsplit

Page 138: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 2

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

T(n, k) =

vu

µ µ′

vsplit

Page 139: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 3

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k)

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

Page 140: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 4

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) +

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

Page 141: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 5

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) +

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 142: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 6

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) + 2h ·O(log n)

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 143: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 7

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) + 2h ·O(log n)

= O(k + log2 n)

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 144: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 8

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) + 2h ·O(log n)

= O(k + log2 n)

Rd?

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 145: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 9

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) + 2h ·O(log n)

= O(k + log2 n)

Rd?

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 146: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 10

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) + 2h ·O(log n)

= O(k + log2 n)

Rd? O(n logd−1 n) storage and construction time

O(k + logd n) query time

T(n, k) =

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 147: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

14 - 11

Range Trees: Query time

∑u ∈ paths to µ and µ′

O(ku + log n)

= O(∑u ku) + O(∑u log n)

= O(k) + 2h ·O(log n)

= O(k + log2 n)

Rd? O(n logd−1 n) storage and construction time

O(k + logd n) query time

T(n, k) =

See Chapter 5.4 in Comp. Geom A&A

vu

µ µ′

vsplit

k︸ ︷︷ ︸

︸︷︷

︸h

Page 148: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

15 - 1

Comparison

kd-tree range treeconstruction time O(n log n) O(n log n)storage O(n) O(n log n)query time O(k +

√n) O(k + log2 n)

Page 149: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

15 - 2

Comparison

kd-tree range treeconstruction time O(n log n) O(n log n)storage O(n) O(n log n)query time O(k +

√n) O(k + log2 n)

Note: trade-off between space and query time

Page 150: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 1

General Sets of PointsIdea: use composite numbers (a|b) with lex order

Page 151: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 2

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y)

Page 152: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 3

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y)

Page 153: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 4

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)

Page 154: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 5

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)

Page 155: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 6

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

Page 156: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 7

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

Page 157: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 8

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

Page 158: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 9

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

R̂ = [(x| −∞), (x′|+ ∞)]× [(y| −∞), (y′|+ ∞)]

Page 159: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 10

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

R̂ = [(x| −∞), (x′|+ ∞)]× [(y| −∞), (y′|+ ∞)]

Show:

Page 160: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 11

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

R̂ = [(x| −∞), (x′|+ ∞)]× [(y| −∞), (y′|+ ∞)]

p ∈ R ⇔ p̂ ∈ R̂Show:

Page 161: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 12

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

R̂ = [(x| −∞), (x′|+ ∞)]× [(y| −∞), (y′|+ ∞)]

p ∈ R ⇔ p̂ ∈ R̂Show:

This removes our assumption about the input points beingin general position.

Page 162: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

16 - 13

General Sets of PointsIdea: use composite numbers (a|b) with lex order

p = (x, y) p̂ =((x|y), (y|x)

)unique coordin.

range R = [x, x′]× [y, y′]

R̂ = [(x| −∞), (x′|+ ∞)]× [(y| −∞), (y′|+ ∞)]

p ∈ R ⇔ p̂ ∈ R̂Show:

This removes our assumption about the input points beingin general position.We can use kd-trees and range trees for any set of points;no matter how many points have the same x- or y-coord.

Page 163: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 1

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B[dBCvKO’08]

Page 164: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 2

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B[dBCvKO’08]

Page 165: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 3

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B[dBCvKO’08]

Page 166: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 4

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B[dBCvKO’08]

Page 167: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 5

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 168: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 6

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 169: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 7

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 170: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 8

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 171: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 9

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 172: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 10

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 173: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 11

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 174: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 12

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

30

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 175: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

17 - 13

Fractional CascadingTask 1: Given sets B ⊂ A ⊂N stored in sorted order in

arrays A[1..n] and B[1..m], support 1d rangequeries in the multiset A ∪ B in k + 1 · log n time!We allow n log m bits extra space.

Task 2: Assuming that task 1 can be solved, speed up2d range queries: O(k + log2 n)→ O(k + log n) time!

3 10 19 23 30 37 59 62 70 80 100 105

10 19 30 62 70 80 100

A

B

23

30

query withrange [20, 65]

link a ∈ Awith smallestb ≥ a in B

[dBCvKO’08]

Page 176: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 1

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

x17

Page 177: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 2

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 10 23 30 37 49 59 62 70 80 89 95 99

x y1917

Page 178: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 3

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

996237103 80 30 49 59 70 89 95

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19 23

17

Page 179: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 4

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

996237103 80 30 49 59 70 89 95

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19 23

17

Page 180: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 5

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

996237103 80 30 49 59 70 89 95

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19 23

17

Page 181: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 6

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33 10 19 37 80 99

996237103 80 30 49 59 70 89 95

3

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

17

Page 182: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 7

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33 10 19 37 80 99

996237103 80 30 49 59 70 89 95

3

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

17

Page 183: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 8

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33 10 19 37 80 99

996237103 80 30 49 59 70 89 95

3 95 59 70 89

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 184: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 9

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33 10 19 37 80 99

996237103 80 30 49 59 70 89 95

3 95 59 70 89

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 185: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 10

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33 10 19 37 80 99

10 378019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 186: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 11

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80 99

6210 378019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 187: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 12

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

99

6210 378019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 188: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 13

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 189: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 14

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y19

19

62

23

23 30 49

17

Page 190: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 15

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 191: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 16

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 192: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 17

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 193: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 18

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 194: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 19

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 195: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 20

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 196: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 21

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 197: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 22

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 198: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 23

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 199: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 24

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 200: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 25

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 201: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 26

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 202: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 27

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 203: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 28

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 204: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 29

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 205: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 30

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 206: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 31

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 207: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 32

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 208: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 33

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

17

Page 209: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 34

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

→ (21, 49), (33, 30), (52, 23)

17

Page 210: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 35

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

→ (21, 49), (33, 30), (52, 23)

Theorem: Let d ≥ 2 and let P be a set of n pts in Rd.Given O(n logd−1 n) preprocessing time &storage, d-dim range queries on P can beanswered in O(k + logd−1 n) time.

17

Page 211: Computational Geometry · 2 - 2 Orthogonal Range Queries Example: Personnel management in a company 2.000 3.000 e 19.500.000 19.559.999 G. Ometer born: salary: 2.500 e 1.000 1953-08-20

18 - 36

Layered Range Trees

2

5 7 8 12 15

17

21 33 41 52

58

672 93

67584121127

5

8

15

52

33

3 99

10 19 37 80

30 49

80 3 99 3049

99

6210 37

10 3719

8019

996237103 80 30 49 59 70 89 95

3 95 59 70 89

23 95 59 70 89

95 23 89 70

3 10 23 30 37 49 59 62 70 80 89 95 99

x y

[16, 20]× [53, 60]

19

19

62

23

23 30 49

→ (21, 49), (33, 30), (52, 23)

Theorem: Let d ≥ 2 and let P be a set of n pts in Rd.Given O(n logd−1 n) preprocessing time &storage, d-dim range queries on P can beanswered in O(k + logd−1 n) time.

17