(Please see PDF link below)
def BFS( V, E, start ): init V all white and NULL parent start.colour = grey init FIFO: Q.push( start ) while Q.notempty(): u = Q.pop() for v in E.adj[ u ]: if v.colour == white: v.colour = grey v.parent = u Q.push( v ) u.colour = black
def DFS( V, E ): init V all white and NULL parent time = 0 for u in V: # why loop over ALL verts? if u.colour == white: DFS-Visit( V, E, u )
def DFS-Visit( V, E, u ): time++ u.discovered = time u.colour = gray for v in E.adj[ u ]: if v.colour == white: v.parent = u DFS-Visit( V, E, v ) u.colour = black time++ u.finished = time