vip» breadth first search Pagina ! ue 2
anh
The Virtual Lecture Proj
depth first search
Breadth First Search
Method
‘This searches for the goal node among all the nodes of a particular generation
before expanding further.
Demonstration
> Shockwave Animation (24k) - do a breadth first search
» Interactive Flash Test (18k) - can you do a breadth first search?
Algorithm
1. Forma one element queue Q consisting of the root node
2. Until Q is empty o the goat has been reached, determine if the fist
element in Qis the goal. If itis, do nothing b. If itisn's, remove te first
element from Q and add the first element's children, if any, to th» BACK
ofQ
3. If the goal is reached, success; else failure
Evaluation
Tf there's more than one goal node, you always catch the one nearest the node in
generations. This is-of value if the tree is unbalanced, but wasteful if the goal
nodes are at similar levels.
‘This is a complete search.
Search Cost
Consider a tree with branching factor b. At depth d, there will be b! odes. This
causes an exponential explosion of tree size.
Time Efficiency is of order b®. This is very inefficient.
Space Efficiency is also of order b'. This is very inefficient.
Non-optimal
This algorithm will not necessarily find the most efficient route through the state
space.
> Next d
Shockwave Animation (22k) — see a depth first search
> Interactive Flash Test (18k) - do a depth first search
Algorithm
1, Form a one element queue Q consisting of the root node
2. Until Qis empty or the goal has been reached, determine if the first
element in Q is the goal
a. Ifitis, do nothing
b. Fit isn’t, remove the first element from Q and edd the first
element's children, if any, to the FRONT of Q
3. Ifthe goal is reached, success; else failure
Evaluation
Depth first search is simple but lacks discrimination, It is very
Unsatisfactory if the tree is unbalanced, with some leaves being at the end of
much longer branches than others.
‘This is a complete search.
Search Cost
Consider a tree with branching factor b. At depth d, there will be b* nodes.
‘This causes an exponential explosion of tree size.
‘Time Efficiency Order(b*)
Space Efficiency Order(bd)
Non-optimal
This algorithm will not necessarily find the most efficient route through the
state space.