![]() 38
Figure 2.1.2.6.b. DFS vs BFS
An explanation of these traversals can be observed as follows:
DFS traversal is conducted through a nodes child to its leaves before proceeding to its
neighbors.
1. {a} --------------- root.
2. {b,c} ------------- root a will provide nodes b and c as current list.
3. {d,e,c}
---------- processing b, resulting the nodes of d and e.
4. {e,c,}
---------- processing d, leaving node e and c in the list.
5. {c} --------------- processing e, the desired node is found.
BFS traversal is carried out based on the depth on the node before proceeding to its
child.
1. {a} --------------- root.
2. {b,c} ------------- root a will provide nodes b and c as current list.
3. {c,d,e} ----------- processing b, resulting the nodes of d and e.
|