adding closest pair algorithm