COMP219: Artificial Intelligence: Lecture 7: Search Strategies
COMP219: Artificial Intelligence: Lecture 7: Search Strategies
COMP219:
Artificial Intelligence • Last time
– basic ideas about problem solving;
– state space;
– solutions as paths;
– the notion of solution cost;
– the importance of using the correct level of abstraction.
1 2
3 4
The Search Tree Search Tree Exploration
Expand
Arad Arad • The tree is built by taking the initial state and
identifying the states that can be obtained by a single
application of the operators/actions available.
Sibiu Timisoara Zerind • These new states become the children of the initial
state in the tree.
• These new states are then examined to see if they are
Expand the goal state.
Sibiu • If not, the process is repeated on the new states.
Arad Fagaras Oradea Rimnicu
Vilcea • We can formalise this description by giving an
algorithm for it.
• We have different algorithms for different choices of
Search strategy: how do we choose
nodes to expand.
which node to expand?
5 6
7 8
Breadth First Search Breadth First Search
• Start by expanding initial state - gives tree of depth 1.
A 1
• Then expand all nodes that resulted from previous step
– gives tree of depth 2.
• Then expand all nodes that resulted from previous step, and
so on.
B 2
• Expand nodes all at depth n before going to level n + 1. C 3
F 6 G 7
D 4 E 5
9 10
Agenda=[Arad]
11 12
Example: Romania BFS Example: Romania BFS
Travel from Arad to Bucharest D= 0 Travel from Arad to Bucharest D= 0
Agenda=[Zerind, Sibiu,
Timisoara]
13 14
15 16
Example: Romania BFS Example: Romania BFS
Travel from Arad to Bucharest D= 0 D= 1 Travel from Arad to Bucharest D= 0 D= 1
Agenda=[Oradea, Fagaras,
Rimnicu Vilcea, Lugoj]
17 18
19 20
Properties of Breadth First Search Complexity
Depth Nodes Time
• Advantage: guaranteed to reach a solution if one Time for BFS assuming
exists. 2 110 0.11 msec
a branching factor of 10
• Finds the shortest (cheapest) solution in terms of the 4 11,110 11 msec and 1 million nodes
number of operations applied to reach a solution. 6 106 1.1 sec expanded per second.
• Disadvantage: time taken to reach solution. 8 108 2 mins
– Let b be branching factor - average number of operations
10 1010 3 hours Combinatorial
that may be performed from any level.
– If solution occurs at depth d, then we will look at 12 1012 13 days Explosion !
b + b2 + b3 + · · · + bd nodes before reaching solution - 14 1014 3.5 years
exponential. 16 1016 350 years
– The memory requirement is bd
21 22
3 4 F 6 G 7
D E
23 24
General Depth First Search Example: Romania DFS
Travel from Arad to Bucharest
/* Depth first search */
agenda = [initial state];
while agenda not empty do
pick node from front of agenda;
new nodes = apply operations to state;
if goal state in new nodes then
return solution;
else put new nodes on FRONT of agenda;
25 26
27 28
Example: Romania DFS Example: Romania DFS
Travel from Arad to Bucharest Travel from Arad to Bucharest
29 30
31 32
Properties of Depth First Search Exercise
• Depth first search is guaranteed to find a solution if one exists, • Consider a state space where the start state is number 1 and
unless there are infinite paths. the successor function for state n returns two states,
• Solution found is not guaranteed to be the best. numbers 2n and 2n+10
• The amount of time taken is usually much less than breadth
first search. 1) Draw the portion of the state space for the first 15 states.
• Memory requirement is always much less than breadth first 2) Suppose the goal state is 38. List the order in which the
search. nodes will be visited for both breadth first search and depth
• For branching factor b and maximum depth of the search tree first search.
m, depth-first search requires the storage of only bm nodes.
33
• Next time
– More advanced search strategies
35