finding the best connection between two arbitrary nodes