add path algorithm