algorithm 1 is more efficient as it no longer searches entire graph every time