L2 UninformedSearch
L2 UninformedSearch
Uninformed Search
2
Eight-Puzzle
3
Dialogue systems
• Decide what do say next:
Hi, [Cortana / Google /
Bixby / Siri]. Tell me a joke!
4
Outline of Rest of Lecture
• Search
• Definition of problem
• Uninformed search algorithms
• Breadth-first search
• Depth-first search
• Analyzing search algorithms
• More uninformed search algorithms
• Uniform-cost search
• Depth-limited and iterative deepening search
5
Defining a search problem
• State space S: all possible configurations of the domain.
6
Defining a search problem (cont’d)
• Path: a sequence of states and operators.
7
Example: Eight-Puzzle
• States?
• Goals?
• Operators?
• Path cost?
8
Example: Eight-Puzzle
• States?
• Goals?
• Operators?
• Path cost?
10
Example: Robot path planning
Get from red square
to yellow dot.
11
Basic assumptions (for next few
lectures)
• Static (c.f. dynamic) environment
• Observable (c.f. unobservable) environment
• Discrete (c.f. continuous) states
• Deterministic (c.f. stochastic) environment
12
State Space Graph
• Can visualize the state space search in terms of a graph.
s0
• e.g., pathfinding in a grid
13
Search Tree
• Represents the exploration paths in a search procedure
• Nodes represent partial solutions, including a state in S.
• Edges correspond to operators.
e.g., first two levels of search tree for previous problem
s0
s0 s0
g g
14
Example with edge costs
Search tree nodes are NOT the same as the state space
graph nodes!
15
Data structures for search tree
• Defining a search tree node:
• Each node contains a state id (from the states in the graph)
• Node also contain additional information:
• The parent state and the operator used to generate it
• Cost of the path so far
• Depth of the node
16
Generic search algorithm
• Initialize the search tree using the initial state of the
problem
• Repeat
1. If no candidate nodes can be expanded, return failure.
2. Choose a node for expansion, according to some search strategy.
3. If the node contains a goal state, then
• return the corresponding path.
4. Otherwise expand the node, by:
• applying each applicable operator
• generating the successor state, and
• adding the resulting nodes to the tree.
17
Example
18
Example
19
Implementation details
• Need to keep track of the nodes to be expanded: the
frontier.
20
Uninformed (blind) search
• If a state is not a goal, you cannot tell how close to the
goal it might be.
• Hence, all you can do is move systematically between
states until you stumble on a goal.
• In contrast, informed (heuristic) search uses a guess on
how close to the goal a state might be.
• (More on this next class.)
21
Uniformed Search Algorithms
Basic algorithms
• Breadth-first search
• Depth-first search
22
Breadth-First Search (BFS)
• Enqueue nodes at the end of queue.
• All nodes at level i get expanded before all nodes at level
i+1.
=expand next
=terminal node
23
Example
• In what order are nodes expanded using Breadth-first
search?
24
Example
• Label all start states as V0.
25
Example
• Label all successors of states in V0 that have not been labeled as
V1.
26
Example
• Label all successors of states in V1 that have not been labeled as
V2.
27
Example
• Label all successors of states in V2 that have not been labeled as
V3.
28
Example
• Label all successors of states in V3 that have not been labeled as
V4.
29
Example
• To recover the path, follow pointers back to the parent node.
30
Revisiting states
• What if we revisit a state that was already expanded?
• What if we visit a state that was already in the queue?
• Example:
s0
s1
s4
s2
s3
sg
31
Revisiting states
• Maintain a closed list to store every expanded node.
• More efficient on problems with many repeated states.
• Worst-case time and space requirements are O(|S|) (|S| =
#states)
32
Depth-First Search (DFS)
• Enqueue nodes at the front of queue
• In other words, use a stack in stead of a queue.
• Nodes at deepest level expanded before shallower ones.
=expand next
=terminal node
33
Example
In what order are nodes expanded using Depth-first search?
34
Example
In what order are nodes expanded using Depth-first search?
Order of operators matter!
35
Example
In what order are nodes expanded using Depth-first search?
Order of operators matter!
36
Example
In what order are nodes expanded using Depth-first search?
Order of operators matter!
37
Key properties of search algorithms
• Completeness: Are we assured to find a solution, if one
exists?
• Optimality: How good is the solution?
• Space complexity: How much storage is needed?
• Time complexity: How many operations are needed?
38
Key properties of search algorithms
• Completeness: Are we assured to find a solution, if one
exists?
• Optimality: How good is the solution?
• Space complexity: How much storage is needed?
• Time complexity: How many operations are needed?
39
Search complexity
• Evaluated in terms of two characteristics:
• Branching factor of the state space (“b”): how many operators
(upper limit) can be applied at any time?
40
Analyzing BFS
Good news:
• Complete.
• Paths to different goals can be explored at the same time.
• Guaranteed to find shallowest path to the goal if unit cost per step.
Will not necessarily find optimal path if graph is weighted.
Bad news:
• Exponential time complexity: O(bd)
41
Analyzing DFS
Good news:
• Linear space complexity: O(bm)
• m is the maximum depth of the tree
• Why? Need to remember where we are at each level of the tree
• Easy to implement recursively (do not even need queue data
structure).
• More efficient than BFS if there are many paths leading to
solution.
42
Analyzing DFS
Good news:
• Linear space complexity: O(bm)
• Easy to implement recursively (do not even need queue data
structure).
• More efficient than BFS if there are many paths leading to
solution.
Bad news:
• Exponential time complexity: O(bm)
• Not optimal.
• DFS may not complete!
• NEVER use DFS if you suspect a big tree depth!
43
Uniformed Search Algorithms
Basic algorithms
• Breadth-first search
• Depth-first search
44
General Step Cost
• Actions often have different costs
45
Uniform Cost Search
• Goal: Fix BFS to ensure an optimal path with general step
costs (i.e., in a weighted graph).
Important distinction:
• Unit cost = Problem where each action has the same cost.
• General cost = Actions can have different costs.
46
Uniform Cost Search
• Goal: Fix BFS to ensure an optimal path with general step
costs (i.e., in a weighted graph).
Important distinction:
• Unit cost = Problem where each action has the same cost.
• General cost = Actions can have different costs.
• Approach:
• Use a priority queue instead of a simple queue.
• Insert nodes in the increasing order of the cost of the path so far.
• Properties:
• Guaranteed to find optimal solution for with general step costs
(same as BFS when all operators have the same cost).
47
Example
• In what order are nodes expanded using Uniform cost
search?
48
Example - solved
49
Uniformed Search Algorithms
Basic algorithms
• Breadth-first search
• Depth-first search
50
Depth-limited search
• Algorithm: search depth-first, but terminate a path either
if a goal state is found, or if the maximum depth allowed
is reached.
• Always terminates:
• Avoids the problem of search never terminating by imposing a
hard limit on the depth of any search path.
51
Iterative Deepening Search (IDS)
• Algorithm: do depth-limited search, but with increasing
depth.
• Expands nodes multiple times, but computation time has
same complexity.
52
Analysis of IDS
• Complete (like BFS).
• Has linear memory requirements (like DFS).
• Classical time-space tradeoff.
• Recall from last lecture: achieving rationality subject to resource
constraints
• Will see similar trade-off often in this course.
53
Analysis of IDS
• Complete (like BFS).
• Has linear memory requirements (like DFS).
• Classical time-space tradeoff.
• Recall from last lecture: achieving rationality subject to resource
constraints
• Will see similar trade-off often in this course.
• Optimal for problems with unit step costs.
• This is the preferred method for large state spaces, where
the solution path length is unknown.
54
Summary of uninformed search
• Main difference between methods is order in which they
consider states
• BFS
• Uniform cost search
• DFS
• Fixed-depth DFS
• Iterative deepening
• Assumes no knowledge about the problem:
• Very general, can be applied to any problem
• Very expensive, since no knowledge about the problem
• Some algorithms are complete
• All uninformed search methods have exponential worst-case
complexity.
55