P1: WQS Trim: 6.125in×9.25in Top: 0.5in Gutter: 0.75in
CUUS2079-02 CUUS2079-Zafarani 978 1 107 01885 3 January 13, 2014 16:38
2.6 Graph Algorithms 33
v 1
v 2 v 3
v 4 v 5 v 6
(1) (2)
(3) (4)
(1) (2)
(3) (4)
(5) (6)
v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
v 1
v 2 v 3
v 4 v 5 v 6 v 7
(a) Depth-First Search (DFS)
(b) Breadth-First Search (BFS)
Figure 2.19. Graph Traversal Example.