50
Jan 2011 Segment Tree 1 Segment Tree and Its VLSI Layout Applications Shmuel Wimer Bar Ilan Univ., School of Engineering

Segment Tree and Its VLSI Layout Applications

  • Upload
    tarmon

  • View
    67

  • Download
    1

Embed Size (px)

DESCRIPTION

Segment Tree and Its VLSI Layout Applications. Shmuel Wimer Bar Ilan Univ., School of Engineering. Segment Tree Definition. Introduced by J. L. Bentley in 1977 Data structure designed to handle intervals on the real line Intervals end points belong to a fixed set of abscissas - PowerPoint PPT Presentation

Citation preview

Page 1: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 1

Segment Tree and Its VLSI Layout Applications

Shmuel Wimer

Bar Ilan Univ., School of Engineering

Page 2: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 2

Segment Tree Definition

• Introduced by J. L. Bentley in 1977

• Data structure designed to handle intervals on the real

line

• Intervals end points belong to a fixed set of abscissas

• Abscissas can be normalized to range [1,N] without loss

of generality by using a lookup table

• Given an interval [l,r], the segment tree T(l,r) is a rooted

binary tree defined recursively

Page 3: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 3

Every node is characterized by two parameters

: beginning of node's world (left end)

: end of node's world (right end)

v

B v

E v

If 1 a midpoint 2 is defined and two

sub-trees dividing 's world into two halves are rooted at :

is the root of a left sub-tree , 2

is the root of a right sub-t

r l B v E v

v v

LSON v T l B v E v

RSON v

ree 2 ,T B v E v r

Page 4: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 4

,T l rv

LSON v

, 2T l B v E v

RSON v

2 ,T B v E v r

The intervals , are called of v T

B v E v T

standard intervals

The unit intervals stored at leaves ( 1) are called

of

r l

T

elementry

intervals

Page 5: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 5

4,15

9,154,9

6,94,6 12,159,12

5,64,5 7,96,7 10,129,10 13,1512,13

8,97,8 11,1210,11 14,1513,14

Page 6: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 6

Insertion and Deletion

Segment tree is a ststic data structure w.r.t the set of abscissae.

It is designed to dynamically store intervals whose ends belong

to a set , 1, , 1, , namely, supporting insertions and

deletions.

l l r r

2

2

For 3, an interval , is partitined into log +

log 2 standard intervals of , at most, hence

for a set of interval with 2 distinct ends, the total number

of standard intervals i

r l l r r l

r l T l r

n n

2s bounded by log .O n n

Page 7: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 7

/ ( , , node ) {

(( ) ( )) {

/ , to ;

}

{

( 2 ) { / (

DELEINSERT

allocate

INSERT , , ) }

TE

de-allocate

DE

(

LETE

2

void int b int e v

if b B v and E v e

b e v

else

if b B v E v b e LSON v

if B v E v

) { / ( , , ) }

}

UPDATE ( ) ; // application specific, comp

DE

ut

LETE

ed at recurrence exit

}

INSERT e b e RSON v

v

Page 8: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 8

RP

LP

INP1,129

1,257 74,107

65,129

97,12965,97

65,81

73,81

81,97

73,77

73,75

74,75

75,77

77,81

97,115

105,109

97,105 105,115

105,107

Page 9: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 9

DELETE ( , , ( ))The action / imposes

a tour in , having the following str

INSERT ( , , ( )

uc

)

t

ure:

b e Rb e ROOT OT T

T

OT

*

An initial path (possible empty) starting at the root and ending at a

node called .

INP

v fork

*

*

From two (possibly empty) path and issue. Either , is

allocated entirely to (then and are empty), or all right sons

of , which are not on , and all left sons of , which are not

L R

L R

L L R

v P P b e

v P P

P P P

on

, are allocated (de-allocated), thus defining , fragmantation

into .

RP b e

standard intervals

Page 10: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 10

Allocation and De-Allocation

• Depends on application.

• If we wish to know the cardinality of cover of [B[v],E[v]]

then a counter C[v] is associated with node v:

– C[v] = C[V]+1 is allocation for INSERT

– C[v] = C[V]-1 is de-allocation for DELETE

• In many cases of VLSI aplication C[v] indicates the

presence of material, so we’ll be interested in whether

C[v] > 0 (material exists) or C[v]==0 (no material).

Page 11: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 11

VLSI Layout Applications

• Useful for calculating area and perimeter of polygon

ensemble for lateral and fringe capacitance extraction.

• Mask Boolean operations like UNION, INTERSECTION,

DIFFERENCE, and more, where contour is required.– Construction (contour) problems are typically more difficult than

reporting (area, perimeter) problems.

• More applications:– Design rule checking.

– Cross coupling capacitance

• Very robust and simple for implementation. There are

other, more efficient and more complex data structures.

Page 12: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 12

This is what mask designer is drawing

This data is used by lithography for mask generation, obtained by UNION operation

We may be interested in calculating the underling area for extracting lateral capacitance and the perimeter for the extraction of fringe capacitance

Page 13: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 13

This is what mask designer is drawing

This is the diffusion mask for manufacturing obtained by Boolean DIFFERENCE

Page 14: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 14

The electric field between the metal wires implies line-to-line capacitance, which is the reason of noise and power dissipation

This is what mask designer is drawing

We’d like to calculate the common parallel run L and the distance D so the line-to-line capacitance is L/D

D

L

Page 15: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 15

1D Measure of Union of Intervals 1 1Given intervals , , , , in the real line, how efficiently their measure

of UNION can be found?

n nn b e b e

1 1 2 2 1 2 2We sort the abscissae , , , , , , in ascending order , , ,

and associating to every point whether it was an opening (left) or closing (right)

end point of an interval. In case of tie, open

n n nb e b e b e p p p

ning end point preceeds closing one.

Page 16: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 16

1

1 2 2

void 1D_MEASURE_OF_UNION( , ) {

obtain , , , in ascending order ;

0 ; // initialize measure and multiplicity (cardinality) of cove 1 ;

( 2 ; 2 ; )

r

{

n

i i i

n

intervals b e

p p p

m C

for i i n i

1 ( 0 ) { }

( is left (opening) end point ) { 1 }

{ // is closing end poi1 }

}

n

t

}

i i

i

i

if C m m p p

if p C C

else pC C

Let be the measure of UNION and the multiplicity of overlapping intervals.m C

2Run time is log .O n n

Page 17: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 17

2D Measure (Area) of Union of RectanglesProblem: How to calculate the area of UNION without double counting

overlapping areas?

We'll simulate the imaginary vertical

line, called or

in a discrete mannar.

scan - line sweep - line

-

Consider an imaginary vertical line is

positioned at abscissa , intersecting

the rectangles with measure .

The area of UNION of rectangles is

then given by .

x

dx

m x

m x

Page 18: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 18

1 2 21Given rectangles , let , , , be their abscissae sorted in ascending

order (left-to-right). Associate with an abscissa whether it belongs to an openning

(left) or closing (right) edge. In c

n

i niR x x x

ase of tie in , openning edge preceeds closing one.x

ix 1ix

1

The projection (measure) of

the UNION of rectangles on

the scan-line can cahnge only

at abscissae of edges and

remains constant at the semi-

open interval , .i ix x

scan-line

1

The area increment is obtained

by .i i im x x x

Page 19: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 19

Efficient Calculation of m(xi)

2

Calculating efficiently is the key of the 2D algorithm and is obtained

in log time by segment tree implementation of the scan-line.

im x

O n

Since the ordinates of the vertical edges (position of horizontal edges) are known

apriori and their count is 2 at most, an appropriate segment tree 1, 2 can be

constructed.

n T n

An opening (left) edge triggers an insertion into 1,2 , while closing (right)

edge triggers deletion. Every insertion or deletion to 1,2 updates

(number of rectangles covering the node). Area is

T n

v T n C v

contributed iff 0.C v

A parameter is associated to a node , indicating how much of the segment

, is covered by the rectangles at . Clearly, root .i i

m v v

B v E v x m T m x

Page 20: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 20

INSERT

DELETE

DELETE

DEL

/ ( , , node ) {

(( ) ( )) { / }

{

( 2 ) { / ( , , ) }

I

N

S

ETE

ERT

IN ( 2 ) { / ( , ,ERT S

void int b int e v

if b B v and E v e

else

if b B v E v b e LSON v

if B v E v e

C C

b e

v v

// node is fully covered

// node is either partially covered or em

) }

}

( 0 ) { = }

{

( is not a leaf ) { = }

{ =0 }

ty

}

}

p

RSON v

if C v m v E v B v

else

if v m v m LSON v m RSON v

else m v

2

Given a vertical edge at abscissa and ordinates , , the measure

root is obtained in log time.

i i i

i

x b e

m T m x O n

Page 21: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 21

1

1 2 2

1 2 1 2

2D_MEASURE_OF_UNION ( ) {

sort vertical edges of retngles in ascending order , , , ;

Initialize root of tree ;

construct segment tree spanning min , max

n

i i

n

ii n i

void rectangles R

x x x

T b

1

;

0 ;

( 1 ; 2 ; ) {

( 1 ) { root }

( is / ) {

/ ( ,

// measure

openi

, root )

ini

cl

;

ng

INSERT

}

osing

DE

talization

T E LE

in

i i

i

i i

e

m

for i i n i

if i m m T x x

if x

b e T

}

2Overall run-time is log . Overall storage is .O n n O n

Page 22: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 22

Perimeter of Union of Rectangles

vertical edgesPerimeter is the length sum of: horizontal edges

: is the vertical contribution to perimeter

resulting from insertion or deletion of an edge.

Observation i i -1m x -m x

i -1m x im x

i i -1m x -m x

Page 23: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 23

1 1

Horizontal contribution is added along scan-line progression. If = 2 number

of scan-line intersections in , . Contribution to perimeter is .

i

i i i i ix x x x

2i

1ix ix

6i

1ix ix

Page 24: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 24

1How to compute efficiently along scan-line progression? Let .

n

i iiF R

2 number of the scan-line intersections with

, .

1 ,

0 otherwise

1 ,

0 otherwise

v S x F

B v E v

B v S x F B v E vLBD v

E v S x F B v E vRBD v

and avoid double counting of horizontal edges in case

that a continous segment is split between two sons.

LBD v RBD v

Page 25: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 25

B v E vv

1RBD 1LBD

, and are maintained at every INSERT and

DELETE.

v LBD v RBD v

2B v E v

Page 26: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 26

UPDATE ( node ) {

( 0 ) { 2 ; 1 ; }

{

2 ;

;

;

void v

if C v v LBD v RBD v

else

v LSON v RSON v

RBD LSON v LBD RSON v

RBD v RBD RSON v

LBD v LBD LSON v

}

}

The term 2 compensates for the

case of artificail split between the two sub-trees of sons.There exists

.i

RBD LSON v LBD RSON v

ROOT T

Page 27: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 27

1

1 2 2

1 2 1 2

PERIMETER_OF_UNION ( ) {

sort vertical edges of retngles in ascending order , , , ;

construct segment tree spanning min , max ;

0 ; 0 ; // m

n

i i

n

i ii n i n

o

void rectangles R

x x x

T b e

m p

*1

easure and perimeter initalization

// take at the

( 1 ; 2 ; ) {

root ;

openning ( is closing

DELET

beginning

/ ) {

/ ( , ,

of

INSERT r tE oo

,

i

i

i

i

i

for i i n i

T

i

b

x

x

x

f

e

* *

*

*1

// vertical contribution

// store old meas

)

}

root ; ;

;

(

ure

// horizontal cont1 ) { }

}

ribution

o

o

i i

T

m m T p m m

m m

if i p x x

Page 28: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 28

2Overall time is log . Overall storage is .O n n O n

What happens if edges have same abscissa and closing edges

are preceding opening ones?

Questions :

Although material is continuous when two rectangles are abutting, the edge

of abutment will be accounted twice in perimeter!

Edges are sorted such that for same abscissa opening edges are preceding

closing ones.

Page 29: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 29

The Contour of Union of Rectangles

1 1Given a collection of rectangles , find the contour of .

nn

i ii iR F R

Rectangles are counterclockwise oriented. Hence contour is also oriented.

Resulting countour orientation must be consistent. External countours are

counterclockwise oriented. Internal contours (holes) clockwise oriented.

Page 30: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 30

S c

E S c F

A left (opening) edge is located at abscissa .

What portion it contributes to the contour?

E c

, >0E S c F

Page 31: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 31

S c

E S c F

A right (closing) edge is located at abscissa .

What portion it contributes to the contour?

E c

, >0E S c F

Page 32: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 32

Two phase algorithm (Lipski - Preparata 1980):

Find the set of vertical edges of contour of UNIONV

Link the vertical edges in by horizontal edges to form properly oriented cycles.V

Derivtion of is done by a segment tree implementation of scan-line. Let

denote vertical scan-line at abscissa . The intersection consists of a

set of disjoint vertical intervals.

V S c

c S c F

1 2 2 1

1

Let , , , be the sorted abscissae of . F doesn't change

at the open interval .

n

n i i

i i

x x x R S x

x x x

Page 33: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 33

The meaning of with regard to scan-line is that the contribution of

a left (opening) edge is computed before edge INSERT takes place.

Similarily, means that the contribution of a right (closing)

c

c

edge is

computed after edge DELETE takes place.

In addition to standard segment-tree parameters of a node , we define

1 0 a potential indicator

0 otherwise

Initiaization: =0 and =1 at construction of the segment-tre

v

C u u T vP v

C v P v

e.

, 0 , so its complement is the gaps

between these intervals, which are found with the aid of and .

S x F B v E v C v

C v P v

Page 34: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 34

The contribution of an edge : , is given by:

,

S x F E E b e

CONTR v B v E v

CONTR LSON v C

0

1

0

C v

P v

P vONTR RSON v

: ,E b e

S x F

Edge : , is INSERT (DELETE)E b e

Decomposed into standard intervals

1Scan-line intersection with

n

iiF R

E S x F

: , intersection with complementE b e

Problem: contiguous segments are split

Page 35: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 35

The formation of contiguous segments of is obtained by using

a STACK data structure. Traversal of decomposition into standard intervals

is done left-to-right, hence abutment across standard int

E S x F

E

ervals can be detected

on-the-fly.

1 2 2Set at any new abscissa of sorted , , , .

( // contiguous

// start ne

) { }

{ w seg ; m en; } t

nSTACK x x x

if B v TOP STACK TOP STACK E v

else B v STACK E v STACK

Edges are sorted such that for same abscissa openning edges are preceding

closing ones. Opening (closing) edges having same abscissa are sorted in

ascending order of their lower ordinate to ensure contiguity and uniqueness.

Page 36: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 36

CONTR ( , , node ) {

( ==0) {

(( ) ( ) ( 1)) {

( ) {

// >0 implies ,

// contribution to contour

// }

void int b int e v

if C v

if b B v and E v e and P v

if B v TOP STACK TOP

C v B v E v S x

STACK E v

F

{ ; ; }

}

{

( 2 ) { CONTR ( , , ) }

( 2 ) { CONTR ( , , ) }

} }

contiguous

// start new segm

ent

}

else B v STACK E v STACK

else

if b B v E v b e LSON v

if B v E v e b e RSON v

Page 37: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 37

/ ( , , node ) {

(( ) ( )) { / }

{

INSERT

INSE

DELETE

DELETRT ( 2 ) { / ( , , ) }

( 2 ) { / (INSERT

E

DEL T ,E , E

void int b int e v

if b B v and E v e

else

if b B v E v b e LSON v

if B v E v e

C v v

b

C

e

) }

}

( >0 ) { =0 }

( is a leaf ) {

// node cannot contribute to contour

// node can contribute to contour

// node inherits contribution

=1 }

potential from son

s

RSON v

if C v P v

else if v P v

els

(( ==1) ( ==1)) { =1 }

{ // contribution may come from lower n =0 d s o}

}

e

e if P LSON v and P LSON v P v

else P v

Page 38: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 38

1

1 2 2

1 2 1 2

VERTICAL_EDGES_OF_CONTOUR ( ) {

sort vertical edges of rectangles in ascending order , , , ;

construct segment tree spanning min , max ;

;

n

i i

n

i ii n i n

void rectangles R

x x x

T b e

V ST

;

( 1 ; 2 ; ) {

( is opening ) {

// i

CO

nitalization

// contribution preceds edge

NTR ( , ,

in

) ; INSERT ( , , ) ;

}

sertion

/

/{

i

i i i i

ACK

for i i n i

if x

b e ROOT T b e ROOT T

else

1

DELETE ( , , ) ; CONTR ( , , ) ;

}

(( > ) (opening / closing status change)) {

; ;

} }

contribution proc

eeds edge deletion

i i i i

i i

b e ROOT T b e ROOT T

if x x or

V V STACK STACK

}

Page 39: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 39

Completing the Cycles of Contour

Denote by ; , vertical edge , at abscissa and by ; , horizontal

edge , at ordinate . Horizontal edge of contour is supported by two vertical

edges.

x b t b t x y l r

l r y

1 1 2 ; ,x y y

2 0 1 ; ,x y y

1 1 2 ; ,y x x

Associate to every vertical edge , ; , , two triplets

, ; and , ; pointing to each other.

j j j j j

j j j j j j

e V e x b t

x b t x t b

2 1 0, ; x y y

2 0 1, ; x y y

1 2 1, ; x y y

1 1 2, ; x y y

Page 40: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 40

1 1 1 2 2 2

Let . We sort , ; , 1 2 , lexicoraphically in ascending

order by as primary key and as secondary key. (Why all triplets must be

distinct?)

Let , ; , , , ; be sorted. It i

j j j

j j

q q q

V q x y z j q

y x

x y z x y z

s possible by traversal

over it and by usage of triplets mutual pointers to construct all contour cycles

in consistent directions (external contours and holes).

The resulting countor may consist of several cycles. Counterclockwise oriented

contours are the external boundary of polygons, while clockwise oriented cycles

are holes of polygons.

Traversal takes time linear in triplet list, so log sorting time defines

run-time complexity.

O q q

Page 41: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 41

e1

e3

e2

e6

e5

e8

e7

e4

e9

e10

Edges , 1 10, were obtained

in this order by first scan-line part.

ie i

2 2 2, ;x b t 4 4 4, ;x b t 4 4 4, ;x t b 9 9 9, ;x b t 9 9 9, ;x t b 10 10 10, ;x b t 5 5 5, ;x b t

7 7 7, ;x b t 1 1 1, ;x b t 2 2 2, ;x t b 7 7 7, ;x t b 1 1 1, ;x t b 5 5 5, ;x t b

6 6 6, ;x b t 8 8 8, ;x b t 10 10 10, ;x t b 3 3 3, ;x t b 8 8 8, ;x t b

3 3 3, ;x b t

6 6 6, ;x t b

Page 42: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 42

There’s no ambiguity in deciding whether to go to left or right triplet when

an horizontal edge is decided.

It follows that a pair of successive triplets defines horizontal edges.

Consequently, once two successive triplets are traversed and define a new

horizontal edge, the number of triplets on both the left and the right parts of

the list must be even.

Therefore, if the index of a triplet is even, its left adjacent triplet is paired,

otherwise, the right triplet is paired.

Page 43: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 43

Run-time Complexity

Let be a balanced binary tree with leaves and a subset

of its nodes. Denote by the set of nodes on the paths from to

the root. Total number of nodes along the paths satisfies:

T n L

P u u L

Lemma :

2

16 log .

u L

nP u L

L

We can assume that is a subset of 's leaves, as this is the

worst case, yielding the longest and least overlapping paths to root.

L TProof :

0Let be the tree whose leaves are and containing

whose parent or itself has at least two descendants in .

T L L T L T L

v T L v L

Page 44: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 44

0

0

0

0

The number of leaves in is . This

follows since a leaf is either in both

and , or if a leaf is in \

then a path to root must enter .

Also, two paths and ,

and can

T L

T L

T L

T L

L

u

P u

P u P u

T L T L

u L

u L

0not merge at a laef of .T L

0 consists of a "top" part whose leaves are 1:1 connect with

disjoint paths (a path is possible empty) to the leaves of .

T L T L L

T L

Page 45: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 45

0Given fixed , The largest is obtained when is balanced and

topmost in . This follows since two paths in connecting leaves

to root are merged as close as possible to root, resulting in ma

xim

T L

T L

T L

T L

L

al count

of distinct nodes of the two paths.

U’ U”

|P(U’)+ P(U”)|=7

U’ U”

|P(U’)+ P(U”)|=5

2 2

2 2 2

2 1 log log

162 log 1 log 1 log . Q.E.D

T L L L n L

nL n L L

L

Page 46: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 46

Consider the contribusion to contour ocurring by an edge , 1 2 ,

in CONTR. Let be the number of distinct pieces of .

i

i i

E i n

n E S x F

There are 3 possibilities for a node in CONTR. If >0 traversal

is aborted. =1, whole node's interval , is contributed

and traversal is aborted.

v C v

P v B v E v

Most time consuming part occurs at partially covered nodes,

=0 and =0. Contribution is made by recursive call

of CONTR and decomposition into contiguous standard

intervals obtained along the left an

C v P v

d right paths issued at .v

Page 47: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 47

Each of the disjoint pieces of results in

at most two search paths terminating at most in two leaves.

Hence the total constribution of such searches is 2

leaves at most, with a constant a

i i

i i

n E S x F

n n

mount of work at each node.

2

1

2

21

Let be the total amount of contour vertical pieces.

By Lemma the total node visits (paths overlap included) is

16bounded by 2 log .

2

n

ii

n

iii

p n

nC n

n

Page 48: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 48

2 2

21 1

2 22 2

2 2 21 1

16Since , 2 log is maximized for = 2 .

2

Hence, the number of visited nodes is bounded by

16 16 642 log log log .

2

n n

i i ii ii

n n

ii ii

np n n n p n

n

n p n nC n C Cp

n n p p

2INSERT and DELETE are standard and consume log ,

and same for intial sort of input vertical edges. Building initial

segment tree is .

O n n

O n

22 2

The edge contour of UNION of n isothetic

rectangles can be found in log log .

p

O n n p n p

Theorem :

Page 49: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 49

21

The run-time complexity of finding a contour of

without holes is bounded by log .n

iiF R n n

Theorem :

1 2

1 2

We'll show that the problem sorting numbers

, , , can be transformed in time into finding

the contour of UNION of rectangles. Let , , , be

arbitrary real positive numbers. We define

n

n

N

x x x O n

x x x

Proof :

1

: , 0, 0, , 1 , max 1.i i i ii n

R x y x M x i n M x

Page 50: Segment Tree and Its VLSI Layout Applications

Jan 2011 Segment Tree 50

2

Finding the contour solves the sorting problem,

known to be bounded by log . Q.E.Dn n