Chapter3 ProblemSolvingBySearching
Chapter3 ProblemSolvingBySearching
Chapter3 ProblemSolvingBySearching
1 2 1 2 3
4 5 3 4 5 6
7 8 6 7 8
Initial State Goal State
8-puzzle
1 2
4 5 3
7 8 6
1 5 2
1 2 1 2
4 3
4 5 3 4 5 3
7 8 6 7 8 6 7 8 6
...
8-puzzle
• States: A state description specifies the location of
each of the tiles.
• Initial state: Any state can be designated as the
initial state.
• Actions: moving Left, Right, Up, or Down.
• Transition model: Maps a state and action to a
resulting state
• Goal state: Although any state could be the goal,
we typically specify a state with the numbers in
order.
• Action cost: Each action costs 1.
Real-world problems
Route-finding problem: is defined in terms of specified
locations and transitions along edges between them
Touring problems: Ex. traveling salesperson problem
(TSP) is a touring problem in which every city on a map
must be visited
A VLSI layout: positioning millions of components and
connections on a chip to
minimize area,
minimize circuit delays,
minimize stray capacitances, and
Maximize manufacturing yield.
Real-world problems
Robot navigation: is a generalization of the
route-finding problem, where search space
becomes many-dimensional.
Automatic assembly sequencing: the aim is to
find an order in which to assemble the parts of
some object.
Ex: Protein design: finds a sequence of amino
acids that will fold into a three-dimensional
protein with the right properties to cure some
disease
Search Algorithms
Distinction between the state space and the search tree.
Search Algorithms
A sequence of search trees generated by a
graph search
Search Algorithms
The separation property of graph search, illustrated
on a rectangular-grid problem.
Best-first search
Find a node, n, with minimum value of some
Best-first search evaluation function, f (n).
The algorithm returns either an indication of
failure, or a node that represents a path to a
goal.
Search data structures: To represent a node in the
tree:
• node.STATE:
• node.PARENT:
• node.ACTION:
• node.PATH-COST:
Best-first search
Three kinds of queues are used in search algorithms:
• A priority queue first pops the node with the
minimum cost according to some evaluation
function, f . It is used in best-first search.
• A FIFO queue it is used in breadth-first search.
• A LIFO queue it is used in depth-first search.
Measuring problem-solving performance
Evaluate an algorithm’s performance in four ways:
• Completeness: Is the algorithm guaranteed to find a
solution when there is one, and to correctly report failure
when there is not?
• Cost optimality: Does it find a solution with the lowest
path cost of all solutions?
• Time complexity: How long does it take to find a
solution? measured in seconds, or number of states and
actions considered.
• Space complexity: How much memory is needed to
perform the search?
Uninformed search
• No clue about how close a state is to the
goal(s).
• Given a state, we only know whether it is a goal
state or not
• Cannot say one nongoal state looks better than
another nongoal state
• Can only traverse state space blindly in hope of
somehow hitting a goal state at some point
– Also called blind search
– Blind does not imply unsystematic!
Breadth-first search
• All actions have the same cost.
• Evaluation function f (n) is the depth of the node
• Additional efficiency with a couple of tricks:
A FIFO queue faster than a priority queue, and will
give us the correct order of nodes.
Once we’ve reached a state, we can never find a better
path to the state.
• Always finds a solution with a minimal number of actions
• Generates nodes at depth d, after generating all the nodes
at depth d −1.
• All actions have the same cost.
• For solution is at depth d total number of nodes generated
1+b+b2+b3+· · ·+bd = O(bd).
• Both time and space complexity are O(bd).
Properties of breadth-first search
• Nodes are expanded in the same order in which they are
generated
– Fringe can be maintained as a First-In-First-Out (FIFO) queue
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal node.
Iterative Deepening Search
Total number of nodes generated in the worst case is
N(IDS) = (d)b1 +(d−1)b2+(d−2)b3 · · ·+bd ,
If b = 10 and d = 5, the numbers are
N(IDS) = 50+400+3,000+20,000+100,000 = 123,450
N(BFS) = 10+100+1,000+10,000+100,000 = 111,110 .
A∗ search: g(n)+h(n) (W = 1)
Uniform-cost search (Dijsktra’s): g(n) (W = 0)
Greedy best-first search: h(n) (W = ∞)
Weighted A∗ search: g(n)+W ×h(n) (1 <W < ∞)