























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A portion of the slides from a university course, cs 5633, analysis of algorithms, taught in spring 2004. The slides cover computational geometry and range searching in 1d and 2d. Topics include fundamental objects, basic structures, orthogonal range searching, and 1d range trees. The slides also discuss the analysis of these algorithms in terms of query time, preprocessing time, and space.
Typology: Study notes
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























CS 5633 Analysis of Algorithms
Carola Wenk
Slides courtesy of Charles Leiserson with small
changes by Carola Wenk
CS 5633 Analysis of Algorithms
Algorithms for solving “geometric problems”in 2D and higher.Fundamental objects:
point
line segment
line
Basic structures:
polygon
point set
CS 5633 Analysis of Algorithms
Input:
n^ points in
d^ dimensions
n^ records
each with
d^ numeric fields
Query:
Axis-aligned
box
(in 2D, a rectangle)
CS 5633 Analysis of Algorithms
Input:
n^ points in
d^ dimensions
Query:
Axis-aligned
box
(in 2D, a rectangle)
Static data structure
CS 5633 Analysis of Algorithms
In 1D, the query is an interval:New solution that extends to higher dimensions:• Balanced binary search tree
leaves
of the tree.
x^ stores in
key [
x ] the maximum
key of any leaf in the left subtree of
x.
CS 5633 Analysis of Algorithms
8
3/22/
11
6 6
8 12812
1414
1717
26 26
35 35
41 41
4242
4343 5959
6161
key [ x
] is the maximum key of any leaf in the left subtree of
x.
CS 5633 Analysis of Algorithms 1212 8 12812
1414
1717
26 26
35 35
4141 2626 1414
11
6 6
4242
4343 5959
6161
6 6
41 41
5959
11
1212 8 12812
1414
1717
26 26
35 35
4141 2626 14 14
35 35
4343 4242
88
1717
R^ ANGE
x^ x ≤^ x^
^ x
CS 5633 Analysis of Algorithms
root
split node
CS 5633 Analysis of Algorithms
1D-R
ANGE
-Q^ UERY
( T , [ x
,^ x ]) 12
[ find the split node
]
//^ w^ is now the split node if^ w^ is a leaf^ then output the leaf
w^ if^ x
≤^ key 1 [ w ]^ ≤ x^2
else^ v
←^ left
[ w ]^
// Left traversal
while
v^ is not a leaf do if^ x ≤^1 key [ v
] then^ output the subtree rooted at
right
[ v ]
v^ ←^ left
[ v ] else^ v
←^ right
[ v ]
output the leaf
v^ if^ x
≤^ key 1 [ v ]^ ≤^
x^2
[ symmetrically for right traversal
]
w
CS 5633 Analysis of Algorithms
Query time:
Answer to range query represented
by O(log
n ) subtrees found in O(log
n ) time.
Thus:• Can test for points in interval in O(log
n ) time.
k^ points in interval in
O(k + log
n ) time.
n ) time (exercise) Space:
O( n
Preprocessing time:
O( n
log^
n )
CS 5633 Analysis of Algorithms
Store a 3/22/
primary
1D range tree for all the points
based on
Thus in O(log
n ) time we can find O(log
n ) subtrees
representing the points with proper
x -coordinate.
How to restrict to points with proper
y -coordinate?
CS 5633 Analysis of Algorithms
Idea:
In primary 1D range tree of
x -coordinate,
every node stores a
secondary
1D range tree
based on
y -coordinate for all points in the subtree of the node. Recursively search within each.
CS 5633 Analysis of Algorithms
Query time:
O( k
d^ n ) to report
k^ points.
Space:
O( n
d log
Preprocessing time:
O( n
d log
Each node of the secondary
y -structure stores
a tertiary
z -structure representing the points in the subtree rooted at the node, etc. Best data structure to date:Query time:
O( k
d^ – 1^ n
) to report
k^ points.
Space:
O( n
(log
n^ / log log
d^ – 1 n )
Preprocessing time:
O( n
d log
CS 5633 Analysis of Algorithms
Given two vectors
v = (^1
x ,^ y^1
) and 1
v = (^2
x ,^ y^2
is their counterclockwise angle
θ
-^ convex
-^ reflex
(> 180º), or
v^2 θ v^1
v^1 v^2 θ convex
reflex
Crossproduct
v ×^1
v =^2
xy^1
-^ y 2
x 1 2 = | v^1
| | v | sin^2
θ^.
Thus, sign(
v ×^1
v ) = sign(sin^2
θ)^
0 if
θ^ convex, < 0 if
θ^ reflex, = 0 if
θ^ borderline.