next up previous
Next: About this document Up: No Title Previous: Weighted Graph Represatation

TRAVERSING GRAPHS

DFS(v): Depth-First Search
mark v
while there is an unmarked node w adjacent to node v DFS(w)
end

connected components
O(m+n)

BFS(v): Breadth-First Search
mark v
Q=Qv
while Q is nonempty do

x= delete Front(Q)
for each unmarked node w adjacent to x do mark w
Q=Qw



Sushil Prasad
Thu May 13 13:06:34 EDT 1999