5.1 Tree Search
5.1 Tree Search
A. Avinash, Ph.D.,
Assistant Professor
School of Computer Science and Engineering (SCOPE)
Vellore Institute of Technology (VIT), Chennai
Motivati
on
One of the major goals of AI is to help humans in solving
complex tasks
🞑 Which is the shortest way from Milan to Innsbruck?
🞑 Which is the fastest way from Milan to Innsbruck?
🞑 How can I solve my Sudoku game?
🞑 What is the sequence of actions I should apply to win a game?
Sometimes finding a solution is not enough, you want the
optimal solution
according to some “cost” criteria
All the example presented above involve looking for a plan
A plan that can be defined as the set of operations to be
performed of an initial state, to reach a final state that is
considered the goal state
Thus we need efficient techniques to search for paths, or
sequences of actions, that can enable us to reach the goal
state, i.e. to find a plan
Such techniques are commonly called Search Methods
Search Space
Representation
Representing the search Nod
Loo
space is the first step to e
Ar p
enable the problem
resolution c
Search space is mostly
represented through
graphs
A graph is a finite set of
nodes that are connected
by arcs
A loop may exist in a
graph, where an arc lead
back to the original node
In general, such a
graph is not explicitly
given
Search space is
constructed
during search
Search Space
Representation
A graph is undirected if
undirect direct
each arc 5 6
2 2 1 1
Search
Methods
A search method is defined by picking the order
of node expansion
Informed methods
🞑 Use problem specific information to guide
search in promising directions
Uninformed
Search
A class of general purpose algorithms that operates in a brute
force way
🞑 The search space is explored without leveraging on any
information on the
problem
Also called blind search, or naïve search
Since the methods are generic they are intrinsically inefficient
Prominent methods:
🞑 Depth-First Search
🞑 Breadth-First Search
Depth-First
Search
Depth-First Search (DFS) begins at the root node and exhaustively
search each branch to it maximum depth till a solution is found
🞑 The successor node is selected going in depth using from right to left
(w.r.t. graph
representing the search space)
If greatest depth is reach with not solution, we backtrack till we find an
unexplored branch to follow
The algorithm can be implemented with a Last In First Out (LIFO) stack
or recursion
Depth-First Search:
Example S 1
A B
2
3
S B F F A C D
5
4
6
open={S} closed
={}
S A F D 1. Visit S: open={A,B}, closed={S}
2.Visit A: open={S,B,F,B}, closed={A,S}
3.Visit S: open={B,F,B}, closed={S,A,S}
4.Visit B: open={S,A,F,D,F,B},
closed={B,S,A,S}
5.Visit S: open={A,F,D,F,B},
closed={S,B,S,A,S}
6.Visit A: open={F,D,F,B},
closed={A,S,B,S,A,S}
Depth-First Search:
Example S
A B
S B F F A C D
S A F D
BFS is complete
🞑 If there is a solution, BFS will found it
BFS is optimal
🞑 The solution found is guaranteed to be the
shortest path possible
2
A B
3
4 5
S B F F A C
D
open = {S}, closed={}
1. Visit S: open = {A,B}, closed={S}
S A F D 2. Visit A: open={B,S,B,F}, closed={S,A}
3. Visit B: open={S,B,F,F,A,C,D},
closed={S,A,B}
4. Visit S: open={B,F,F,A,C,D},
closed={S,A,B,S}
5. Visit B:
open={F,F,A,C,D,S,A,C,D},
closed={S,A,B,S,B}
Breadth-First Search:
Example S
A B
S B F F A C D
S A F D
A*
Hill Climbing
Cost and Cost
Estimation
f(n)=g(n)+h(n)
g(n) the cost (so far) to reach the node
n
h(n) estimated cost to get from the
node to the goal
f(n) estimated total cost of path
through n to goal
Informed Search: Best-First
Search
Special case of breadth-first search
Uses h(n) = heuristic function as its evaluation
function
Ignores cost so far to get to that node (g(n))
Expand the node that appears closest to goal
Special cases:
🞑 uniform cost search: f(n) = g(n) = path to n
🞑 A* search
Best-First Search:
Example S 1
h= h=
1 2 1
A B
h= h=
3
h= h= 2 2 h= h= h=
2 S 2 2 2 2
F F A C
B D
open = {S}, closed={}
1. Visit S: open = {A,B}, closed={S}
S A F D 2. Visit A: open={B,F,B,S}, closed={S,A}
3. Visit B: open={F,B,S,F,A,C,D},
closed={S,A,B}
4. Visit F: Goal Found!
In this case we estimate the cost as the distance from the root node (in
term of nodes)
Best-First Search:
Example S
h=1, h=1,
A w=2 w=1
B
h=2, h=2,
h= h= w=7 w=4 h= h= h=
2 S 2 2 2 2
F F A C D
B
S A F D
b, branching factor
d, tree depth of the
solution
m, maximum tree depth