Uninformed (Blind) Search Ghaz
Uninformed (Blind) Search Ghaz
Search Methods :
Uninformed (Blind) search
Search Methods
Once we have defined the problem space (state representation, the initial state, the
goal state and operators) is all done?
A farmer wishes to carry a wolf, a duck and corn across a river, from the south to the
north shore. The farmer is the proud owner of a small rowing boat called Bounty
which he feels is easily up to the job. Unfortunately the boat is only large enough to
carry at most the farmer and one other item. Worse again, if left unattended the wolf
will eat the duck and the duck will eat the corn.
River
boat
Farmer, Wolf,
Duck and Corn
How can the farmer safely transport the wolf, the duck and the corn to the opposite
shore?
3
Search Methods
The River Problem:
F=Farmer W=Wolf D=Duck C=Corn /=River
-/FWCD
FWCD/-
How can the farmer safely transport the wolf, the duck and
the corn to the opposite shore?
4
Search Methods
Problem formulation:
Initial State: farmer, wolf, duck and corn in the south shore
FWDC/-
Operators: the farmer takes in the boat at most one item from one side to
the other side
(F-Takes-W, F-Takes-D, F-Takes-C, F-Takes-Self [himself only])
5
Search Methods
State space:
A problem is solved by moving from the initial state to the goal state by applying valid
operators in sequence. Thus the state space is the set of states reachable from a particular
initial state.
F WD C
Initial state
WD C D C W C WD
Dead ends
F F W F D F C
Illegal states
F W C F WD C
D
repeated state F
W
D
C
F WD
C
F
W
D C
intermediate state
F C F W C F D C F W F WD F W C
WD D W D C C D
D C C D WD D W
F W F WD F W C F C F W C F D C
F D F WD F D C
W C C W
F W
D
C F WD C Goal state 6
Search Methods
Searching for a solution: F WD C
W C C W
…really large… DC C D WD D W
FW F WD FW C F C FW C F DC
D
FW C F WD C
7
Search Methods
F WD C
Problem solution:
WD C DC W C WD
A problem solution is simply the set F FW F D F C
state:
W C C W
F D F WD F DC
F D F WD F DC
F-Takes-D. W C C W
D
FW C F WD C
8
Search Methods
Problem solution: (path Cost = 7)
While there are other possibilities here is one 7 step solution to the river problem
F D D F W D
F-Takes-D F-Takes-S F-Takes-W
F W D C W C F W C C
Initial State WC/FD FWC/D C/FWD
F-Takes-D
F W G C W C F W C W
13
A Toy Example: A Romanian
Holiday
State space: Cities in Romania
Initial state: Town of Arad
Goal: Airport in Bucharest
Operators: Drive between cities
Solution: Sequence of cities
Path cost: number of cities, distance,
time, fuel
14
The state Space
15
Generic Search Algorithms
Sibiu Bucharest
17
Solution
18
Implementation of Generic
Search Algorithm
function general-search(problem, QUEUEING-FUNCTION)
nodes = MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE))
loop do
if EMPTY(nodes) then return "failure"
node = REMOVE-FRONT(nodes)
if problem.GOAL-TEST(node.STATE) succeeds then return solution(node)
nodes = QUEUEING-FUNCTION(nodes, EXPAND(node, problem.OPERATORS))
end
A nice fact about this search algorithm is that we can use a single algorithm to do
many kinds of search. The only difference is in how the nodes are placed in the
queue. The choice of queuing function is the main feature. 19
Key Issues of State-Space
search algorithm
Search process constructs a “search tree”
• root is the start node
• leaf nodes are:
unexpanded nodes (in the nodes list)
“dead ends” (nodes that aren’t goals and have no successors because
no operators were applicable)
20
Uninformed search strategies
(Blind search)
Uninformed (blind) strategies use only the information available in
the problem definition. These strategies order nodes without
using any domain specific information
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Bidirectional search
21
Basic Search Algorithms
Uninformed Search
23
Breadth First Search (BFS)
Main idea: Expand all nodes at depth (i) before expanding nodes at depth (i + 1)
Level-order Traversal.
Implementation: Use of a First-In-First-Out queue (FIFO). Nodes visited first
are expanded first. Enqueue nodes in FIFO (first-in, first-out) order.
24
Complete?
Yes (if b is finite)
Time?
Number of nodes generated is b+b2+b3+… +bd + b(bd-1) =
O(bd+1)
Space?
O(bd+1) (keeps every node in memory)
Optimal?
Not necessarily since shallowest is not necessarily optimal
Yes (if cost = 1 or uniform per step)
Optimal? No, for general cost functions.
Yes, if cost is a non-decreasing function only of depth.
With f(d) ≥ f(d-1), e.g., step-cost = constant:
All optimal goal nodes occur on the same level
Optimal goal nodes are always shallower than non-optimal goals
An optimal goal will be found before any non-optimal goal
25
Breadth First Search
QUEUING-FN:- successors added to end
of queue Arad
Arad
Arad Oradea
Oradea Fagaras
Arad Lugoj
Rimnicu Vilcea
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
Goal state
4 5
29
Uniform Cost Search (UCS)
5 2
[5] [2]
30
Uniform Cost Search (UCS)
5 2
[5] [2]
1 7
[3] [9]
31
Uniform Cost Search (UCS)
5 2
[5] [2]
1 7
[3] [9]
4 5
[7] [8]
32
Uniform Cost Search (UCS)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
33
Uniform Cost Search (UCS)
5 2
[5] [2]
Goal state
1 4 1
path cost 7
g(n)=[6] [3] [9]
[9]
4 5
[7] [8]
34
Uniform Cost Search (UCS)
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
35
Uniform Cost Search (UCS)
Main idea: Expand the cheapest node. Where the cost is the path cost g(n).
Implementation:
Enqueue nodes in order of cost g(n).
QUEUING-FN:- insert in order of increasing path cost.
Enqueue new node at the appropriate position in the queue so that we
dequeue the cheapest node.
Complete? Yes.
Optimal? Yes,
Time Complexity: O(bd)
Space Complexity: O(bd), note that every node in the fringe keep in the queue.
36
Basic Search Algorithms
Uninformed Search
38
Depth First Search (DFS)
Main idea: Expand node at the deepest level (breaking ties left to right).
• Optimal? No
40
Depth-First Search (DFS)
QUEUING-FN:- insert successors at
front of queue Arad
Arad Oradea
41
Basic Search Algorithms
Uninformed Search
Depth Bound = 3
43
Depth-Limited Search (DLS)
It is simply DFS with a depth bound.
Searching is not permitted beyond the depth bound.
Termination is guaranteed.
Implementation:
Enqueue nodes in LIFO (last-in, first-out) order. But limit depth to L
• Optimal? No
function ITERATIVE-DEEPENING-SEARCH():
47
Iterative Deepening Search (IDS)
Key idea: Iterative deepening search (IDS) applies DLS repeatedly
with increasing depth. It terminates when a solution is found or no
solutions exists.
IDS combines the benefits of BFS and DFS: Like DFS the memory
requirements are very modest (O(bd)). Like BFS, it is complete
when the branching factor is finite.
Time?
d b1 + (d-1)b2 + … + bd = O(bd)
Space?
O(bd)
Optimal?
Yes, for uniform costs e.g. = 1
50
Iterative Deepening Search (IDS)
L=0
L=1
L=2
L=3
51
Iterative Deepening Search (IDS)
52
Iterative Deepening Search (IDS)
53
Basic Search Algorithms
Uninformed Search
Optimal?
Yes, if step costs are uniform and both searches are breadth-first
57
Basic Search Algorithms
b: Branching factor
d: Depth of solution
m: Maximum depth
l : Depth Limit
59
Blind Search Algorithms
Tree Search:
BFS, DFS, DLS, IDS
Basic Search Algorithms
B C D E
F G H I J
K L M N
O
62
Breadth First Search
A,
B C D E
63
Breadth First Search
A,
B,
B C D E
F G
64
Breadth First Search
A,
B,C
B C D E
F G H
65
Breadth First Search
A,
B,C,D
B C D E
F G H I J
66
Breadth First Search
A,
B,C,D,E
B C D E
F G H I J
67
Breadth First Search
A,
B,C,D,E,
F,
A
B C D E
F G H I J
68
Breadth First Search
A,
B,C,D,E,
F,G
A
B C D E
F G H I J
K L
69
Breadth First Search
A,
B,C,D,E,
F,G,H
A
B C D E
F G H I J
K L
70
Breadth First Search
A,
B,C,D,E,
F,G,H,I
A
B C D E
F G H I J
K L M
71
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
A
B C D E
F G H I J
K L M N
72
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K, A
B C D E
F G H I J
K L M N
73
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L A
B C D E
F G H I J
K L M N
O
74
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L, M, A
B C D E
F G H I J
K L M N
O
75
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L, M,N, A
B C D E
F G H I J
K L M N
O
76
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L, M,N, A
Goal state: O
B C D E
F G H I J
K L M N
O
77
Breadth First Search
The returned solution is the sequence of operators in the path:
A, B, G, L, O
B C D E
F G H I J
K L M N
O
78
Basic Search Algorithms
B C D E
F G H I J
K L M N
O
80
Depth First Search
A,
B C D E
81
Depth First Search
A,B,
B C D E
F G
82
Depth First Search
A,B,F,
B C D E
F G
83
Depth First Search
A,B,F,
G,
B C D E
F G
K L
84
Depth First Search
A,B,F,
G,K,
B C D E
F G
K L
85
Depth First Search
A,B,F,
G,K,
L,
A
B C D E
F G
K L
O
86
Depth First Search
A,B,F,
G,K,
L, O: Goal State
A
B C D E
F G
K L
O
87
Depth First Search
The returned solution is the sequence of operators in the path:
A, B, G, L, O
B C D E
F G
K L
O
88
Basic Search Algorithms
Depth-Limited Search
DLS
Depth-Limited Search (DLS)
Application3:
Given the following state space (tree search), give the sequence
of visited nodes when using DLS (Limit = 2):
Limit = 0 A
Limit = 1 B C D E
Limit = 2 F G H I J
K L M N
O
90
Depth-Limited Search (DLS)
A,
B C D E
Limit = 2
91
Depth-Limited Search (DLS)
A,B,
B C D E
Limit = 2 F G
92
Depth-Limited Search (DLS)
A,B,F,
B C D E
Limit = 2 F G
93
Depth-Limited Search (DLS)
A,B,F,
G,
B C D E
Limit = 2 F G
94
Depth-Limited Search (DLS)
A,B,F,
G,
C,
A
B C D E
Limit = 2 F G H
95
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
A
B C D E
Limit = 2 F G H
96
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D, A
B C D E
Limit = 2 F G H I J
97
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I A
B C D E
Limit = 2 F G H I J
98
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I A
J,
B C D E
Limit = 2 F G H I J
99
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I A
J,
E B C D E
Limit = 2 F G H I J
100
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I A
J,
E, Failure B C D E
Limit = 2 F G H I J
101
Depth-Limited Search (DLS)
DLS algorithm returns Failure (no solution)
The reason is that the goal is beyond the limit (Limit =2): the
goal depth is (d=4)
A
B C D E
Limit = 2 F G H I J
K L M N
O
102
Basic Search Algorithms
Limit = 0 A
Limit = 1 B C D E
Limit = 2 F G H I J
Limit = 3 K L M N
Limit = 4 O
104
Iterative Deepening Search
(IDS)
Limit = 0 A
106
Iterative Deepening Search (IDS)
A, Failure
Limit = 0 A
107
Iterative Deepening Search
(IDS)
Limit = 1 B C D E
109
Iterative Deepening Search (IDS)
A,B,
Limit = 1 B C D E
110
Iterative Deepening Search (IDS)
A,B,
C,
Limit = 1 B C D E
111
Iterative Deepening Search (IDS)
A,B,
C,
D,
A
Limit = 1 B C D E
112
Iterative Deepening Search (IDS)
A,B
C,
D,
E, A
Limit = 1 B C D E
113
Iterative Deepening Search (IDS)
A,B,
C,
D,
E, Failure A
Limit = 1 B C D E
114
Iterative Deepening Search (IDS)
A,
B C D E
Limit = 2
115
Iterative Deepening Search (IDS)
A,B,
B C D E
Limit = 2 F G
116
Iterative Deepening Search (IDS)
A,B,F,
B C D E
Limit = 2 F G
117
Iterative Deepening Search (IDS)
A,B,F,
G,
B C D E
Limit = 2 F G
118
Iterative Deepening Search (IDS)
A,B,F,
G,
C,
A
B C D E
Limit = 2 F G H
119
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
A
B C D E
Limit = 2 F G H
120
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D, A
B C D E
Limit = 2 F G H I J
121
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I A
B C D E
Limit = 2 F G H I J
122
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I A
J,
B C D E
Limit = 2 F G H I J
123
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I A
J,
E B C D E
Limit = 2 F G H I J
124
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I A
J,
E, Failure B C D E
Limit = 2 F G H I J
K L M N
O
125
Iterative Deepening Search
(IDS)
B C D E
Limit = 3
127
Iterative Deepening Search (IDS)
A,B,
B C D E
F G
Limit = 3
128
Iterative Deepening Search (IDS)
A,B,F,
B C D E
F G
Limit = 3
129
Iterative Deepening Search (IDS)
A,B,F,
G,
B C D E
F G
Limit = 3 K L
130
Iterative Deepening Search (IDS)
A,B,F,
G,K,
B C D E
F G
Limit = 3 K L
131
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
A
B C D E
F G
Limit = 3 K L
132
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C, A
B C D E
F G H
Limit = 3 K L
133
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
B C D E
F G H
Limit = 3 K L
134
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,
B C D E
F G H I J
Limit = 3 K L
135
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,I,
B C D E
F G H I J
Limit = 3 K L M
136
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,I,M,
B C D E
F G H I J
Limit = 3 K L M
137
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,I,M,
J, B C D E
F G H I J
Limit = 3 K L M N
138
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,I,M,
J,N, B C D E
F G H I J
Limit = 3 K L M N
139
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,I,M,
J,N, B C D E
E,
F G H I J
Limit = 3 K L M N
140
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H, A
D,I,M,
J,N, B C D E
E,Failure
F G H I J
Limit = 3 K L M N
O
141
Iterative Deepening Search
(IDS)
B C D E
Limit = 4
143
Iterative Deepening Search (IDS)
A,B,
B C D E
F G
Limit = 4
144
Iterative Deepening Search (IDS)
A,B,F,
B C D E
F G
Limit = 4
145
Iterative Deepening Search (IDS)
A,B,F,
G,
B C D E
F G
K L
Limit = 4
146
Iterative Deepening Search (IDS)
A,B,F,
G,K,
B C D E
F G
K L
Limit = 4
147
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
A
B C D E
F G
K L
Limit = 4 O
148
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L, O: Goal State
A
B C D E
F G
K L
Limit = 4 O
149
Iterative Deepening Search (IDS)
The returned solution is the sequence of operators in the path:
A, B, G, L, O
B C D E
F G
K L
O
150
Summary
Search: process of constructing sequences of actions that achieve a goal given a
problem.
The studied methods assume that the environment is observable, deterministic,
static and completely known.
Goal formulation is the first step in solving problems by searching. It facilitates
problem formulation.
Formulating a problem requires specifying four components: Initial states,
operators, goal test and path cost function. Environment is represented as a
state space.
A solution is a path from the initial state to a goal state.
Search algorithms are judged on the basis of completeness, optimality, time
complexity and space complexity.
Several search strategies: BFS, DFS, DLS, IDS,…