adding breath first search for the graph algorithm