06 - 20 jan - divide and conquer
TRANSCRIPT
![Page 1: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/1.jpg)
CS 321. Algorithm Analysis & Design Lecture 6
Divide and Conquer
![Page 2: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/2.jpg)
Closest Pair
![Page 3: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/3.jpg)
![Page 4: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/4.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
![Page 5: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/5.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 6: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/6.jpg)
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
![Page 7: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/7.jpg)
Compute distances between all pairs.
Approach #0
O(n2)
![Page 8: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/8.jpg)
Sort the points.
Sweep through adjacent pairs.
Approach 1
Time to sort + O(n)
![Page 9: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/9.jpg)
Divide and Conquer.
Split the point set, use recursive solutions.
Approach 2
C ost of Recursion + Time to merge
![Page 10: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/10.jpg)
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
![Page 11: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/11.jpg)
Input: A set of n points given in terms of (x) coordinates.
Output: The closest pair.
![Page 12: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/12.jpg)
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
![Page 13: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/13.jpg)
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
![Page 14: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/14.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 15: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/15.jpg)
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
![Page 16: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/16.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 17: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/17.jpg)
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
![Page 18: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/18.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 19: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/19.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 20: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/20.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 21: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/21.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 22: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/22.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
![Page 23: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/23.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
d/2
d/2
![Page 24: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/24.jpg)
Input: A set of n points given in terms of (x,y) coordinates.
Output: The closest pair.
d/2
d/2
![Page 25: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/25.jpg)
![Page 26: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/26.jpg)
![Page 27: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/27.jpg)
![Page 28: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/28.jpg)
![Page 29: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/29.jpg)
![Page 30: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/30.jpg)
![Page 31: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/31.jpg)
![Page 32: 06 - 20 Jan - Divide and Conquer](https://reader034.vdocument.in/reader034/viewer/2022051709/5876d4cd1a28ab1d238b54c5/html5/thumbnails/32.jpg)
T(n) ≤ 2T(n/2) + O(n)
T(n) = O(n log n)