06 - 20 jan - divide and conquer
TRANSCRIPT
CS 321. Algorithm Analysis & Design Lecture 6
Divide and Conquer
Closest Pair
Input: A set of n points given in terms of (x,y) coordinates.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
Compute distances between all pairs.
Approach #0
O(n2)
Sort the points.
Sweep through adjacent pairs.
Approach 1
Time to sort + O(n)
Divide and Conquer.
Split the point set, use recursive solutions.
Approach 2
C ost of Recursion + Time to merge
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
Closest Pair on Left - d1
Closest Pair on Right - d2
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
Closest Pair on Left - d1
Closest Pair on Right - d2
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
1
2
3
4
5
67
8
9
10
11
12
13
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
13
1
7
5
3
98
11
10
4
12
2
6
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
d/2
d/2
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
d/2
d/2
T(n) ≤ 2T(n/2) + O(n)
T(n) = O(n log n)