hw1_sol

hw1_sol - CSE 202 Homework 1 Solutions 1 Kleinberg &...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 202 Homework 1 Solutions 1 Let Q = ( q 1 , . . ., q n , 0 , . . ., 0 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/26/2012 for the course CSE 202 taught by Professor Hu during the Spring '06 term at UCSD.

Page1 / 5

hw1_sol - CSE 202 Homework 1 Solutions 1 Kleinberg &...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online