Professional Documents
Culture Documents
Uninformed Search Chapter 3 Hamid
Uninformed Search Chapter 3 Hamid
▪ A state space
“N”, 1.0
▪ A successor function
(with actions, costs)
“E”, 1.0
▪ A start state and a goal test
• problem formulation
• It is a process of deciding what actions should be taken to achieve formulated
goal.
• what are the possible states of the world relevant for solving the problem
• what information is accessible to the agent
• how can the agent progress from state to state
Problem Formulation
• To solve a problem by search, we need to first formulate the problem.
HOW?
• Our textbook suggest the following schema to help us formulate problems
• We have seen that the basic elements of a problem definition are the states
and actions. To capture these ideas more precisely, we need the following:
1. State space
2. Initial state
3. Actions or Successor Function:
4. Goal State:
5. Path Cost:
6. Solution:
Problem Formulation
Initial state: starting point from which the agent sets out.
state space
• set of all states reachable from the initial state by any sequence of actions
path
• sequence of actions leading from one state in the state space to another
goal test
• determines if a given state is the goal state
Problem Formulation
solution
• path from the initial state to a goal state
search cost
• time and memory required to calculate a solution
path cost
• determines the expenses of the agent for executing the actions in a path
• sum of the costs of the individual actions in a path
total cost
• sum of search cost and path cost
• overall cost for finding a solution
More formally, a problem is defined by:
1.A set of states S
2.An initial state S
3.A set of actions A —Actions(s) = the set of actions that can be executed
4.Transition Model:
—s is called a successor of s
—Successors(si)* = state space
5.Goal test Goal(s)
—s is a goal state if Goal(s) is true
start
end
Example: Traveling in Romania
State: We regard a problem as state space here a state is a City
Initial State: the state to start from In(Arad)
Successor Function: description of the possible actions, give state x, S(X)
returns a set of <action, successor> ordered pairs.
S(x)= { <Go(Sibiu), In(Sibiu)>, <Go(Timisoara), In(Timisoara)>,
<Go(Zerind),In(Zerind)> } start
Path Cost: a function that assigns a numeric cost to each path. end
Solution: a sequence of actions leading from the initial state to a goal state
{Arad aSibiu a Rimnicu Vilcea a Pitesti a Bucharest}
Example: 8-puzzle
2 1 3 1 2 3
Slide blank square left.
4 7 6 Slide blank square right. 4 5 6
….
5 8 7 8
Problem Formulation
8-Puzzle Problem
Representing states:
▪ 3 by 3 array
▪ 5, 6, 7
▪ 8, 4, BLANK 5 6 7
▪ 3, 1, 2
8 4
▪ A vector of length nine 3 1 2
▪ 5,6,7,8,4, BLANK,3,1,2
▪ A list of facts
▪ Upper_left = 5
▪ Upper_middle = 6
▪ Upper_right = 7
▪ Middle_left = 8
Problem Formulation
8-Puzzle Problem
▪ Specifying operators:
▪ There are often many ways to specify the operators, some will be much easier
to implement...
• Move 1 left
• Move 1 right
• Move 1 up
• Move 1 down
• Move Blank left
• Move 2 left
• Move Blank right
• Move 2 right
• Move Blank up
• Move 2 up
• Move 2 down
• Move Blank down 5 6 7
• Move 3 left 8 4
• Move 3 right
• Move 3 up 3 1 2
• Move 3 down
• Move 4 left
• …
Problem Formulation
8-Puzzle Problem
1 2 3 1 2 3
4 8 4 5 6
7 6 5 7 8
Operators: slide blank up, slide blank down, slide blank left, slide blank right
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
4 8 4 8 5 4 8 5 4 5 4 5 4 5 6
7 6 5 7 6 7 6 7 8 6 7 8 6 7 8
Solution: A B C
0 0 0
0 5 0
3 2 0
3 0 2
3 5 2
3 0 7
Which solution do we prefer?
Example 1: water jug
Given 3 jugs (9, 5 and 3 liters), a water pump, and a sink, how do you get exactly 7 liters
into the 9 liter jug?
• Goal state: (x x 7)
You have three jugs. They can hold 12 liters, 8 liters, and 5 liters Jug 12 Jug 8 Jug 5
of milk respectively. 12-liter jug is full of milk, but you need to
split it in half using only the jugs on hand. How can you split up A B C
the malik to give away exactly 6 liter, and keep 6 liter? 12 0 0
4 8 0
4 3 5
12 9 3 0
liter 8
liter 5 liter 9 0 3
1 8 3
1 6 5
6 6 0
Missionaries and cannibals
▪ Three missionaries and three cannibals are on the left bank of a river.
▪ There is one canoe which can hold one or two people.
▪ Find a way to get everyone to the right bank, without ever leaving a
group of missionaries in one place outnumbered by cannibals in that
place.
Near side Far side
0 Initial setup: MMMCCC B –
1. Two cannibals cross over: MMMC B CC
2. One comes back: MMMCC B C
3. Two cannibals go over again: MMM B CCC
4. One comes back: MMMC B CC
5. Two missionaries cross: MC B MMCC
6. A missionary & cannibal return: MMCC B MC
7. Two missionaries cross again: CC B MMMC
8. A cannibal returns: CCC B MMM
9. Two cannibals cross: C B MMMCC
10. One returns: CC B MMMC
11 And brings over the third: - B MMMCCC
Missionaries and cannibals
▪ States: three numbers (i,j,k) representing the number of missionaries,
cannibals, and canoes on the left bank of the river.
▪ Initial state: (3, 3, 1)
▪ Operators: take one missionary, one cannibal, two missionaries, two
cannibals, one missionary and one cannibal across the river in a given
direction (I.e. ten operators).
▪ Goal Test: reached state (0, 0, 0)
▪ Path Cost: Number of crossings.
Missionaries and cannibals
▪ States: three numbers (i,j,k) representing the number of missionaries,
cannibals, and canoes on the left bank of the river.
▪ Initial state: (3, 3, 1)
▪ Operators: take one missionary, one cannibal, two missionaries, two
cannibals, one missionary and one cannibal across the river in a given
direction (I.e. ten operators).
▪ Goal Test: reached state (0, 0, 0)
▪ Path Cost: Number of crossings.
State space Representation and search
• A state space is the set of all possible configurations of a system.
• It is a useful abstraction for reasoning about the behavior of a given system and is widely
used in the fields of artificial intelligence and game theory.
In Artificial Intelligence a state space consists of the following elements,
1. A (possibly infinite) set of states
1.1. Out of the possible states, one state represents the start state that is the initial state of the problem.
1.2. Each state represents some configuration reachable from the start state
1.3. Out of the possible states, some states may be goal states (solutions)
2. A set of rules,
2.1. Applying a rule to the current state, transforms it to another or a new state in the state space
2.2 All operators may not be applicable to all states in the state space State spaces are used extensively
in Artificial Intelligence (AI) to represent and solve problems.
State Space Search Examples:
A maze problem can be represented as a state-space;
A set of States
• Each state represents “where you are” that is the current position in the maze
• The start state or initial state represents your starting position
• The goal state represents the exit from the maze
• Organize data:
• It is used to organize data for efficient insertion, deletion and searching. ...
• Trie:
• It is a special kind of tree that is used to store the dictionary.
State Space Graphs vs. Search Trees
Each NODE in in
the search tree is
State Space Graph an entire PATH in Search Tree
the state space
graph. S
a G d e p
b c
b c e h r q
e
d f a a h r p q f
S h
p q f q c G
p q r
We construct both a
q c G
on demand – and
we construct as a
little as possible.
Example: Tree Search
State space graph Search tree
A S
S C
A B
C C
B
G G G
Example: Tree Search
a G
b c
e
d f
S h
p q r
Example: Tree Search
a G
b c
e
d f
S h
p q r
S s
s→d
d e p s→e
s→p
b c e h r q s→d→b
s→d→c
a a h r p q f s→d→e
s→d→e→h
p q f q c G s→d→e→r
a s→d→e→r→f
q c G
s→d→e→r→f→c
a s→d→e→r→f→G
SEARCH TECHNIQUES
1. Search without information, 1. Search with information
2. No knowledge 2. Use knowledge to find step to
3. Time consuming Search techniques solution
4. More complexity(time, space) 3. Quick solution
4. Less complexity (Time , space)
Uninformed or Blind informed or Heuristic
Breadth Hill
Depth first A*
first climbing
Search search
Search Search
( DFS )
( BFS )
Best-First Greedy
Search Search
SEARCH TECHNIQUES
• Uninformed search, also called blind search or unguided search, is a class
of general purpose search algorithms that operate in a brute-force way.
• The term 'uninformed’ means that they have no additional information about
states beyond that provides in the problem definition.
bs nodes
▪ Space? O(bd+1) (keeps every node in memory)
bm nodes
▪ Optimal? Yes (if cost = 1 per step)
d e p
Search
b c e h r q
Tiers
a a h r p q f
p q f q c G
q c G a
a
Example (Breadth-First Search - BFS)
Initial state
A
B C D E F
Goal state
G H I J K L M N O P
Q R S T U V W X Y Z
B C D E F
G H I J K L M N O P
Node L is located and the search returns
a solution. Press space to end.
Q R S T U
Implementation: e
d f
Fringe is a LIFO stack S h
p q r
d e p
b c e h r q
a a h r p q f
p q f q c G
q c G a
a
Search Algorithm Properties
▪ Complete: Guaranteed to find a solution if one exists?
▪ Optimal: Guaranteed to find the least cost path?
▪ Time complexity?
▪ Space complexity? b
1 node
… b nodes
b2 nodes
▪ Cartoon of search tree:
m tiers
▪ b is the branching factor
▪ m is the maximum depth
▪ solutions at various depths
bm nodes
▪ Number of nodes in entire tree?
▪ 1 + b + b2 + …. bm = O(bm)
Depth-First Search (DFS) Properties
▪ What nodes DFS expand?
▪ Some left prefix of the tree. 1 node
b
▪ Could process the whole tree! … b nodes
▪ If m is finite, takes time O(bm) b2 nodes
m tiers
▪ How much space does the fringe take?
▪ Only has siblings on path to root, so O(bm)
▪ Is it complete? bm nodes
▪ m could be infinite, so only if we prevent
cycles (more later)
▪ Is it optimal?
▪ No, it finds the “leftmost” solution,
regardless of depth or cost
Properties of depth-first search
▪ Complete? No: fails in infinite-depth spaces,
spaces with loops b
1 node
… b nodes
▪ Modify to avoid repeated states along path
b2 nodes
→ complete in finite spaces
m tiers
▪ Optimal? No
Search Algorithm Properties
EXAMPLE (Depth-First Search - DFS)
Depth First Search examines the nodes in the following order:
A, B, E, K, S, L, T, F, M, C, G, N, H, O, P, U, D, I, Q, J, R
OPEN CLOSED
Start A A
BCD A
EFCD BA
B C D KL FCD E BA
S LFCD K EBA
LFCD S KEBA
TFCD LSKEBA
E F G H I J FCD TLSKEBA
MCD FTLSKEBA
CD M FTLSKEBA
GHD C MFTLSKEBA
K L M N O P Q R NHD G CMFTLSKEBA
HD NGCMFTLSKEBA
OPD H NGCMFTLSKEBA
PD O HNGCMFTLSKEBA
S T Goal U UD P OHNGCMFTLSKEBA
Blind Search Strategies
▪ Breadth-first search
▪ Expand all the nodes of one level first.
▪ Depth-first search
▪ Expand one of the nodes at the deepest level.
Depth-first vs. Breadth-first
Advantages of depth-first: Advantages of breadth-first:
▪ Simple to implement; ▪ Guaranteed to find a solution (if one
▪ Needs relatively small memory for storing the exists) - complete;
state-space.
▪ Depending on the problem, can be
Disadvantages of depth-first: guaranteed to find an optimal
▪ Sometimes fail to find a solution (may be get solution.
stuck in an infinite long branch) - not complete; Disadvantages of breadth-first:
▪ More complex to implement;
▪ Not guaranteed to find an optimal solution
(may not find the shortest path solution); ▪ Needs a lot of memory for storing the
▪ Can take a lot longer to find a solution. state space if the search space has a
high branching factor.
Depth-first vs. Breadth-first
Would you use breadth-first or depth-first search for each of the following
problems? What would you base your choice on:
Arad
75 118
140
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G
q 11 c G 10 a
a
Uniform Cost Search (UCS) Properties
▪ What nodes does UCS expand?
▪ Processes all nodes with cost less than cheapest solution!
b c1
▪ If that solution costs C* and arcs cost at least , then the …
“effective depth” is roughly C*/ C*/ “tiers”
c2
▪ Takes time O(b ) (exponential in effective depth)
C*/
c3
▪ Is it complete?
▪ Assuming best solution has a finite cost and minimum arc cost
is positive, yes!
▪ Is it optimal?
▪ Yes! (Proof next lecture via A*)
Home Work
a GOAL
2 2
b c
3
2
1 8
2 e
3 d
f
9 8 2
START h
1 4 2
p 4 r
15 q
Draw the search tree and find path for BSF and DFS
Home Work