CSE 202 Homework 1 Solutions
1 Kleinberg & Tardos, problem 4, page 247. Coulomb forces among charged particles.
Let
Q = (q1, . . ., qn, 0, . . ., 0
| {z }
n-1
)
P = (- 1
(n - 1)2, . . . , -
1 22
, -
1 21
, 0,
1 21
,
1 22
, . . . ,
1
(n - 1)2).
Both vectors have 2n - 1 elements. Let R = (r0, . . . , r4n-4) = Q ⊗ P be the convolution of Q, P,
which can be computed in O(n lg n)
...[Show More]
CSE 202 Homework 1 Solutions
1 Kleinberg & Tardos, problem 4, page 247. Coulomb forces among charged particles.
Let
Q = (q1, . . ., qn, 0, . . ., 0
| {z }
n-1
)
P = (- 1
(n - 1)2, . . . , -
1 22
, -
1 21
, 0,
1 21
,
1 22
, . . . ,
1
(n - 1)2).
Both vectors have 2n - 1 elements. Let R = (r0, . . . , r4n-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 Fj = Cqjrn+j-2 for
j = 1, . . . , n.
2 Kleinberg & Tardos, problem 5, page 248. Hidden surface removal
2.1 Solution 1
• n non-vertical lines in the plane L1, L2, ..., Ln
• No three lines meet at a single point
• Li is specified by equation y = ai · x + bi
• Li is uppermost at x-coordinate x0 if ai · x0 + bi > aj · x0 + bj for all j 6= i
• Li 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
[Show Less]