Professional Documents
Culture Documents
• Cannot say one nongoal state looks better than another nongoal state
• Implementation:
– For BFS, fringe is a first-in-first-out (FIFO) queue
– new successors go at end of the queue
• Repeated states?
– Simple strategy: do not add parent of a node as a leaf
Breadth-First Search (BFS)
• Algorithm outline:
– Always select from the OPEN the node with the smallest depth for
expansion, and put all newly generated nodes into OPEN
– OPEN is organized as FIFO (first-in, first-out) list, I.e., a queue.
– Terminate if a node selected for expansion is a goal
• Properties
– Complete
– Optimal (i.e., admissible) if all operators have the same cost. Otherwise,
not optimal but finds solution with shortest path length (shallowest
solution).
– Exponential time and space complexity,
O(b^d) nodes will be generated, where
d is the depth of the solution and
b is the branching factor (i.e., number of children) at each node
Breadth-First Search (BFS)
Example: Map Navigation
State Space:
S = start, G = goal, other nodes = intermediate states, links = legal transitions
A B C
S G
D E F
BFS Search TreeA B C
S G
S
D E F
Queue = {S}
Select S
Goal(S) = true?
If not, Expand(S)
BFS Search TreeA B C
S G
S
D E F
A D
Queue = {A, D}
Select A
Goal(A) = true?
If not, Expand(A)
BFS Search TreeA B C
S G
S
D E F
A D
B D Queue = {D, B, D}
Select D
Goal(D) = true?
If not, expand(D)
BFS Search TreeA B C
S G
S
D E F
A D
B D A E Queue = {B, D, A, E}
Select B
etc.
BFS Search TreeA B C
S G
S
D E F
A D
B D A E
C E S E S B B F
Level 3
Queue = {C, E, S, E, S, B, B, F}
BFS Search TreeA B C
S G
S
D E F
A D
B D A E
C E S E S B B F
D F A B F D C E A C G
Level 4
Expand queue until G is at front
Select G
Goal(G) = true
Breadth-First Search
Breadth-First Search (BFS) Properties
• Complete? Yes
d=0
• Space Complexity
– how many nodes can be in the queue (worst-
d=1
case)?
– at depth d there are bd+1 unexpanded nodes in d=2
the Q = O (bd+1) G
Examples of Time and Memory Requirements for Breadth-First Search
Depth of Nodes
Solution Generated Time Memory
8 109 31 hours 1 TB
12 1013 35 years 10 PB
Depth-First (DFS)
• Algorithm outline:
– Always select from the OPEN the node with the greatest depth for
expansion, and put all newly generated nodes into OPEN
– OPEN is organized as LIFO (last-in, first-out) list
– Terminate if a node selected for expansion is a goal
• Properties:
May not terminate without a "depth bound," i.e., cutting off search
below a fixed depth D (How to determine the depth bound?)
Not complete (with or without cycle detection, and with or without a
cutoff depth)
Exponential time, O(b^d), but only linear space, O(bd), required
Can find deep solutions quickly if lucky
When search hits a deadend, can only back up one level at a time even if
the "problem" occurs because of a bad operator choice near the top of the
tree. Hence, only does "chronological backtracking"
DFS Search TreeA B C
S G
S
D E F
A D
Queue = {A,D}
DFS Search TreeA B C
S G
S
D E F
A D
B D
Queue = {B,D,D}
DFS Search TreeA B C
S G
S
D E F
A D
B D
Queue = {C,E,D,D}
C E
DFS Search TreeA B C
S G
S
D E F
A D
B D
Queue = {D,F,D,D}
C E
D F
DFS Search TreeA B C
S G
S
D E F
A D
B D
Queue = {G,D,D}
C E
D F
G
Depth-First Search (DFS) Properties
• Complete?
– Not complete if tree has unbounded depth
• Optimal?
– No
• Time complexity?
– Exponential
• Space complexity?
– Linear
What is the Complexity of Depth-First Search?
• Time Complexity
– maximum tree depth = m d=0
– assume (worst case) that there is
1 goal leaf at the RHS at depth d d=1
– so DFS will generate O (bm) d=2
G
d=0
Depth of Nodes
Solution Generated Time Memory
While no solution, do
DFS from initial state S0 with cutoff L
• Optimal
• Only if path cost is a non-decreasing function of depth
• IDS combines the small memory footprint of DFS, and has the
completeness guarantee of BFS
• In practice, IDS is the preferred uniform search method with a large
search space and unknown solution depth
Bidirectional Search
• Idea
– simultaneously search forward from S and backwards from G
– stop when both “meet in the middle”
– need to keep track of the intersection of 2 open sets of nodes
• Complexity
– time complexity at best is: O(2 b(d/2)) = O(b (d/2))
– memory complexity is the same
Bi-Directional Search
Uniform Cost Search
• Optimality: path found = lowest cost
– Algorithms so far are only optimal under restricted
circumstances
• Let g(n) = cost from start state S to node n
• Uniform Cost Search:
– Always expand the node on the fringe with minimum cost
g(n)
– Note that if costs are equal (or almost equal) will behave
similarly to BFS
• A Generalized version of Breadth-First Search
– C(ni, nj) = cost of going from ni to nj
– Guarantee to find the minimum cost path
– Dijkstra Algorithm
Uniform-Cost (UCS)
• Algorithm outline:
– Always select from the OPEN the node with the least g(.) value for expansion,
and put all newly generated nodes into OPEN
– Nodes in OPEN are sorted by their g(.) values (in ascending order)
– Terminate if a node selected for expansion is a goal
Uniform Cost Search
Uniform-Cost (UCS)
• Complete (if cost of each action is not infinitesimal)
– The total # of nodes n with g(n) <= g(goal) in the state space is finite
– If n’ is a child of n, then g(n’) = g(n) + c(n, n’) > g(n)
– Goal node will eventually be generated (put in OPEN) and selected for
expansion (and passes the goal test)
• Optimal/Admissible
– Admissibility depends on the goal test being applied when a node is removed
from the OPEN list, not when it's parent node is expanded and the node is first
generated (delayed goal testing)
– Multiple solution paths (following different backpointers)
– Each solution path that can be generated from an open node n will have its path
cost >= g(n)
– When the first goal node is selected for expansion (and passes the goal test), its
path cost is less than or equal to g(n) of every OPEN node n (and solutions
entailed by n)
• Exponential time and space complexity, O(b^d) where d is the
depth of the solution path of the least cost solution
Comparison of Uninformed Search Algorithms
When to use what
• Depth-First Search:
– Many solutions exist
– Know (or have a good estimate of) the depth of solution
• Breadth-First Search:
– Some solutions are known to be shallow
• Uniform-Cost Search:
– Actions have varying costs
– Least cost solution is the required
This is the only uninformed search that worries about costs.
• Iterative-Deepening Search:
– Space is limited and the shortest solution path is required
Summary
• A review of search
– a search space consists of states and operators: it is a graph
– a search tree represents a particular exploration of search space