2. Outline
• What they are
• DFS and BFS
• Take a look at a scenario
• Test Scenario 1
• Test Scenario 2
• Let talk about UCS
• Conclusion
11/22/2016 ITCS661 2
3. What they are
• They both are search algorithms which can be used
to search path to a vertex (node) in the tree or
unweighted graph domain.
11/22/2016 ITCS661 3
DFS:
1. Implement with Stack (LIFO)
2. It attempts to search as far as
possible to find the goal node
3. It cares to reach the goal, but it
doesn’t care if the path is
shorter
4. If the goal is deep, it is good
BFS:
1. Implement with Queue (FIFO)
2. Search layer by layer, as close as
possible
3. If the goal is not far, the BFS is good
4. If you care the shorter path to the
goal, it is good
But yes, it consumes more time and
memory as the goal is deeper
They’re good for their scenarios
4. Take a look in one scenario
• Suppose a company has many branches (routers) and all
branches are formed topology as showing below.
• We want to know which path host A sends data to host B
11/22/2016 ITCS661 5
8. About Uniform Cost Search (UCS)
• It is one of the best search algorithm
compare to DFS or BFS because it
determines the best path through
the actual path cost NOT just count
number of nodes.
• implement with priority queue
11/22/2016 ITCS661 9
10. Conclusion
• DFS uses Stack and BFS uses Queue
• DFS tries as deep as possible & BFS tries layer by layer
• DFS is simpler compared to BFS
• We cannot say which one is better. It depends on which
scenario we want to apply.
• If the goal is deep, DFS would be better
• If the goal is not far, BFS would be better
11/22/2016 ITCS661 12