algorithm to find close pairs in list