hw4_sol - CSE 413 Homework 4 Solution Guide Problem 1 The...

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

View Full Document Right Arrow Icon
CSE 413 Homework 4 Solution Guide Problem 1 The points for this problem are not given in sorted order. The algorithm should be O(n log n) time, and it would be convenient to sort the points. Given the desired time complexity, sorting (known to be O(n log n) time) the points is acceptable. For convenience, the first step is to sort the points by x coordinate. Intuitively the algorithm works in the following fashion. Divide the points into two subsets of equal size with a vertical line. Recursively compute the maximal points of each side. Combine the two sets of maximal points and return the result. This is a divide and conquer algorithm. Intuitively, the merge step consists of merging the two sets of maximal points. The base case consists of a set of points with only one point, and the maximal point of that degenerate case is simply the point itself (after all, there are no points above and to the right of it). The merging step is the most complex and will be considered next. For clarity consider the following example. The points have been divided by the vertical line, and the maximal points of each set of points have been returned (noted in this picture by the points connected by lines). Note that a point p 1 dominates p 2 if x 1 >= x 2 AND y 1 >= y 2 . The x coordinate of any point on the left side of the dividing line is less than the x coordinate of any point on the right side of the dividing line by definition. Therefore, no point from the left side will ever dominate a point from the right side, though it is possible for a point from the right side to dominate one on the left. This is the key observation for the merging step. Note that every point in the dominating point set from the right side has a greater x coordinate than those in the dominating set of the right side. Therefore points on the right side will dominate any points in the left set with y coordinates lower than them. The merge step then requires taking the uppermost point from the right side, and determining which of the left points have a lower y coordinate, and then removing any left points that are below that point. In graphical terms, simply extend a horizontal line from the highest point in the right set, and any point on the left below that line is no longer in the dominating set, while any point above it is. All points from the right set are always in the next level dominating set. This process is shown below. The next illustration shows the final dominating set.
Background image of page 1

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

View Full Document Right Arrow Icon
This description gives the general idea. However, there are a few details that must be dealt with in order for the algorithm to work in the proper time. First, the location of the vertical line must be selected carefully. If there are n points to be divided, going from x 0 to x n in the x direction, the division must occur so that each side of the line contains n/2 points. Intuitively it may seem like the best idea is to place the line at (x 0 + x n )/2, however if the points are all clustered towards one end of the spectrum (for example, if
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.

{[ snackBarMessage ]}

Page1 / 11

hw4_sol - CSE 413 Homework 4 Solution Guide Problem 1 The...

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