Implementation of graph related algorithms