The time complexity of the closest pair problem is T(n) = 2T(n/2) + O(n). I understand that 2T(n/2) comes from the fact that the algorithm is applied to 2 sets of half the original's size, but why does the rest come out to O(n)? Thanks.
Asked
Active
Viewed 816 times
0
-
You'll need to specify which algorithm you are using. – chepner Feb 25 '13 at 21:57
2 Answers
1
Check out http://en.wikipedia.org/wiki/Closest_pair_of_points_problem which mentions clearly where the O(n) comes from (Planar case).

user1952500
- 6,611
- 3
- 24
- 37
-1
Any divide and conquer algorithm will consist of a recursive 'divide' component, and a 'merge' component where the recursed results are put together. The linear O(n) component in closet pair comes from merging the results from the 'divide' step into a merged answer.

Nick Mitchinson
- 5,452
- 1
- 25
- 31
-
There's also a sweep-line variant that also runs on O(n log n) time. You keep the points that are close enough to the sweep line in a balanced binary tree, then you examine the points that are closer to the swept point than the closest pair found so far. There are at most a constant number of such "close enough" points, so you get O(n log n) time total. – tmyklebu Feb 26 '13 at 03:01