CSE 202 Homework 1 Solutions
1
Let
Q
= (
q
1
, . . ., q
n
,
0
, . . .,
0
b
B±
²
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
2.1
Solution 1
•
n
non-vertical 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
n
=
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 divide-and-conquer 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