2021 Lecture03 P2 UninformedSearch
2021 Lecture03 P2 UninformedSearch
UNINFORMED SEARCH
STRATEGIES
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
Bidirectional search
5
Review: Search strategies
7
Breadth-first search (BFS)
• 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)
11
Breadth-first search on a graph
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
p d e
q b e c
Search Tree
31
Uniform-cost search: An example
p d e
q b e c
a r h
Search Tree
32
Uniform-cost search: An example
p d e
q b e c
a r h
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
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
p d e
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 𝑂(𝑏1+ 𝐶 ) (exponential in effective depth)
• How much space does the frontier take?
∗ /𝜖
• Roughly the last tier, so 𝑂(𝑏1+ 𝐶 )
• 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
• Graph separation property: every path from the initial state to
an unexplored state must pass through a state on the frontier.
• Proved inductively
40
An evaluation of UCS
1+ 𝐶 ∗ /𝜖
• The complexity of 𝑂(𝑏 ) can be greater than 𝑂(𝑏 𝑑 ).
• UCS can explore large trees of small steps before exploring paths
involving large and perhaps useful steps.
1+ 𝐶 ∗ /𝜖
• When all step costs are equal, 𝑂(𝑏 ) is just 𝑂(𝑏 𝑑+1 ).
• UCS does strictly more work by unnecessarily expanding nodes at
depth 𝑑, while BFS stops as soon as it generates a goal.
41
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.
42
Depth-first search
43
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 44
Depth-first search: An example
45
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
46
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
47
Comparison of BFS and DFS
DFS BFS
Space complexity Linear space Maybe the whole 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.
48
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.
49
Depth-limited search
50
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
53
Iterative deepening search
54
Iterative deepening search (IDS)
• General strategy, often used in combination with depth-first
tree search to find the best depth limit
55
Iterative deepening search (IDS)
56
Iterative deepening search (IDS)
57
An evaluation of IDS
• Completeness
• YES when the branching factor is finite
• Optimality Similar to BFS
• YES if step cost = 1
• Time complexity
• 𝑑 + 1 𝑏 0 + 𝑑𝑏1 + 𝑑 − 1 𝑏𝑑 = 𝑂(𝑏 𝑑 )
• Space complexity
• 𝑂(𝑏𝑑), similar to DFS
59
Bidirectional search
60
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
61
Bidirectional search
• Goal test: whether the frontiers of two searches intersect
• Optimality: maybe NO
• Time and Space complexity: 𝑂(𝑏 𝑑/2 )
62
A summary of uninformed search
• Comparison of uninformed algorithms (tree-search versions)
63
THE END
64