[24F-COSE361] 1. Search (2)(1)
[24F-COSE361] 1. Search (2)(1)
Search (2)
Search takes time O(bm) space O(bm) Search takes time O(bs) space O(bs)
May get stuck on infinite paths Guaranteed to find a solution if one exists
Finds the “leftmost” solution Finds the “shallowest” solution
Iterative Deepening Search
▪ Idea: DFS’s space advantage + BFS’s time/shallow-solution advantages
▪ For every depth limit, perform DFS until the depth limit is reached
▪ Run a DFS with depth limit 1. If no solution…
▪ Run a DFS with depth limit 2. If no solution…
▪ Run a DFS with depth limit 3. …..
b
…
Example: Iterative Deepening Search
▪ Build search trees for depth = 0, 1, 2 on the search graph below
▪ Starting from S (a root node, depth = 0)
▪ Quiz: what is the total number of nodes visited?
a G
b c
e
d f
S h
p r
q
Iterative Deepening Search
▪ Idea: DFS’s space advantage + BFS’s time/shallow-solution advantages
▪ For every depth limit, perform DFS until the depth limit is reached
▪ Space Complexity b
…
▪ O(bs), linear in s, similar to DFS
s tiers
▪ Completeness
▪ Yes, same as BFS
▪ Optimality
▪ No, only the shallowest solution, same as BFS
▪ (but Yes if costs are all 1)
Quiz
▪ Find the shortest path (in terms of # of nodes in the path) from
Start node to Goal node
a G
b c
e
d
f
S h
p r
q
Cost-Sensitive Search
a GOAL
2 2
b c
3
2
1 8
2 e
Cost: 3 d
f
9 8 2
START h
1 4 2
p 4 r
15
q
▪ BFS finds the shortest path in terms of number of actions, but not the least-cost path
▪ We will now cover a similar algorithm which does find the least-cost path
Uniform Cost Search
Uniform Cost Search (a.k.a. Dijkstra’s algorithm)
2 a G
Strategy: expand a cheapest node first b c
1 8 2
2 e
Fringe is a priority queue 3 d f
9 2
S h 8
(i.e., ordered by cumulative cost) 1
1 p q r
15
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G
q 11 c G 10 a
a
Uniform Cost Search (UCS) Properties
▪ What nodes does UCS expand?
▪ Processes all nodes with cost less than cheapest solution!
b c1
▪ If that solution costs C* and arcs cost at least , then the …
“effective depth” is roughly C*/ C*/ “tiers”
c2
▪ Takes time O(b ) (exponential in effective depth)
C*/
c3
▪ Is it complete?
▪ Yes, assuming best solution has a finite cost and minimum arc
cost is positive
▪ Is it optimal?
▪ Yes
Uniform Cost Search Issues
▪ UCS explores increasing cost contours c1
…
c2
c3
▪ The good:
▪ UCS is complete and optimal!
▪ The bad:
▪ Explores options in every “direction”
▪ No information about goal location Start Goal
▪ How can we fix that?
Video of Demo Empty UCS
Video of Demo Contours UCS Pacman Small Maze
Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS?
Comparing Uninformed Search Algorithms
▪ All these search algorithms are the same except for fringe strategies
▪ Conceptually, all fringes are priority queues (i.e., collections of nodes with priorities)
▪ Practically, for DFS and BFS, you can use LIFO stacks and FIFO queues
Summary
▪ Search problem:
▪ States (configurations of the world)
▪ Successor function (world dynamics)
▪ Actions and costs
▪ Start state and goal test
▪ Search tree:
▪ Nodes: represent plans for reaching states
▪ Plans have costs (sum of action costs)
▪ Search algorithm:
▪ Systematically builds a search tree
▪ Chooses an ordering of the fringe (unexplored nodes)
▪ Finds least-cost plans
Example: Pancake Problem
4
2 3
2
3
4
3
4 2
3 2
2
4
3
General Tree Search
10
5
11.2
Example: Heuristic Function for Traveling
h(x)
Quiz: Heuristic Function for Pancake
Slido.com
What could be the heuristic function for the pancake problem? → Code: 2650956
Goal state
Quiz: Heuristic Function for Pancake
Example heuristic: the number (ID) of the largest pancake that is still out of place
3
h(x): 4
3
4
3 0
4
4 3
4
4 2
3
Greedy Search
Greedy Search (with Heuristics)
▪ Expand the node that seems closest to the goal
Heuristics h(x)
Cost
178
▪ A common case:
▪ Greedy best-first may take you straight to the (wrong) goal
b
▪ Worst-case: …
▪ Properties:
▪ Exponential both for time and space
▪ Not complete, not optimal
Video of Demo Contours Greedy (Empty)
Video of Demo Contours Greedy (Pacman Small Maze)
Example: Uniform-Cost Search
State space graph with cost Search Tree
8
e
Cost 1
S 1 a 3 d 2 G
1
c 1 b
8
e h=1
Cost 1
S 1 a 3 d 2 G
h=6 1 h=5 h=2 h=0
c 1 b
h=7 h=6