Update algorithms to support loops in the graph.
Update algorithms to support loops in the graph.