Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Interval Tree + Priority Search Trees
๐ฃ
๐ผ๐๐๐๐ก ๐ผ๐๐๐โ๐ก
๐ผ๐๐๐ ๐ผ๐๐๐
PST: min heap over
the ๐ฅ-coordinate
(of left endpoint)
while a BST over
the ๐ฆ-coordinate
PST: max heap over
the ๐ฅ-coordinate
(of right endpoint)
while a BST over
the ๐ฆ-coordinate
๐ฅ๐๐๐
Query object: vertical segment ๐๐ฅ ร [๐๐ฆ , ๐๐ฆโฒ ]
rootSet: ๐ horizontal line segments
Applicable to axis-parallel segments only.
IT
๐
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
General Windowing Queries
Line segments can have arbitrary orientations.
๐ค
General Windowing Queries
Line segments can have arbitrary orientations.
A bounding box approach?
๐ค
General Windowing Queries
Line segments can have arbitrary orientations.
A bounding box approach?
โข Replace each segment with its bounding box.
๐ค
General Windowing Queries
Line segments can have arbitrary orientations.
A bounding box approach?
โข Replace each segment with its bounding box.
โข Find all bounding boxes intersected the query.
โข Check the segments defining these boxes.
๐ค
General Windowing Queries
Line segments can have arbitrary orientations.
A bounding box approach?
โข Replace each segment with its bounding box.
โข Find all bounding boxes intersected the query.
โข Check the segments defining these boxes.
Works well generally in practice.
๐ค
General Windowing Queries
Line segments can have arbitrary orientations.
A bounding box approach?
โข Replace each segment with its bounding box.
โข Find all bounding boxes intersected the query.
โข Check the segments defining these boxes.
Works well generally in practice.
Worst case can be very bad.
No segment intersects
๐ even though all the
bounding boxes do!
๐ค
๐ค
General Windowing Queries
Line segments can have arbitrary orientations.
A bounding box approach?
โข Replace each segment with its bounding box.
โข Find all bounding boxes intersected the query.
โข Check the segments defining these boxes.
Works well generally in practice.
Worst case can be very bad.
No segment intersects
๐ even though all the
bounding boxes do!
๐ค
๐ค
No guarantee on a fast query time.
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Range trees.
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Range trees.
Segments intersecting the window boundary.
One intersection query with each of the 4 boundary edges.
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Range trees.
Segments intersecting the window boundary.
One intersection query with each of the 4 boundary edges.
Focus on a vertical boundary edge.
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Range trees.
Segments intersecting the window boundary.
One intersection query with each of the 4 boundary edges.
Focus on a vertical boundary edge.
Query problem
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Range trees.
Segments intersecting the window boundary.
One intersection query with each of the 4 boundary edges.
Focus on a vertical boundary edge.
Query problem
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Thinking Top-Down
Segments with โฅ 1 endpoints in ๐.
Range trees.
Segments intersecting the window boundary.
One intersection query with each of the 4 boundary edges.
Focus on a vertical boundary edge.
Query problem
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set: ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of ๐ segments
โข arbitrarily oriented
โข non-intersecting in the interior
โข possibly sharing endpoints
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ ๐ผ ๐๐๐ ๐ฃ dat node ๐ฃat node ๐ฃ
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ ๐ผ ๐๐๐ ๐ฃ dat node ๐ฃat node ๐ฃ
๐ฅ ๐๐๐ ๐ฃ > ๐ ๐ฅ๐ฅ ๐ฅ ๐ฅ ๐๐๐ ๐ ๐๐๐ ๐ฃ > ๐๐ฅ
Checking if left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ, ๐๐ฆโฒ ]
(for a horizontal segment).
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ ๐ผ ๐๐๐ ๐ฃ dat node ๐ฃat node ๐ฃ
๐ฅ ๐๐๐ ๐ฃ > ๐ ๐ฅ๐ฅ ๐ฅ ๐ฅ ๐๐๐ ๐ ๐๐๐ ๐ฃ > ๐๐ฅ
Checking if left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ, ๐๐ฆโฒ ]
(for a horizontal segment).
No such reduction to range
query when the segment is
arbitrarily oriented
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ ๐ผ ๐๐๐ ๐ฃ dat node ๐ฃat node ๐ฃ
๐ฅ ๐๐๐ ๐ฃ > ๐ ๐ฅ๐ฅ ๐ฅ ๐ฅ ๐๐๐ ๐ ๐๐๐ ๐ฃ > ๐๐ฅ
Checking if left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ, ๐๐ฆโฒ ]
(for a horizontal segment).
No such reduction to range
query when the segment is
arbitrarily oriented
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ ๐ผ ๐๐๐ ๐ฃ dat node ๐ฃat node ๐ฃ
๐ฅ ๐๐๐ ๐ฃ > ๐ ๐ฅ๐ฅ ๐ฅ ๐ฅ ๐๐๐ ๐ ๐๐๐ ๐ฃ > ๐๐ฅ
Checking if left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ, ๐๐ฆโฒ ]
(for a horizontal segment).
No such reduction to range
query when the segment is
arbitrarily oriented
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
๐
Segment ๐ 1 โ ๐ผ๐๐๐(๐ฃ) intersects ๐but its left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ , ๐๐ฆ
โฒ ].
๐ 2
๐ 1
Inapplicability of an Interval Tree
An interval tree is not very helpful.
Search with ๐๐ฅ ๐ผ ๐๐๐ ๐ฃ dat node ๐ฃat node ๐ฃ
๐ฅ ๐๐๐ ๐ฃ > ๐ ๐ฅ๐ฅ ๐ฅ ๐ฅ ๐๐๐ ๐ ๐๐๐ ๐ฃ > ๐๐ฅ
Checking if left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ, ๐๐ฆโฒ ]
(for a horizontal segment).
No such reduction to range
query when the segment is
arbitrarily oriented
โโ,๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐ฅ๐๐๐
๐ 3
Segment ๐ 3 โ ๐ผ๐๐๐(๐ฃ) and
its left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ , ๐๐ฆโฒ ].
But it has no intersection with ๐.
๐
Segment ๐ 1 โ ๐ผ๐๐๐(๐ฃ) intersects ๐but its left endpoint โ (โโ, ๐๐ฅ] ร [๐๐ฆ , ๐๐ฆ
โฒ ].
Locus Approach
Window ๐: ๐๐ฅ, ๐๐ฅโฒ ร [๐๐ฆ , ๐๐ฆ
โฒ ] defined by four parameters.
Idea: Partition the parameter space into regions such that queries in
the region have the same answer.
Locus Approach
Window ๐: ๐๐ฅ, ๐๐ฅโฒ ร [๐๐ฆ , ๐๐ฆ
โฒ ] defined by four parameters.
Idea: Partition the parameter space into regions such that queries in
the region have the same answer.
Input: interval set: ๐ผ = { ๐ฅ1, ๐ฅ1โฒ , ๐ฅ2, ๐ฅ2
โฒ , โฆ , ๐ฅ๐, ๐ฅ๐โฒ }
1D Query
point ๐๐ฅ
Output: all intervals containing ๐๐ฅ
Locus Approach
Window ๐: ๐๐ฅ, ๐๐ฅโฒ ร [๐๐ฆ , ๐๐ฆ
โฒ ] defined by four parameters.
Idea: Partition the parameter space into regions such that queries in
the region have the same answer.
Input: interval set: ๐ผ = { ๐ฅ1, ๐ฅ1โฒ , ๐ฅ2, ๐ฅ2
โฒ , โฆ , ๐ฅ๐, ๐ฅ๐โฒ }
1D Query
point ๐๐ฅ
Output: all intervals containing ๐๐ฅ
๐1, ๐2, โฆ , ๐๐: distinct interval endpoints in the increasing order.
๐๐โ1๐1 ๐2 ๐๐
Locus Approach
Window ๐: ๐๐ฅ, ๐๐ฅโฒ ร [๐๐ฆ , ๐๐ฆ
โฒ ] defined by four parameters.
Idea: Partition the parameter space into regions such that queries in
the region have the same answer.
Input: interval set: ๐ผ = { ๐ฅ1, ๐ฅ1โฒ , ๐ฅ2, ๐ฅ2
โฒ , โฆ , ๐ฅ๐, ๐ฅ๐โฒ }
1D Query
point ๐๐ฅ
Output: all intervals containing ๐๐ฅ
๐1, ๐2, โฆ , ๐๐: distinct interval endpoints in the increasing order.
๐๐โ1๐1 ๐2 ๐๐
The parameter space โโ,โ is partitioned into elementary intervals.
โโ, ๐1 , ๐1, ๐1 , ๐1, ๐2 , ๐2, ๐2 ,โฆ , ๐๐โ1, ๐๐ , ๐๐, ๐๐ , ๐๐, โ
Locus Approach
Window ๐: ๐๐ฅ, ๐๐ฅโฒ ร [๐๐ฆ , ๐๐ฆ
โฒ ] defined by four parameters.
Idea: Partition the parameter space into regions such that queries in
the region have the same answer.
Input: interval set: ๐ผ = { ๐ฅ1, ๐ฅ1โฒ , ๐ฅ2, ๐ฅ2
โฒ , โฆ , ๐ฅ๐, ๐ฅ๐โฒ }
1D Query
point ๐๐ฅ
Output: all intervals containing ๐๐ฅ
๐1, ๐2, โฆ , ๐๐: distinct interval endpoints in the increasing order.
๐๐โ1๐1 ๐2 ๐๐
The parameter space โโ,โ is partitioned into elementary intervals.
โโ, ๐1 , ๐1, ๐1 , ๐1, ๐2 , ๐2, ๐2 ,โฆ , ๐๐โ1, ๐๐ , ๐๐, ๐๐ , ๐๐, โ
Every open interval has two consecutive endpoints.
Every closed interval consists of a single endpoint.
Open intervals alternate with closed intervals.
Using a Binary Search Tree?
๐
โโ, ๐1 ๐1, ๐1 โฆ ๐๐ , ๐๐+1 โฆ ๐๐, ๐๐ ๐๐, โ
Int ๐ : elementary interval
corresponding to ๐.
๐ : a leaf
Using a Binary Search Tree?
Store at the leaf ๐ all the intervals
in ๐ผ that contain Int ๐ .
๐
โโ, ๐1 ๐1, ๐1 โฆ ๐๐ , ๐๐+1 โฆ ๐๐, ๐๐ ๐๐, โ
Int ๐ : elementary interval
corresponding to ๐.
๐ : a leaf
Using a Binary Search Tree?
Store at the leaf ๐ all the intervals
in ๐ผ that contain Int ๐ .
๐
โโ, ๐1 ๐1, ๐1 โฆ ๐๐ , ๐๐+1 โฆ ๐๐, ๐๐ ๐๐, โ
Int ๐ : elementary interval
corresponding to ๐.
๐ : a leaf
Query time
๐(log ๐ + ๐)
Using a Binary Search Tree?
Store at the leaf ๐ all the intervals
in ๐ผ that contain Int ๐ .
๐
โโ, ๐1 ๐1, ๐1 โฆ ๐๐ , ๐๐+1 โฆ ๐๐, ๐๐ ๐๐, โ
Int ๐ : elementary interval
corresponding to ๐.
๐ : a leaf
Query time
๐(log ๐ + ๐)
BST search #reported
intervals
Using a Binary Search Tree?
Store at the leaf ๐ all the intervals
in ๐ผ that contain Int ๐ .
๐
โโ, ๐1 ๐1, ๐1 โฆ ๐๐ , ๐๐+1 โฆ ๐๐, ๐๐ ๐๐, โ
Int ๐ : elementary interval
corresponding to ๐.
๐ : a leaf
Query time
๐(log ๐ + ๐)
BST search #reported
intervals
High storage if the intervals overlap
a lot.
Using a Binary Search Tree?
Store at the leaf ๐ all the intervals
in ๐ผ that contain Int ๐ .
๐
โโ, ๐1 ๐1, ๐1 โฆ ๐๐ , ๐๐+1 โฆ ๐๐, ๐๐ ๐๐, โ
Int ๐ : elementary interval
corresponding to ๐.
๐ : a leaf
Query time
๐(log ๐ + ๐)
BST search #reported
intervals
High storage if the intervals overlap
a lot.
๐ ๐2 possible!
Store an Interval As High as Possible
๐2๐1 ๐3 ๐4 ๐5
๐ฃ
๐
Interval ๐ is stored five times at
๐1, ๐2, ๐3 , ๐4, ๐5.
Store an Interval As High as Possible
๐2๐1 ๐3 ๐4 ๐5
๐ฃ
๐
Interval ๐ is stored five times at
๐1, ๐2, ๐3 , ๐4, ๐5.
Store an Interval As High as Possible
๐2๐1 ๐3 ๐4 ๐5
๐ฃ
๐
Interval ๐ is stored five times at
๐1, ๐2, ๐3 , ๐4, ๐5.
Observation A search path ends at
๐1, ๐2, ๐3 , ๐4 if and only if
it passes through ๐ฃ.
Store an Interval As High as Possible
๐2๐1 ๐3 ๐4 ๐5
๐ฃ
๐
Interval ๐ is stored five times at
๐1, ๐2, ๐3 , ๐4, ๐5.
Why not store ๐ only two times
at ๐ฃ and ๐5?
Observation A search path ends at
๐1, ๐2, ๐3 , ๐4 if and only if
it passes through ๐ฃ.
Store an Interval As High as Possible
๐2๐1 ๐3 ๐4 ๐5
๐ฃ
๐
Interval ๐ is stored five times at
๐1, ๐2, ๐3 , ๐4, ๐5.
Why not store ๐ only two times
at ๐ฃ and ๐5?
Observation A search path ends at
๐1, ๐2, ๐3 , ๐4 if and only if
it passes through ๐ฃ.
Idea: Store a segment ๐ at the fewest nodes whose corresponding intervals
form a partitioning of ๐ .
Store an Interval As High as Possible
๐2๐1 ๐3 ๐4 ๐5
๐ฃ
๐
Interval ๐ is stored five times at
๐1, ๐2, ๐3 , ๐4, ๐5.
Why not store ๐ only two times
at ๐ฃ and ๐5?
Observation A search path ends at
๐1, ๐2, ๐3 , ๐4 if and only if
it passes through ๐ฃ.
Idea: Store a segment ๐ at the fewest nodes whose corresponding intervals
form a partitioning of ๐ .
These nodes must be as high as possible in the tree.
Segment Tree
(โโ,โ)
(โโ, ๐4]
[๐1, ๐1] (๐2, ๐3)(โโ, ๐1) [๐2, ๐2] [๐3, ๐3] [๐4, ๐4] [๐5, ๐5] [๐6, ๐6] [๐7, ๐7](๐3, ๐4) (๐4, ๐5) (๐5, ๐6) (๐7, โ)(๐6, ๐7)(๐1, ๐2)
(โโ, ๐1] (๐1, ๐2] (๐2, ๐3] (๐3, ๐4] (๐4, ๐5] (๐5, ๐6] (๐6, ๐7]
(โโ, ๐2] (๐2, ๐4] (๐4, ๐6] (๐6, โ)
(๐4, โ)
๐1 ๐2 ๐7๐6๐5๐4๐3๐ 1 ๐ 3
๐ 2 ๐ 4
๐ 5
Segment Tree
(โโ,โ)
(โโ, ๐4]
[๐1, ๐1] (๐2, ๐3)(โโ, ๐1) [๐2, ๐2] [๐3, ๐3] [๐4, ๐4] [๐5, ๐5] [๐6, ๐6] [๐7, ๐7](๐3, ๐4) (๐4, ๐5) (๐5, ๐6) (๐7, โ)(๐6, ๐7)(๐1, ๐2)
(โโ, ๐1] (๐1, ๐2] (๐2, ๐3] (๐3, ๐4] (๐4, ๐5] (๐5, ๐6] (๐6, ๐7]
(โโ, ๐2] (๐2, ๐4] (๐4, ๐6] (๐6, โ)
(๐4, โ)
๐1 ๐2 ๐7๐6๐5๐4๐3๐ 1 ๐ 3
๐ 2 ๐ 4
๐ 5
{๐ 1} {๐ 1}{๐ 3} {๐ 3, ๐ 4}
{๐ 2, ๐ 5} {๐ 5}
Tree Structure
Leaves โ elementary intervals (left-to-right)
Tree Structure
Leaves โ elementary intervals (left-to-right)
๐ฃ
Tree Structure
Leaves โ elementary intervals (left-to-right)
Internal node ๐ฃ โ union Int(๐ฃ) of elementary intervals at the leaves in the
subtree ๐ฏ(๐ฃ) rooted at ๐ฃ.
๐ฃ
Tree Structure
Leaves โ elementary intervals (left-to-right)
Internal node ๐ฃ โ union Int(๐ฃ) of elementary intervals at the leaves in the
subtree ๐ฏ(๐ฃ) rooted at ๐ฃ.
๐ฃ
At ๐ฃ stores Int(๐ฃ) and the canonical subset (as a linked list) defined below:
Tree Structure
Leaves โ elementary intervals (left-to-right)
Internal node ๐ฃ โ union Int(๐ฃ) of elementary intervals at the leaves in the
subtree ๐ฏ(๐ฃ) rooted at ๐ฃ.
๐ฃ
At ๐ฃ stores Int(๐ฃ) and the canonical subset (as a linked list) defined below:
๐ถ ๐ฃ = ๐ฅ, ๐ฅโฒ โ ๐ผ Int ๐ฃ โ [๐ฅ, ๐ฅโฒ]and Int(parent ๐ฃ) โ [๐ฅ, ๐ฅโฒ]}
Tree Structure
Leaves โ elementary intervals (left-to-right)
Internal node ๐ฃ โ union Int(๐ฃ) of elementary intervals at the leaves in the
subtree ๐ฏ(๐ฃ) rooted at ๐ฃ.
๐ฃ
At ๐ฃ stores Int(๐ฃ) and the canonical subset (as a linked list) defined below:
๐ถ ๐ฃ = ๐ฅ, ๐ฅโฒ โ ๐ผ Int ๐ฃ โ [๐ฅ, ๐ฅโฒ]and Int(parent ๐ฃ) โ [๐ฅ, ๐ฅโฒ]}
Store intervals at nodes
as high as possible.
A Closer Look at Storage
๐ถ ๐ฃ = ๐ฅ, ๐ฅโฒ โ ๐ผ Int ๐ฃ โ [๐ฅ, ๐ฅโฒ] and Int(parent(๐ฃ)) โ [๐ฅ, ๐ฅโฒ]}
๐ข
๐ฃ
Int ๐ข โ [๐ฅ, ๐ฅโฒ]
Int ๐ฃ โ [๐ฅ, ๐ฅโฒ]๐ถ(๐ฃ):(๐ฅ, ๐ฅโฒ)
Linked list
Number of Leaves
๐ = ๐ผ : #segments
๐๐ , ๐๐+1 ๐โ 1
[๐๐ , ๐๐] ๐
(โโ, ๐1) 1
(๐๐, โ) 1
๐ โค 2๐: #distinct endpoints
Number of Leaves
โข 2๐ + 1 โค 4๐ + 1 leaves
๐ = ๐ผ : #segments
๐๐ , ๐๐+1 ๐โ 1
[๐๐ , ๐๐] ๐
(โโ, ๐1) 1
(๐๐, โ) 1
๐ โค 2๐: #distinct endpoints
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
Then ๐ฃ2 must be a sibling of either ๐ฃ1 or ๐ฃ3.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
Then ๐ฃ2 must be a sibling of either ๐ฃ1 or ๐ฃ3.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)Suppose its sibling is ๐ฃ1 without loss of generality.
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
Then ๐ฃ2 must be a sibling of either ๐ฃ1 or ๐ฃ3.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)Suppose its sibling is ๐ฃ1 without loss of generality.
Int ๐ฃ1 โ [๐ฅ, ๐ฅโฒ]
Int ๐ฃ2 โ [๐ฅ, ๐ฅโฒ]
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
Then ๐ฃ2 must be a sibling of either ๐ฃ1 or ๐ฃ3.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)Suppose its sibling is ๐ฃ1 without loss of generality.
Int ๐ฃ1 โ [๐ฅ, ๐ฅโฒ]
Int ๐ฃ2 โ [๐ฅ, ๐ฅโฒ]
Int(parent(๐ฃ2)) = Int(๐ฃ1) โช Int(๐ฃ2) โ [๐ฅ, ๐ฅโฒ]
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
Then ๐ฃ2 must be a sibling of either ๐ฃ1 or ๐ฃ3.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)Suppose its sibling is ๐ฃ1 without loss of generality.
Int ๐ฃ1 โ [๐ฅ, ๐ฅโฒ]
Int ๐ฃ2 โ [๐ฅ, ๐ฅโฒ]
Int(parent(๐ฃ2)) = Int(๐ฃ1) โช Int(๐ฃ2) โ [๐ฅ, ๐ฅโฒ]
[๐ฅ, ๐ฅโฒ] should be stored at parent(๐ฃ2) or above instead of at ๐ฃ2. Contradiction.
Storage of an Interval
Claim Each interval [๐ฅ, ๐ฅโฒ] โ ๐ผ is stored at โค 2 nodes at any depth.
Proof Suppose the interval is stored at the nodes ๐ฃ1, ๐ฃ2, โฆ , ๐ฃ๐, ๐ โฅ 3, at
the same depth in the left to right order.
Then ๐ฃ2 must be a sibling of either ๐ฃ1 or ๐ฃ3.
๐ฃ1 ๐ฃ2 ๐ฃ3
parent(๐ฃ2)Suppose its sibling is ๐ฃ1 without loss of generality.
Int ๐ฃ1 โ [๐ฅ, ๐ฅโฒ]
Int ๐ฃ2 โ [๐ฅ, ๐ฅโฒ]
Int(parent(๐ฃ2)) = Int(๐ฃ1) โช Int(๐ฃ2) โ [๐ฅ, ๐ฅโฒ]
[๐ฅ, ๐ฅโฒ] should be stored at parent(๐ฃ2) or above instead of at ๐ฃ2. Contradiction.
Total Storage
Following the claim, any interval is stored at most twice at any
given length.
Total Storage
Following the claim, any interval is stored at most twice at any
given length.
The required storage at each depth is ๐(๐).
Total Storage
Following the claim, any interval is stored at most twice at any
given length.
The required storage at each depth is ๐(๐).
Maximum tree depth (i.e., height) is ๐(log ๐).
Total Storage
Following the claim, any interval is stored at most twice at any
given length.
The required storage at each depth is ๐(๐).
Maximum tree depth (i.e., height) is ๐(log ๐).
๐(๐ log ๐)
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
root
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
๐๐ฅ
Example: ๐๐ฅ
root
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
๐๐ฅ
Example: ๐๐ฅQuerySegmentTree(root, ๐๐ฅ)
root
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
๐๐ฅ
Example: ๐๐ฅQuerySegmentTree(root, ๐๐ฅ)
root
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
๐๐ฅ
Example: ๐๐ฅ
Output in order:
๐ 2, ๐ 5, ๐ 1
QuerySegmentTree(root, ๐๐ฅ)
root
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
๐๐ฅ
Example: ๐๐ฅ
Output in order:
๐ 2, ๐ 5, ๐ 1
Query time:
๐(log ๐ + ๐)
QuerySegmentTree(root, ๐๐ฅ)
root
Query Algorithm
QuerySegmentTree(๐ฃ, ๐๐ฅ)
1. report all the intervals in ๐ถ(๐ฃ) // canonical subset2. if ๐ฃ is not a leaf3. then if ๐๐ฅ โ Int(๐๐(๐ฃ))4. then QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)5. else QuerySegmentTree(๐๐ ๐ฃ , ๐๐ฅ)
๐๐ฅ
Example: ๐๐ฅ
Output in order:
๐ 2, ๐ 5, ๐ 1
Query time:
๐(log ๐ + ๐)
#reported intervals
QuerySegmentTree(root, ๐๐ฅ)
root
Segment Tree Construction
Sort endpoints from ๐ผ to yield elementary intervals.
Segment Tree Construction
Sort endpoints from ๐ผ to yield elementary intervals.
๐(๐ log ๐)
Segment Tree Construction
Sort endpoints from ๐ผ to yield elementary intervals.
Construct a balanced BST in a bottom-up way.
๐(๐ log ๐)
Segment Tree Construction
Sort endpoints from ๐ผ to yield elementary intervals.
Construct a balanced BST in a bottom-up way.
Determine interval ๐ผ(๐ฃ) for each node ๐ฃ.
๐(๐ log ๐)
Segment Tree Construction
Sort endpoints from ๐ผ to yield elementary intervals.
Construct a balanced BST in a bottom-up way.
Determine interval ๐ผ(๐ฃ) for each node ๐ฃ.
๐(๐ log ๐)
๐(๐) for all the nodes together
Segment Tree Construction
Sort endpoints from ๐ผ to yield elementary intervals.
Construct a balanced BST in a bottom-up way.
Determine interval ๐ผ(๐ฃ) for each node ๐ฃ.
Compute canonical subsets by inserting original intervals [๐ฅ, ๐ฅโฒ]from ๐ผ one by one.
๐(๐ log ๐)
๐(๐) for all the nodes together
Segment Tree Insertion
InsertSegmentTree(๐ฃ, [๐ฅ, ๐ฅโฒ])
1. if Int(๐ฃ)โ [๐ฅ, ๐ฅโฒ] // Int(parent(๐ฃ))โ [๐ฅ, ๐ฅโฒ] holds2. then store [๐ฅ, ๐ฅโฒ] at ๐ฃ3. else if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 4. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
5. if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 6. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
Segment Tree Insertion
InsertSegmentTree(๐ฃ, [๐ฅ, ๐ฅโฒ])
1. if Int(๐ฃ)โ [๐ฅ, ๐ฅโฒ] // Int(parent(๐ฃ))โ [๐ฅ, ๐ฅโฒ] holds2. then store [๐ฅ, ๐ฅโฒ] at ๐ฃ3. else if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 4. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
5. if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 6. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
โข At each visited node ๐ฃ, either [๐ฅ, ๐ฅโฒ] is stored or Int(๐ฃ) contains an endpoint
of [๐ฅ, ๐ฅโฒ].
Segment Tree Insertion
InsertSegmentTree(๐ฃ, [๐ฅ, ๐ฅโฒ])
1. if Int(๐ฃ)โ [๐ฅ, ๐ฅโฒ] // Int(parent(๐ฃ))โ [๐ฅ, ๐ฅโฒ] holds2. then store [๐ฅ, ๐ฅโฒ] at ๐ฃ3. else if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 4. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
5. if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 6. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
โข At each visited node ๐ฃ, either [๐ฅ, ๐ฅโฒ] is stored or Int(๐ฃ) contains an endpoint
of [๐ฅ, ๐ฅโฒ].
An interval is stored โค 2 times at each level.
Segment Tree Insertion
InsertSegmentTree(๐ฃ, [๐ฅ, ๐ฅโฒ])
1. if Int(๐ฃ)โ [๐ฅ, ๐ฅโฒ] // Int(parent(๐ฃ))โ [๐ฅ, ๐ฅโฒ] holds2. then store [๐ฅ, ๐ฅโฒ] at ๐ฃ3. else if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 4. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
5. if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 6. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
โข At each visited node ๐ฃ, either [๐ฅ, ๐ฅโฒ] is stored or Int(๐ฃ) contains an endpoint
of [๐ฅ, ๐ฅโฒ].
An interval is stored โค 2 times at each level.
At each depth, there exist
Segment Tree Insertion
InsertSegmentTree(๐ฃ, [๐ฅ, ๐ฅโฒ])
1. if Int(๐ฃ)โ [๐ฅ, ๐ฅโฒ] // Int(parent(๐ฃ))โ [๐ฅ, ๐ฅโฒ] holds2. then store [๐ฅ, ๐ฅโฒ] at ๐ฃ3. else if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 4. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
5. if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 6. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
โข At each visited node ๐ฃ, either [๐ฅ, ๐ฅโฒ] is stored or Int(๐ฃ) contains an endpoint
of [๐ฅ, ๐ฅโฒ].
An interval is stored โค 2 times at each level.
At each depth, there exist
โค 1 node ๐ข such that ๐ฅ โ Int(๐ข)
Segment Tree Insertion
InsertSegmentTree(๐ฃ, [๐ฅ, ๐ฅโฒ])
1. if Int(๐ฃ)โ [๐ฅ, ๐ฅโฒ] // Int(parent(๐ฃ))โ [๐ฅ, ๐ฅโฒ] holds2. then store [๐ฅ, ๐ฅโฒ] at ๐ฃ3. else if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 4. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
5. if Int(๐๐ ๐ฃ )โฉ [๐ฅ, ๐ฅโฒ] โ โ 6. then InsertSegmentTree(๐๐ ๐ฃ , [๐ฅ, ๐ฅโฒ])
โข At each visited node ๐ฃ, either [๐ฅ, ๐ฅโฒ] is stored or Int(๐ฃ) contains an endpoint
of [๐ฅ, ๐ฅโฒ].
An interval is stored โค 2 times at each level.
At each depth, there exist
โค 1 node ๐ข such that ๐ฅ โ Int(๐ข)
โค 1 node ๐ขโฒ such that ๐ฅโฒ โ Int(๐ขโฒ)
Construction Time
โข โค 2 storage actions + โค 2 containments
Construction Time
โข โค 2 storage actions + โค 2 containments
โค 4 nodes visited per level.
Construction Time
โข โค 2 storage actions + โค 2 containments
โค 4 nodes visited per level.
๐ log ๐ time to insert an interval.me to insert an interval.
Construction Time
โข โค 2 storage actions + โค 2 containments
โค 4 nodes visited per level.
๐ log ๐ time to insert an interval.me to insert an interval.
๐ ๐ log ๐ time for segment tree construction.
Construction Time
โข โค 2 storage actions + โค 2 containments
โค 4 nodes visited per level.
๐ log ๐ time to insert an interval.me to insert an interval.
๐ ๐ log ๐ time for segment tree construction.
Compared with an interval tree, a segment tree has
the same query time ๐(log ๐ + ๐)
a larger storage ๐(๐ log ๐) than ๐ ๐ ,
Construction Time
โข โค 2 storage actions + โค 2 containments
โค 4 nodes visited per level.
๐ log ๐ time to insert an interval.me to insert an interval.
๐ ๐ log ๐ time for segment tree construction.
Compared with an interval tree, a segment tree has
the same query time ๐(log ๐ + ๐)
a larger storage ๐(๐ log ๐) than ๐ ๐ ,
but it allows to answer more complicated queries.
Back to Windowing
Query segment: ๐ = ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
๐(๐ฃ2) ๐(๐ฃ3)
๐(๐ฃ1)
๐ 1
๐ 3
๐ 2
๐ 4
๐ 5
๐ 6
๐ 7
๐ฃ1
๐ฃ2 ๐ฃ3
๐ถ ๐ฃ1 = {๐ 3}
๐ถ ๐ฃ3 = {๐ 4, ๐ 6}๐ถ ๐ฃ2 = {๐ 1, ๐ 2}
Over ๐ arbitrarily oriented segments
Back to Windowing
Query segment: ๐ = ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
Construct a segment tree ๐ฏ.
๐(๐ฃ2) ๐(๐ฃ3)
๐(๐ฃ1)
๐ 1
๐ 3
๐ 2
๐ 4
๐ 5
๐ 6
๐ 7
๐ฃ1
๐ฃ2 ๐ฃ3
๐ถ ๐ฃ1 = {๐ 3}
๐ถ ๐ฃ3 = {๐ 4, ๐ 6}๐ถ ๐ฃ2 = {๐ 1, ๐ 2}
Over ๐ arbitrarily oriented segments
Back to Windowing
Query segment: ๐ = ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
Construct a segment tree ๐ฏ.
On the ๐ฅ-intervals of the segments in ๐.
Canonical subset ๐ถ(๐ฃ) at a vertex ๐ฃ store segments rather than their ๐ฅ-intervals.
๐(๐ฃ2) ๐(๐ฃ3)
๐(๐ฃ1)
๐ 1
๐ 3
๐ 2
๐ 4
๐ 5
๐ 6
๐ 7
๐ฃ1
๐ฃ2 ๐ฃ3
๐ถ ๐ฃ1 = {๐ 3}
๐ถ ๐ฃ3 = {๐ 4, ๐ 6}๐ถ ๐ฃ2 = {๐ 1, ๐ 2}
Over ๐ arbitrarily oriented segments
Back to Windowing
Query segment: ๐ = ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
Construct a segment tree ๐ฏ.
Segment ๐ โ ๐ถ(๐ฃ) if it crosses the slab ๐ ๐ฃ : Int(๐ฃ) ร (โโ,โ)but does not cross its parentโs slab.
On the ๐ฅ-intervals of the segments in ๐.
Canonical subset ๐ถ(๐ฃ) at a vertex ๐ฃ store segments rather than their ๐ฅ-intervals.
๐(๐ฃ2) ๐(๐ฃ3)
๐(๐ฃ1)
๐ 1
๐ 3
๐ 2
๐ 4
๐ 5
๐ 6
๐ 7
๐ฃ1
๐ฃ2 ๐ฃ3
๐ถ ๐ฃ1 = {๐ 3}
๐ถ ๐ฃ3 = {๐ 4, ๐ 6}๐ถ ๐ฃ2 = {๐ 1, ๐ 2}
Over ๐ arbitrarily oriented segments
Back to Windowing
Query segment: ๐ = ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
๐
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
Construct a segment tree ๐ฏ.
Segment ๐ โ ๐ถ(๐ฃ) if it crosses the slab ๐ ๐ฃ : Int(๐ฃ) ร (โโ,โ)but does not cross its parentโs slab.
On the ๐ฅ-intervals of the segments in ๐.
Canonical subset ๐ถ(๐ฃ) at a vertex ๐ฃ store segments rather than their ๐ฅ-intervals.
๐(๐ฃ2) ๐(๐ฃ3)
๐(๐ฃ1)
๐ 1
๐ 3
๐ 2
๐ 4
๐ 5
๐ 6
๐ 7
๐ฃ1
๐ฃ2 ๐ฃ3
๐ถ ๐ฃ1 = {๐ 3}
๐ถ ๐ฃ3 = {๐ 4, ๐ 6}๐ถ ๐ฃ2 = {๐ 1, ๐ 2}
Over ๐ arbitrarily oriented segments
Segments on the Search Path
โข Search with ๐๐ฅ in ๐ฏ. (โโ,โ)
Segment
tree
Segments on the Search Path
โข Search with ๐๐ฅ in ๐ฏ. (โโ,โ)
๐ฃ
Segment
tree
Segments on the Search Path
โข Search with ๐๐ฅ in ๐ฏ. (โโ,โ)
๐ฃ
Segment
treeโข ๐(log๐) canonical sets together include
all the segments intersected by the
vertical line ๐ฅ = ๐๐ฅ.
Segments on the Search Path
โข Search with ๐๐ฅ in ๐ฏ. (โโ,โ)
๐ฃ
Segment
tree
๐ถ(๐ฃ)
โข ๐ฃ is a node on the search path.
โข ๐(log๐) canonical sets together include
all the segments intersected by the
vertical line ๐ฅ = ๐๐ฅ.
Segments on the Search Path
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
๐
๐
โข Search with ๐๐ฅ in ๐ฏ. (โโ,โ)
๐ฃ
Segment
tree
๐ถ(๐ฃ)
โข Segment ๐ โ ๐ถ(๐ฃ) is intersected by ๐ iff
โข ๐ฃ is a node on the search path.
โข ๐(log๐) canonical sets together include
all the segments intersected by the
vertical line ๐ฅ = ๐๐ฅ.
Segments on the Search Path
(๐๐ฅ, ๐๐ฆ)
(๐๐ฅ, ๐๐ฆโฒ )
๐
๐
โข Search with ๐๐ฅ in ๐ฏ. (โโ,โ)
๐ฃ
Segment
tree
๐ถ(๐ฃ)
โข Segment ๐ โ ๐ถ(๐ฃ) is intersected by ๐ iff
โข ๐ฃ is a node on the search path.
(๐๐ฅ, ๐๐ฆ) below ๐ and (๐๐ฅ, ๐๐ฆโฒ ) above ๐
โข ๐(log๐) canonical sets together include
all the segments intersected by the
vertical line ๐ฅ = ๐๐ฅ.
Storage of a Canonical Set
โข Segments in ๐ถ(๐ฃ) do not intersect each other.(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข Each segment is over an ๐ฅ-interval containing
Int ๐ฃ .
Int(๐ฃ)
๐ 1
๐ 2
๐ 3
๐ 4
๐ 5
Slab
Storage of a Canonical Set
โข Segments in ๐ถ(๐ฃ) do not intersect each other.(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข These segments span the slab Int ๐ฃ ร [โโ,โ].
โข Each segment is over an ๐ฅ-interval containing
Int ๐ฃ .
Int(๐ฃ)
๐ 1
๐ 2
๐ 3
๐ 4
๐ 5
โข They do not intersect each other in the interior.Slab
Storage of a Canonical Set
โข Segments in ๐ถ(๐ฃ) do not intersect each other.(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข These segments span the slab Int ๐ฃ ร [โโ,โ].
โข Each segment is over an ๐ฅ-interval containing
Int ๐ฃ .
Int(๐ฃ)
๐ 1
๐ 2
๐ 3
๐ 4
๐ 5
โข They do not intersect each other in the interior.
โข Store the segments in a balanced BST โฌ ๐ฃ in
the vertical order.
Slab
Storage of a Canonical Set
โข Segments in ๐ถ(๐ฃ) do not intersect each other.(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข These segments span the slab Int ๐ฃ ร [โโ,โ].
โข Each segment is over an ๐ฅ-interval containing
Int ๐ฃ .
Int(๐ฃ)
๐ 1
๐ 2
๐ 3
๐ 4
๐ 5
โข They do not intersect each other in the interior.
โข Store the segments in a balanced BST โฌ ๐ฃ in
the vertical order.
๐ 3
๐ 5 ๐ 2
๐ 1๐ 4
Slab
associate structure โฌ ๐ฃ
Storage of a Canonical Set
โข Segments in ๐ถ(๐ฃ) do not intersect each other.(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข These segments span the slab Int ๐ฃ ร [โโ,โ].
โข Each segment is over an ๐ฅ-interval containing
Int ๐ฃ .
Int(๐ฃ)
๐ 1
๐ 2
๐ 3
๐ 4
๐ 5
โข They do not intersect each other in the interior.
โข Store the segments in a balanced BST โฌ ๐ฃ in
the vertical order.
๐ 3
๐ 5 ๐ 2
๐ 1๐ 4
๐(log ๐ + ๐๐ฃ) query time
within โฌ ๐ฃ
Slab
#intersected
segments in ๐ถ(๐ฃ)
associate structure โฌ ๐ฃ
Segment Tree Storage Summary
The set ๐ of segments is stored in a segment tree ๐ฏ based on
their ๐ฅ-intervals.
The canonical subset ๐ถ(๐ฃ) of every internal node ๐ฃ in ๐ฏ is stored in
a BST โฌ(๐ฃ) based on
the vertical order within the slab Int ๐ฃ ร [โโ,โ].
Total storage: ๐(๐ log ๐)
Construction time: ๐(๐ log ๐)
Query Algorithm
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
(โโ,โ)
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โฌ ๐ฃ
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โฌ ๐ฃ
(๐๐ฅ, ๐๐ฆ)
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โฌ ๐ฃ
(๐๐ฅ, ๐๐ฆ) (๐๐ฅ, ๐๐ฆโฒ )
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โฆ
โฌ ๐ฃ
(๐๐ฅ, ๐๐ฆ) (๐๐ฅ, ๐๐ฆโฒ )
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โฆ
segments satisfying the query
โฌ ๐ฃ
(๐๐ฅ, ๐๐ฆ) (๐๐ฅ, ๐๐ฆโฒ )
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข ๐(log ๐) nodes on the search path, each requiring
such a search.
โข The search takes ๐(log ๐ + ๐๐ฃ) time.
โฆ
segments satisfying the query
โฌ ๐ฃ
(๐๐ฅ, ๐๐ฆ) (๐๐ฅ, ๐๐ฆโฒ )
Query Algorithm
Search with ๐๐ฅ in a segment tree ๐ฏ.
Query object: a vertical line segment ๐: ๐๐ฅ ร [๐๐ฆ, ๐๐ฆโฒ ]
Set ๐ = ๐ 1, ๐ 2, โฆ , ๐ ๐ of arbitrarily oriented segments
At every node ๐ฃ on the search path, search with the two endpoints
of ๐ to report segments in ๐ถ(๐ฃ) intersected by ๐.
(โโ,โ)
๐ฃ๐ถ(๐ฃ)
โข ๐(log ๐) nodes on the search path, each requiring
such a search.
โข The search takes ๐(log ๐ + ๐๐ฃ) time.
Query time: ๐(log2๐ + ๐)โฆ
segments satisfying the query
โฌ ๐ฃ
(๐๐ฅ, ๐๐ฆ) (๐๐ฅ, ๐๐ฆโฒ )