Upload
others
View
7
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
ℬ 𝑣
(𝑞𝑥, 𝑞𝑦) (𝑞𝑥, 𝑞𝑦′ )