This is a high-level algorithm that relies on each graph's implementation of the general functions, so the algorithm is implemented in the Graph class.