I am trying to understand the closest pair algorithm. I understand about dividing the set in half. But I am having trouble understanding how to recursively compute the closest pair. I understand recursion, but do not understand how to compute the closest pair by recursion. If you have (1,2)(1,11)(7,8) how would recursion work on these?
If you mean this algorithm you do the following:
- Sort points: (1,2) (1,11) (7,8)
- Build two subsets: (1,2) (1,11) and (7,8)
- Run the algorithm on (1,2) (1,11) and on (7,8) separately <= this is where the recursion comes. The result is dLmin = 9 and dRmin = infinity (there is no second point on the right)
- dLRmin = sqrt(45)
- result = min(dLmin, dRmin, dLRmin) = sqrt(45)
The recursion consists of the same steps as above. E.g. the call with (1,2) and (1,11) does:
- Sort points: (1,2) (1,11)
- Build two subsets: (1,2) and (1,11)
- Run the algorithm on (1,2) and on (1,11) separately <= again recursion calls. The result is dLmin = infinity and dRmin = infinity
- dLRmin = 9
- result = min(dLmin, dRmin, dLRmin) = 9