Chapter 3
Solving Problems by Searching
What is a problem?
• It is a gap between what actually is and
what is desired.
• A problem exists when an individual becomes aware of the
existence of a significant difference between the expected
and the actual situation, which is an obstacle and makes it
difficult to achieve a desired goal or objective.
•To solve problems by searching we can
consider: uninformed search and informed
search
Uniformed Search
• It is also called blind of exhaustive search
• Two types : BFS(Breadth First search) and
DFS(depth first search)
1) BFS(Breadth First search): this is
blind/exhaustive search algorithm in which
search start from initial node and searches level
by level up to goal node found.
• Search terminates when a solution is found.
Uniformed
Example: Search…
let Initial state= A goal state = J and
M
leve0
leve1
leve2
leve
3
leve
4
Uniformed Search…
Nodes are explored in the level like
leve0,level1,level2,level3,level as follows
ABCDEFGHIJKLM
• The goal node J will be found before the goal
I G G2
node M. 1
• Search requires considerable memory resource.
• Similar to BFS, DFS search requires considerable
memory space
Uniformed Search…
2) DFS(Depth First Search):is also blind/exhaustive
search algorithm in which search starts at initial
node and searches up to some depth in one
direction.
• If goal node is found, it stop the search process,
otherwise you can do backtracking.
Uniformed
Example:
search…
Let initial node=A and goal node=M
and J
Uniformed search…
• Nodes are explored as A B D E H L M I N O F GJ
I G G
1 2
•The goal node M will be found before J the goal
node
•Similar to BFS, DFS also requires considerable
memory space
Informed Search
• It is also called heuristic/intelligent search
• It is technique that improve the efficiency of search
process.
• For complex problems, traditional algorithms are unable
to find the solution with some limits of time & space.
• Hence heuristic techniques are used to solve complex
problems.
types of informed search:
8-puzzle problem
Generate and test
A* search
AO* search
Hill climbing
Constraint satisfaction
Informed Search:8-puzzle
problem:
• State space: Configuration of 8-tiles on the board.
• Action:“Move tiles towards blank spaces”
• Direction: Left, Right, Up, Down
Informed Search:8-puzzle problem …
Approaches to solve 8-puzzle problem
Approach1: count correct position of tiles when
compared with goal state.
• In this approach the highest heuristic value is the
best it is and other values are ignored
Approach2: count incorrect position tiles when
compared with goal state
• In this approach the lowest heuristic value is the
best it is and other values are ignored
Approach3: count how far away each tile from its
position when compared with goal state.
• In this approach the lowest heuristic value the best
it is and other values are ignored.
• This method is preferable when there is
ambiguities.
Informed Search:8-puzzle problem …
Compute the following 8-puzzle problem using three approaches?
Given
Initial state Goal
state
method1: Solution
Initial state Goal
state
method2: Solution
Initial state Goal
state
method3: Solution
Initial state Goal
state
• Assignment2:
Compute the following 8-puzzle problem using three
approaches?
Informed Search : Generate and
Test algorithm
• Acceptable for simple problems.
• There is the problem state space.
• Inefficient for problems with large space.
• This is disadvantage of generate and test search
algorithm
problem state space
2. Generate and Test
Algorithm for Generate and Test
1.start with initial state
2.Apply technique
1.Produce a new state
3.Chech a new state
4. If new state is goal state search stop, otherwise
return to step2
2. Generate and Test…
Start
Initial
state
Apply
technique
Produce
new
state
YES
NO
New sate is goal state
Flow chart for generate and test algorithm
STOP
3. Hill climbing
• Generate and test + direction toward the goal
state.
• Searching for goal=climbing to the top of hill
Example of hill climbing
• Algorithm:
1. Evaluate the initial state. If it is goal state, then
return and quit. Otherwise make initial state as
the current state.
2. Loop until a solution is found
3) Select and apply operator on current sate to
produce a new state.
4) Evaluate the new state.
i) If it is goal state, then return & quit.
ii) If it is not goal state, but it is better than the current
state, then make it as new current state.
iii) If it is not better than current state, then go to step2
Limitation of hill climbing
1. Local
Maxima
• A state that is better than all of its neighbor states, but not better
than some other
• For example In figure below , node C have better value than neighbor node A
and B but it is not better than node E, F and G
• This represents local maxima.
• You will not see other node in search space for goal state
• So search will see local maxima as goal state and stops search
process without reaching goal node .
• This is limitation of local maxima
Goal state
Local maxima
starts
Local Maxima
Limitation of hill climbing…
2. Plateau
•A plat area of search space in which all neighboring states have
the same value
•So in plateau search stops at particular point because of plat
value will found at particular point.
•
•ForeThis is limitation of hill climbing
example, in figure below , node A,B And C have the same value.
•The equality represents plateau.
Goal state
Plateau
starts
Plateau
4. A* search
•Also called Best First Search
•The lowest heuristic function value is called
most promising node and that node is expanded
in
next level
• A* search has three function such as f(n), g(n)
and h(n)
Law: f(n)= g(n)+h(n)
g(n)= edge cost
h(n)= estimated cost from node n to goal node
f(n)= estimated total cost of path from node n
to goal node
•It has 2lists:
{OPEN} and {CLOSE} lists.
A* search…
Example: Find shortest path from initial node S to goal node G
using A* search algorithm
A* search…
• Exploring S:
A* search…
• A is the current most promising path, so it is
explored next:
A* search…
• Exploring D:
A* search…
• Exploring F:
Notice that the goal node G has been found. However,
it hasn’t been explored, so the algorithm continues
because there may be a shorter path to G.
A* search…
The node B has two entries in the open list: one at a
cost of 16 (child of S) and one at a cost of 18 (child
of A). The one with the lowest cost is explored next
A* search…
• Exploring C:
A* search…
• The next node in the open list is again B.
However, because B has already been
explored and the algorithm continues to
the next candidate.
A* search…
• The next node to be explored is the goal node G,
meaning the shortest path to G has been found!
The path is constructed by tracing the graph
backwards from G to S: