Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
courses:cs211:winter2011:journals:wendy:chapter5 [2011/03/09 06:00] – [Section 3: Counting Inversions] shangw | courses:cs211:winter2011:journals:wendy:chapter5 [2011/03/14 00:52] (current) – shangw | ||
---|---|---|---|
Line 31: | Line 31: | ||
I think this way of counting inversion is smart. | I think this way of counting inversion is smart. | ||
Readability is 7. | Readability is 7. | ||
+ | |||
+ | ===== Section 4: Finding the Closest Pair of Points ===== | ||
+ | Here is another application of the divide conquer algorithm. | ||
+ | The general idea is to divide the plane into two parts, find out the minimum distance of each part, compare both with the distances between points beside the boundary of the two planes and hence get a minimum distanced pair of the combined plane. The most difficult part to implement is the combining part. First it is not hard to conceive that let x be the smaller distance from the two planes to be combined, if the new minimum distance comes from between points from the two planes, then the points have to locate from the strip centered at the splitting vertical line with wideth 2x. Sort the points inside the strip according to their y coordinate in ascending order. Another smart observation is if si, sj are two points in the strip and |i-j|> | ||
+ | T(n)< | ||
+ | Readability is 8. | ||
+ | |||
+ | ===== Section 5: Integer Multiplication ===== | ||
+ | This section introduces another problem that uses the divide conquer algorithm--integer multiplication. | ||
+ | This seemingly straight forward problem actually takes O(n^2) if using brute-force algorithm. But we can improve the running time using divide and conquer method. | ||
+ | The first try is to divide the original problem into 4 subproblems: | ||
+ | xy=x1y1+(x1y0)2^n/ | ||
+ | However, the recurrence relationship T(n)< | ||
+ | xy=x1y1+(x1y1+x0y0+x1y0+x0y1-x1y1+x0y0)2^n/ | ||
+ | =x1y1+(p-x1y1-x0y0)2^n/ | ||
+ | where p=(x0+x1)(y0+y1). | ||
+ | Now the recurrence relationship is T(n)< | ||
+ | |||
+ | Readability is 7. | ||
+ | |||
+ |