march 20111 trapezoidal maps shmuel wimer bar ilan univ., school of engineering

26
March 2011 1 Trapezoidal Maps Shmuel Wimer Bar Ilan Univ., School of Engineering

Upload: ruth-fields

Post on 28-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

March 2011 1

Trapezoidal Maps

Shmuel Wimer

Bar Ilan Univ., School of Engineering

March 2011 2

Trapezoidal Map

Planar subdivision

Abscissas are all distinct

n segments

6n+4 vertices at most

3n+1 trapezoids at most

March 2011 3

leftPoint

top

bottom

leftPoint top

bottom

leftPoint

top

bottom

leftPoint

top

bottom

Trapezoidal map can be constructed in O(nlogn) time

by a scan-line algorithm.

March 2011 4

Randomized Incremental Algorithm

1 - trapezoidal map of a set of line

segments with distinct abscissae of end points.

n

i iS S s

T

The algorithm builds a by-product data structure

supporting point location queries in .S SD T

An advantage over construction by scan-line which

doesn't yield query supporting data structure.

March 2011 5

Inner nodes have degree 2

1p1q1s

2p

2q2s

A

B

C

D E G

F

ST

1p

1qA

2q

G2s

E

F

2S

D

2p

1s

C

B

x-node

y-node

trapezoid

SD

Trapezoids of and leaves of are interlinked by pointersS ST D

March 2011 6

1p1q1s

2p

2q2s

A

B

C

D E G

F

1p

1qA

2q

G2s

E

F

2S

D

2p

1s

C

B

Does q lie to the left or to the right ?

Does q lie above or below?

Querying a point location

March 2011 7

Randomized Construction Algorithm

Segments are added to randomly, one at a time.ST

The structure of is affected by selection order.

Some orders may yield with bad query time of

, others may yield good query time of l .ogO n

S

S

O n

D

D

Expected query time is log and expected size

is !

O n

O n

2Some my be of large size , others may be

of size .

O nS

O n

D

March 2011 8

0 0

10

( ) {

bound by a rectang

// - non

le ;

crossing segments

initialeze and ;

( , 1 , randomly selected ) {

find

// Returns

,

,

an

,

d

i

ik j

S

S R

S

S S

s S i n

s

TrapezoidalMap

T

T D

D

T

for

10

1

;

remove , , and insert new

trapezoids in appearing by insertion ;

remove corresponding leaves from , create

leaves in for new trapezoids and interlink to

i

ik

ii

i

i

s

T

T

D

D ;

}

}

iT

March 2011 9

1

Two invariants of :

1) is a trapezoidal map of , , ,

2) is a valid search structure for .

ii i

i i

S s s

TrapezoidalMap

T

D T

0 0Initialization: , is a corresponding leaf.R T T D

1 1

0

To modify we query by searching in and

derive , , successively from left to right.

i ii

k

p

T D

1If is above , then is its lower-right

neighbor, otherwise it is upper right. (Abscissa uniqueness

ensures there are only two right-adjacent trapezoids).

j i js rightPoint

March 2011 10

is0 1

23

11

0

If doesn't exist in , searching in will end

at a leaf (trapezoid ).

ii ip S

D

March 2011 11

1

0

If exists in , it must meet an internal node. If it is

-node laying on a vertical line, proceeding query with

= obtaine .

i i

i i

p S

x

p p s

1

0

If it is -node, it must be a left point , . Slops

of and are compared and is decided accordingly.

j j i

i j

y p s S

s s

js i jp q

is

jsi jp p

is

0

0

March 2011 12

0

1 1

10

// Returns sequence , , inter

( , , : , ) {

search in to find ;

0 ;

( ) {

i

sected by

// progress rightward along

f

i ii i i

ii

i

ij

k

i

s p q

p

j

while sq

s

FollowSegment

T D

T

rightPoint

1

1

0

( is above )

{ is lower-right neighbor of }

else { is upper-right neighbor of }

++ ;

}

return sequence , , ;

}

j i

j j

j j

k

s

j

rightPoint

March 2011 13

isip iq

1iT

A

iT

BC

D

1iD

ip

iq

is B

A

DC

iD

1iD

New segment insertion

March 2011 14

The information attached to new trapezoids is their left

and right neighbor trapezoids, top and bottom segment

and points defining their left and right vertical segment.

If the information in Δ is properly stored, above info

can be determined in a constant time from si and Δ.

Assuming that a point is contained in Δ, the sub tree

replacing its leaf is sufficient to determine whether the

point is in A, B, C or D.

If pi=leftPoint(Δ) and / or qi=rightPoint(Δ), Δ is divided

into two or three trapezoids and sub-tree replacement is

simpler.

March 2011 15

A

iT

B

C

E

D

F

Intersection with more than one trapezoid

0Any of and that didn't exist partition and into

three trapezoids.i i kp q

is

ipiq

01iT1 2

3

0By using the information stored in , , , the vertical

extensions are shortened to incidence , consuming constant

time per trapezoid.

k

is

March 2011 16

A

iT

B

C

E

D

Fis

ipiq

01iT1 2

3

1iD

3210

iqis

B FD

E

1iD

is is

is

CA

iD

March 2011 17

0If and / or are internal points, leaf is

replaced with an internal -node pointing to a leaf

and a -node of which points to two leaves. Else,

a leaf is replaced by a -node pointing to tw

i i k

i

p q

x

y s

y

o leaves.

1 1The leaves of to are replaced with a -node

of pointing to two leaves.k

i

y

s

1The fact that different trapezoids in merge into

a single trapezoid in results few incoming arcs to

a leaf in .

i

i

i

T

T

D

March 2011 18

and its associated search structure

for line segments set , are constructed in

log expected time, occupying storage

and yielding expected query time of log .

S

S n S

O n n O n

O n

:Theorem T

D

A query traverses a path in from root

to a leaf (trapezoid).

S:Proof D

- the number of new nodes on the query path,

which have been created at insertion. , 1

are random variables satisfying 3.

i

i i

i

X

s X i n

X

March 2011 19

- probability that there exists a node on the search

path of , created at insertion. Therefore

0 1 3 .

i

i

i i i i i

P

q s

E X X P P P

1

The length of a search paths is obtained by summing

the random variables over all insertions, .

By linearity of expectation it follows that the expected

length of a search path is:

ni iiX X

1 1 E E .

n ni ii iX X

March 2011 20

1 1

1

1

- trapezoid after insertion of containing .

Therefore, Pr

Pr 4 .

q i i

i q i q i

iq i

S s q

P S S

S i

T

R.H.S follows from the observation that the probability

of to disappear by the removal of from is

4 at most since may participate in defining any of

its four border edges.

iq i i

i

S s

i s

T

March 2011 21

1 1 1 1

Putting everything togather, the expected length of

a query path is bounded by:

E 3 12 12 1 12n n n n

i i ni i i iX P i i H

1

1 1 1 is the -th harmonic number , which

1 2

satisfies ln ln 1 (recall that ln ).

n

n

n

H nn

n H n n dx x

In conclusion, query time is log .O n

To obtain the size of we'll bound its node count. SD

March 2011 22

leaves are in 1:1 correspondence with

trapezoids, whose number is bounded by .

S S

O n

D T

To bound the number of inner node let be the

mumber of new trapezoids created by insertion.

It follows by construction of that the number of

inner nodes is exactly 1.

i

i

i

k

s

k D

How many new trapezoids are in ? No more

than total number in which is bounded by ( ).

i

i O i

T

T

March 2011 23

2

1

Summing over all insertion, a worst-case upper

bound of size is given by:

.n

i

S

O n O i O n

D

1 1

More interesting is the expected size, which by

linearity of expectation is:

E 1 En n

i ii iO n k O n k

For a trapezoid and a segment define

1 if when is removed from , ,

0 otherwise.

ii

ii

s S

s Ss

T

T

March 2011 24

4 segments at most cause trapezoids disappearence.

Hence, , 4 | | .iis Si

s O i

TT

| | and the probability of a segment to be chosen

is1 . is the number of trapezoids created (removed)

by insertion (removal) of .

i

i

i

S i

i k

s

Taking the average over all ,

1E , 1 .

i i

ii s Si

s S

O ik s O

i i

T

March 2011 25

In conclusion the expected number of new trapezoids

created at a segment insertion is 1 .O

This yields storage bound.O n

Expected run time consists of 1 initialization

time, log quering to find at insertion,

and E 1 for internal nodes creation.

i i

i

O

O i p s

k O

This yields log creation time.O n n ■

March 2011 26

Given a set of segments, nothing is guaranteed on the

maximal run time, which can be quadratic.

Considering all possible problems of n segments, what

is the expected maximal query time?

O(logn)