# Search in AI: Problem Solving by Search

AI and Robotics

Nov 26, 2011 (6 years and 6 months ago)

1,599 views

Search in AI:
Problem Solving by Search
Systematic Exploration of
Alternatives
Example Problems
States
:

Dirt and
hoover
locations

Integer location of tile
Actions
:

Left, right, suck, no-op

Move blank left, right, up,
down
Goal Test
:

No dirt

Goal state as given
Path Cost
:

1 per action, 0 for no-op

1 per move
Represent and Search

Characterise abstract representations of well-
defined problems and their solutions

state space, initial and goal states;

traverse state-space, successor function

goal test

path cost

Examples

8-puzzle, 8-queens, route-
finding,

travelling salesman, web-search, p2p file
search
Search Strategies
Blind
(independent of the domain):
Heuristic
(utilises domain-specific features):
best-first, A*
Local
(if only finding goal state matters):
hill-climbing, simulated annealing, genetic
algorithm
Tree Search Algorithms

Node expansion a key idea

for exploration of state
space
How do you search for a file in your directory structure?
Tree Search Example:
From
to Bucharest
Macros: from State to Node

Node

Make-node(State)

List

Insert(Node) -- called
fringe

or
open
(graph)

List may be LIFO, FIFO,

unordered,
organised
by
some other criterion
Fringe? Later

Open

Search

Expand shallowest unexpanded node

Implementation: fringe as FIFO queue
Depth-First Search

Expand deepest unexpanded node

Implementation: fringe as LIFO queue
Features for Evaluation of Strategies
i
.
Completeness
:
Does the method always find a solution?
(Is there a path from initial state to goal state?)
ii
.
Optimality
:
Does the strategy find the optimal solution?
(Does this path have lowest cost among other such paths?)
iii
.
Time Complexity
:
How long does it take?
(The number of nodes expanded.)
iv
.
Space Complexity
:
How much memory does it require?
(The number of search nodes it keeps track of.)

In CS, complexities measured in terms of graph (explicit representation); in AI
the graph is represented implicitly.

Complexity expressed in terms of
- b, the
branching factor

(
maximum number of successors of any node )
- d, the
depth
of the
shallowest goal
node
- m, the
maximum path length

in the state space

Assume the branching factor is uniform

b

Completeness

if shallowest goal state is at finite depth d, and
b is finite, BFS will find the goal

Optimality

--
s
hallowest goal node is not necessarily optimal; it is
optimal if
path cost is non-decreasing function of node depth

Complexity
In BFS, every node generated is held in memory

it
is either a search node or an ancestor of one.
If goal is at level d,
the
best
case scenario is

the goal

is
first node at level d; no more
nodes need to be expanded;
hence (b+b
2
+b
3
+∙ ∙ ∙+
b
d

) nodes in memory
the
worst
case: if the goal is the last one at level d; number of nodes
in memory is (b+b
2
+b
3
+∙ ∙ ∙+
b
d
+1

ʵ 
b) = O(
b
d
+1
)
Evaluation of Depth-First Search

Not optimal
: expands deepest node
first, can get stuck exploring long
(infinite) paths

Space:
Modest memory requirements
bm
+ 1 =
O(
bm
)

stores single path
from root to leaf node, plus unexpanded
nodes along the way. Once node
expanded and descendants explored,
delete from memory.

Time
:
b
m

; bad if d << m, but if solutions
are dense, better than BFS

Variant of DFS

backtracking search:
only one of b successors expanded at a
bm
)
Making use of depth-first

s memory efficiency
Iterative deepening search:
the depth-limited subroutine
Illustrating Iterative Deepening Search
Illustrating Iterative Deepening Search
Illustrating Iterative Deepening Search
Illustrating Iterative Deepening Search
Properties of IDS

Appears wasteful, revisiting same states over and over; but most states

in a
large tree are in the bottom level, so revisiting upper levels is not as wasteful as
it seems:

level d nodes are expanded once: # of nodes = (1)
b
d

,
level d

1 nodes expanded twice: # of nodes = (2)b
d

, etc.
Adding up: total # nodes generated is
(1)
b
d

+ (2)b
d

+ ∙ ∙ ∙ + (d

1)b
2
+ (d)b = O(
b
d
)

Time complexity
:
IDS generates O(
b
d
) nodes,

and so is
faster
than BFS which generates O(
b
d
+1
)
Properties of IDS
Algorithm
:
1: Do depth-first search until fixed depth D
2: If no goal node found, D++ and go to 1

Completeness:
yes

Time complexity
: IDS generates O(
b
d
) nodes

Space
: O(
bd
)

Optimal
if step cost = 1.

Preferred uninformed search method if search space is large and
the depth of solution unknown
Open and Closed Nodes

Fringe to be
explored is
called
OPEN

nodes from
the queue,
place them
in a
CLOSED or
VISITED list

Graph
search
BFS on a graph: Goal

g

DFS on a graph: Goal

g