Artificial Intelligence
UNINFORMED SEARCH
STRATEGIES
Bùi Duy Đăng
[email protected]Outline
• Uninformed search strategies
• Breadth-first search
• Uniform-cost search
• Depth-first search
• Depth-limit search
• Iterative deepening search
• Bidirectional search
2
Uninformed search strategies
• No additional information about states beyond that provided
in the problem definition
• All they can do is to generate successors and distinguish a goal state
from a non-goal state.
• Also called Blind Search
3
Uninformed search strategies
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Bidirectional search
Iterative lengthening search, branch and bound, etc.
4
Review: Tree search vs. Graph search
• Tree search can end up repeatedly visiting the same nodes.
• E.g., Arad-Sibiu-Arad-Sibiu-Arad-…
• A good search algorithm avoids such paths.
• Graph search: frontier, explored set, etc.
Tree search vs. Graph search
5
Review: Search strategies
• Search strategies are distinguished by the order in which
nodes are expanded
• How to evaluate a search strategy?
• Completeness
• Time complexity
Measured by factors 𝑏, 𝑑, and 𝑚
• Space complexity
• Optimality
• 𝑏: maximum branching factor of the search tree
• 𝑑: depth of the least-cost solution
• 𝑚: maximum depth of the state space (may be ∞)
6
Breadth-first search
7
Breadth-first search (BFS)
Example state space graph for
a 1ny search problem
• The root node is expanded first, then all the successors of the root,
then their successors, and so on.
• In general, all the nodes are expanded at a given depth in the search
tree before any nodes at the next level are expanded.
8
Breadth-first search (BFS)
Expansion order:
(S, d, e, p, b, c, h,
r, q, a, f, G)
• Expand shallowest unexpanded node
• Implementation: frontier is a FIFO queue
9
Breadth-first search on a graph
function BREADTH-FIRST-SEARCH(problem) returns a solution, or failure
node ← a node with STATE = problem.INITIAL-STATE, PATH-COST = 0
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
frontier ← a FIFO queue with node as the only element
explored ← an empty set
loop do
if EMPTY?( frontier) then return failure
node ← POP(frontier) /* chooses the shallowest node in frontier */
add node.STATE to explored
for each action in problem.ACTIONS(node.STATE) do
child ← CHILD-NODE(problem, node, action)
if child.STATE is not in explored and not in frontier then
if problem.GOAL-TEST(child.STATE) then return SOLUTION(child)
frontier ← INSERT(child, frontier)
10
Breadth-first search (BFS)
• An instance of the general graph search algorithm
• The shallowest unexpanded node is chosen for expansion
• The goal test is applied to each node when it is generated
rather than when it is selected for expansion
• Discard any new path to a state already in the frontier or in
the explored set
11
Breadth-first search on a graph
Breadth-first search on a simple binary tree.
At each stage, the node to be expanded next is indicated by a marker
12
Breadth-first search: An example
d=0
Search Tree
13
Breadth-first search: An example
d e p
d=1
Search Tree
14
Breadth-first search: An example
d e p
c b h r q
d=2
Search Tree
15
Breadth-first search: An example
d e p
c b h r q
a f
d=3
Search Tree
16
Breadth-first search: An example
d e p
c b h r q
a f
d=4 G
Search Tree
17
Breadth-first search: An example
d e p
c b h r q
a f
Search path: S ® e ® r ® f ® G G
Search Tree
18
An evaluation of BFS
• What nodes does BFS expand?
• Process all nodes above the shallowest solution
• Let the shallowest solution’s depth be 𝑑. Search takes time O(𝑏 ! ).
• How much space does the frontier take?
• Roughly the last tier, so O(𝑏 ! ).
• Is it complete?
• YES
• Is it optimal?
• Only if costs are all uniform bd
19
The complexity of BFS
Time and memory requirements for BFS. The numbers shown assume
branching factor 𝑏 = 10; 1 million nodes/second; 1000 bytes/node.
The memory requirements are a bigger problem for BFS than the
execution time.
In general, exponential-complexity search problems cannot be
solved by uninformed methods for any but the smallest instance
20
Quiz 01: Breadth-first search
• Work out the order in which states are expanded, as well as the path
returned by graph search. Assume ties resolve in such a way that states
with earlier alphabetical order are expanded first.
21
Uniform-cost search
22
Search with varying step costs
• BFS finds the path with the fewest steps but does not always
find the cheapest path.
• An algorithm that is optimal with any step-cost function?
23
Uniform-cost search (UCS)
• UCS expands the node 𝑛 with the lowest path cost 𝑔(𝑛)
• Implementation: frontier is a priority queue ordered by 𝑔
® Equivalent to breadth-first search if step costs all equal
® Equivalent to Dijkstra’s algorithm in general
• The goal test is applied to a node when it is selected for
expansion
• A test is added in case a better path is found to a node
currently on the frontier.
24
Uniform-cost search (UCS)
function UNIFORM-COST-SEARCH(problem) returns a solution, or failure
node ← a node with STATE = problem.INITIAL-STATE, PATH-COST = 0
frontier ← a priority queue ordered by PATH-COST, with node as the element
explored ← an empty set
loop do
if EMPTY?( frontier) then return failure
node ← POP(frontier) /* chooses the lowest-cost node in frontier */
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
add node.STATE to explored
for each action in problem.ACTIONS(node.STATE) do
child ← CHILD-NODE(problem, node, action)
if child.STATE is not in explored and not in frontier then
frontier ← INSERT(child, frontier)
else if child.STATE is in frontier with higher PATH-COST then
replace that frontier node with child 25
Uniform-cost search
Expansion order
S,p,d,b,e,a,r,f,e,G
26
Uniform-cost search: An example
frontier
PQ = { (S:0) }
Search Tree
27
Uniform-cost search: An example
p d e
frontier
Selected for
expansion
PQ = { (p:1), (d:3), (e:9) }
Search Tree
28
Uniform-cost search: An example
p d e
expanded
PQ = { (d:3), (e:9), (q:16) }
Search Tree
29
Uniform-cost search: An example
p d e
q b e c
PQ = { (b:4), (e:5), (c:11), (q:16) }
Update path cost of e
Search Tree
30
Uniform-cost search: An example
p d e
q b e c
PQ = { (e:5), (a:6), (c:11), (q:16) }
Search Tree
31
Uniform-cost search: An example
p d e
q b e c
a r h
PQ = { (a:6), (r:7), (c:11), (h:13), (q:16) }
Search Tree
32
Uniform-cost search: An example
p d e
q b e c
a r h
PQ = { (r:7), (c:11), (h:13), (q:16) }
Search Tree
33
Uniform-cost search: An example
p d e
q b e c
a r h
f
PQ = { (f:8), (c:11), (h:13), (q:16) }
Search Tree
34
Uniform-cost search: An example
l d w e S
S ho u
h ere ?
ST OP p d e
q b e c
a r h
f
PQ = { (G:10), (c:11), (h:13), (q:16) }
G
Not update path cost of c
Search Tree
35
Uniform-cost search: An example
NO! S
Only
whe
n GO stop
POP A p d e
out L is
of P
Q
q b e c
a r h
f
PQ = { (c:11), (h:13), (q:16) }
Goal is taken out of PQ ® STOP G
Search Tree
Search path: S ® d ® e ® r ® f ® G, cost = 10 36
Uniform-cost search: An example
37
Uniform-cost search: Suboptimal path
38
An evaluation of UCS
• What nodes does UCS expand?
• Process all nodes with cost less than cheapest solution!
• Let 𝐶 ∗ be the cost of the optimal solution and assume that every
action costs at least 𝜖.
∗ /'
• Take time 𝑂(𝑏#$ % ) (exponential in effective depth)
• How much space does the frontier take?
∗ /'
• Roughly the last tier, so 𝑂(𝑏#$ % )
• Is it complete?
• Assume that the best solution has a finite cost
and minimum arc cost is positive, YES
• Is it optimal?
• YES
39
An evaluation of UCS
!" # ∗ /%
• The complexity of 𝑂(𝑏 ) can be greater than 𝑂(𝑏 & ).
• UCS can explore large trees of small steps before exploring paths
involving large and perhaps useful steps.
!" # ∗ /%
• When all step costs are equal, 𝑂(𝑏 ) is just 𝑂(𝑏 &"!).
• UCS does strictly more work by unnecessarily expanding nodes at
depth 𝑑, while BFS stops as soon as it generates a goal.
40
Quiz 02: Uniform-cost search
• Work out the order in which states are expanded, as well as the path
returned by graph search. Assume ties resolve in such a way that states
with earlier alphabetical order are expanded first.
41
Depth-first search
42
Depth-first search (DFS)
• Expand deepest unexpanded node
• Implementation: frontier is a LIFO Stack
Expansion order:
S,d,b,a,c,a,e,h,p,q,q,r,f,c,a,G 43
Depth-first search: An example
44
An evaluation of DFS
• What nodes DFS expand?
• Some left prefix of the tree, and it could process the whole tree!
• If the maximum depth 𝑚 is finite, it takes time 𝑂(𝑏 ( )
• How much space does the frontier take?
• Only has siblings on path to root, so 𝑂(𝑏𝑚) ® linear space
• Is it complete?
• 𝑚 could be infinite
• YES if loops prevented
• Is it optimal?
• NO, the “leftmost” solution,
regardless of depth or cost
45
Completeness of DFS
• Graph-search: complete, while tree-search: not complete
• Avoid repeated states by checking new states against those
on the path from the root to the current node.
• Infinite loops in finite state spaces are avoided, but the proliferation
of redundant paths remains.
• Infinite state spaces: both versions fail if an infinite non-goal
path is encountered.
• E.g., the Knuth’s 4 problem ® keep applying the factorial operator
46
Comparison of BFS and DFS
DFS BFS
Space complexity Linear space Maybe the whole search space
Time complexity Same, better on the average Same, better in worst-cases
(many goals, no loops, and
no infinite paths)
In general better if many goals, not better if goal is not deep,
many loops, and much better infinite paths, many loops, or
in terms of memory. small search space
DFS in use
• The goal test is applied to each node when it is generated rather than when it is
selected for expansion.
• Avoid repeated states by checking new states against those on the path from the root to
the current node.
47
Quiz 03: Depth-first search
• Work out the order in which states are expanded, as well as the path
returned by the algorithm. Assume ties resolve in such a way that states
with earlier alphabetical order are expanded first.
48
Depth-limited search
49
Depth-limited search (DLS)
• Standard DFS with a predetermined depth limit 𝑙
• Nodes at depth 𝑙 are treated as if they have no successors ® infinite
problems solved.
• Depth limits can be based on knowledge of the problem.
• Diameter of state-space, typically unknown ahead of time in practice
E.g., 20 cities in the Romania map
® 𝑙 = 19
but any city is reached from any other
city in at most 9 steps
® 𝑙 = 9 is better
50
Depth-limited search (DLS)
function DEPTH-LIMITED-SEARCH(problem, limit) returns a solution, or
failure/cutoff
return RECURSIVE-DLS(MAKE-NODE(problem.INITIAL-STATE),
problem, limit)
function RECURSIVE-DLS(node, problem, limit) returns a solution, or
failure/cutoff
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
else if limit = 0 then return cutoff
else cutoff_occurred? ← false • Failure: no solution
for each action in problem.ACTIONS(node.STATE) do • Cutoff: no solution
child ← CHILD-NODE(problem, node, action) within the depth limit
result ← RECURSIVE-DLS(child, problem, limit – 1)
if result = cutoff then cutoff occurred? ← true
else if result ¹ failure then return result
if cutoff occurred? then return cutoff else return failure
51
An evaluation of DLS
• Completeness
• Maybe NO if 𝑙 < 𝑑
• Optimality
DFS is a special case of DLS
• NO if 𝑙 > 𝑑 when 𝑙 = ∞
• Time complexity
• 𝑂(𝑏𝑙 )
• Space complexity
• 𝑂(𝑏𝑙)
52
Itera7ve deepening search
53
Iterative deepening search (IDS)
• General strategy, often used in combination with depth-first
tree search to find the best depth limit
function ITERATIVE-DEEPENING-SEARCH(problem) returns a solution, or failure
for depth = 0 to ∞ do
result ← DEPTH-LIMITED-SEARCH(problem, depth)
if result ¹ cutoff then return result
• Gradually increase the limit until a goal is found.
• The depth limit reaches the depth 𝑑 of the shallowest goal node.
54
Iterative deepening search (IDS)
55
Iterative deepening search (IDS)
56
An evaluation of IDS
• Completeness
• YES when the branching factor is finite
• Optimality Similar to BFS
• YES if step cost = 1
• Time complexity
• 𝑑 + 1 𝑏 ) + 𝑑𝑏# + 𝑑 − 1 𝑏 ! = 𝑂(𝑏 ! )
• Space complexity
• 𝑂(𝑏𝑑), similar to DFS
• Preferred when the search space is large and the depth of
the solution is not known
57
Bidirec7onal search
58
Bidirectional search
• Two simultaneous searches: one from the initial state
towards, and the other from the goal state backwards
• Hoping that two searches meet in the middle
59
Bidirectional search
• Goal test: whether the frontiers of two searches intersect
• Optimality: maybe NO
• Time and Space complexity: 𝑂(𝑏 &/+)
• It sounds attractive, but what is the tradeoff?
• Space requirement for the frontiers of at least one search
• Not easy to search backwards (predecessors required)
• In case there are more than 1 goals
• Especially if the goal is an abstract description (no queen attacks
another queen)
60
A summary of uninformed search
• Comparison of uninformed algorithms (tree-search versions)
61
THE END
62