CSE 202 Homework 1 Solutions
1
Kleinberg & Tardos, problem 4, page 247. Coulomb forces among charged particles.
Let
Q
= (
q
1
,...,q
n
,
0
,...,
0
bracehtipupleft
bracehtipdownrightbracehtipdownleft
bracehtipupright
n
−
1
)
P
= (
−
1
(
n
−
1)
2
,...,
−
1
2
2
,
−
1
1
2
,
0
,
1
1
2
,
1
2
2
,...,
1
(
n
−
1)
2
)
.
Both vectors have
2
n
−
1
elements. Let
R
= (
r
0
,...,r
4
n
−
4
) =
Q
⊗
P
be the convolution of
Q,P
,
which can be computed in
O
(
n
lg
n
)
time using FFT. The answer we seek is
F
j
=
Cq
j
r
n
+
j
−
2
for
j
= 1
,...,n
.
2
Kleinberg & Tardos, problem 5, page 248. Hidden surface removal
2.1
Solution 1
•
n
nonvertical lines in the plane
L
1
,
L
2
, ...,
L
n
•
No three lines meet at a single point
•
L
i
is specified by equation
y
=
a
i
·
x
+
b
i
•
L
i
is uppermost at
x
coordinate
x
0
if
a
i
·
x
0
+
b
i
> a
j
·
x
0
+
b
j
for all
j
negationslash
=
i
•
L
i
is visible if it is uppermost at some
x
coordinate
Given
n
input lines, we want to find the
visible envelope
, i.e. all visible half lines and line
segments.
We use the divideandconquer approach. To get a high level intuition, we describe the key ideas
as follows. First, we sort the input lines by slopes to facilitate the analysis of the visible envelope.
Then we split the set of input lines into two equal parts (i.e. the “divide” step), and recursively
compute the visible envelope for each part (i.e. the “conquer” step). The main subtlety is on how
to efficiently combine the two visible envelopes into one single visible envelope of the original
input lines (i.e. the “combine” step). Here, we leverage the fact that the slopes in the second visible
envelope are larger than the slopes in the first visible envelope because we sorted the input lines
by slopes. This guarantees that the two visible envelopes meet at
exactly
one intersection point.
By exploiting the sorted order of slopes, this intersection point can be determined in linear time.
Finally, we take this intersection point as the pivot to merge the two visible envelopes.
Full details of the algorithm are as follows.
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Figure 1:
L
1
,
L
3
,
L
4
, and
L
5
are visible.
L
2
is hidden. The intersections points are
p
1
,
p
2
, and
p
3
in
the order of
x
coordinate. The
visible envelope
is (
L
1
,
p
1
,
p
2
,
p
3
,
L
5
).
1. First, sort the input lines by slopes with time complexity
O
(
n
log
n
)
. Among the lines with
the same slope, keep only the one with largest
y
intercept (since the others are hidden by this
line). From now on, we suppose
L
1
,
L
2
, ...,
L
n
are sorted by unique slopes.
2. We design an algorithm that returns the set of visible lines in increasing slopes (
L
i
1
,
L
i
2
,
...,
L
im
), together with the set of intersection points (
p
i
1
,
p
i
2
, ...,
p
i
(
m
−
1)
) where
p
ij
is the
intersection of
L
ij
and
L
i
(
j
+1)
. See Figure 1 for an example.
Note that since the slopes of
L
i
1
,
L
i
2
, ...,
L
im
are increasing in that order, the
x
coordinates
of
p
i
1
,
p
i
2
, ...,
p
i
(
m
−
1)
are also increasing in that order.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '06
 Hu
 Big O notation, Line segment, Lj

Click to edit the document details