find path algorithm