AI Search Uninformed 4
AI Search Uninformed 4
AI Search Uninformed 4
Artificial Intelligence
Problem Solving by Search
2
Search algorithm
• Defined as
– taking a problem
– and returns a solution
• Once a solution is found
– the agent follows the solution
– and carries out the list of actions – execution phase
• Design of an agent
– “Formulate, search, execute”
Evaluation Criteria
• Initial state
– The root of the search tree is a search node
• Expanding
– applying successor function to the current state
– thereby generating a new set of states
• leaf nodes
– the states having no successors
Fringe : Set of search nodes that have not been expanded yet.
• Refer to next figure
Example
From our Example
1. Formulate Goal
- Be In Amman
2. Formulate Problem
- States : Cities
- actions : Drive Between Cities
3. Find Solution
• Find solution:
– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
–
Example: Romania
State Space Problem Formulation
A solution is a sequence of actions leading from the initial state to a goal state
Example: The 8-puzzle
• States:
– a state description specifies the location of each of the eight
tiles and blank in one of the nine squares
• Initial State:
– Any state in state space
• Successor function:
– the blank moves Left, Right, Up, or Down
• Goal test:
– current state matches the goal configuration
• Path cost:
– each step costs 1, so the path cost is just the length of the
path
The 8-puzzle Search Tree
Start State
1 2 3
4 6
7 5 8
1 2 3
4 5 6
7 8
1 2 3
4 5 6
7 8
Goal State
Example: River Crossing
• the farmer will first take goat on the other side and return
back alone. We have farmer, wolf, and cabbage at one side
and goat on the other side.
• Now, he will take the wolf along, drop the wolf on the
other side and return with the goat.
• So now on one side, we have farmer, cabbage, and goat
and on the other side, we have a wolf.
• Now, he takes the cabbage along and returns alone.
• So now the scenario is: farmer, goat on one side and wolf,
cabbage on the other side.
• Now, finally, he crosses the river with the goat and hence
succeeds in taking all his belongings with him.
River Crossing Search tree
• Farmer: f
• Wolf: w
• Goat: g
• Cabbage: c
Measuring problem-solving performance
• The evaluation of a search strategy
– Completeness:
• is the strategy guaranteed to find a solution when there is one?
– Optimality:
• does the strategy find the highest-quality solution when there are
several different solutions?
– Time complexity:
• how long does it take to find a solution?
– Space complexity:
• how much memory is needed to perform the search?
Measuring problem-solving performance
• Examples:
– b = 2, d = 10: bd = 210= 1024
– b = 10, d = 10: bd = 1010= 10,000,000,000
Measuring problem-solving performance
• Breadth-first search
• Depth-first search
Breadth-first search
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Breadth-First Strategy
2 3 FRINGE = (1)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (2, 3)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (3, 4, 5)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (4, 5, 6, 7)
4 5 6 7
Breadth-first search (Analysis)
• Breadth-first search
– Complete – find the solution eventually
– Optimal, if step cost is 1
The disadvantage
– if the branching factor of a node is large,
– for even small instances (e.g., chess)
• the space complexity and the time complexity are enormous
Breadth-first search (Analysis)
• assuming 10000 nodes can be processed per second, each with 1000
bytes of storage
Depth-first search
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Depth-first search (Analysis)
• Not complete
– because a path may be infinite or looping
– then the path will never fail and go back try another
option
• Not optimal
– it doesn't guarantee the best solution
• It overcomes
– the time and space complexities
Comparison between Depth-first and Breadth-first
Depth-first search n Breadth-first search
n It requires less memory since n All the tree that so far has been
only the nodes on the current generated must be stored.
path are stored.
n All the tree must be examined
n By chance it may find a to level (n) before any node on
solution without examining level (n+1).
much of the search space.
n It will not follow a wrong path
n It may follow a wrong path for a long time.
for a very long time.
n If there are multiple solutions
n It may find a long path then the minimal solution will
solution be found so the longer paths
never explored before shorter
one.
11