Algorithm design - nearest neighbor pairs