0% found this document useful (0 votes)
20 views45 pages

Uninformed Search

Which search is best depends on the properties of the maze: - DFS would be a poor choice since it could get stuck exploring deep water areas without finding the goal. - BFS would eventually find the goal but would waste a lot of time exploring shallow water areas far from the goal. - UCS would be the best strategy since it prioritizes exploring shallow water areas first, finding the goal more quickly than BFS while avoiding getting stuck like DFS. So for a maze with both deep and shallow water areas, UCS would generally perform best by leveraging cost information to guide the search towards lower cost, shallow areas near the goal.

Uploaded by

yusifovyadigar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views45 pages

Uninformed Search

Which search is best depends on the properties of the maze: - DFS would be a poor choice since it could get stuck exploring deep water areas without finding the goal. - BFS would eventually find the goal but would waste a lot of time exploring shallow water areas far from the goal. - UCS would be the best strategy since it prioritizes exploring shallow water areas first, finding the goal more quickly than BFS while avoiding getting stuck like DFS. So for a maze with both deep and shallow water areas, UCS would generally perform best by leveraging cost information to guide the search towards lower cost, shallow areas near the goal.

Uploaded by

yusifovyadigar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Search

Agents

Uninformed
search
[Some slides created by Dan Klein and Pieter Abbeel for Intro to AI at UC Berkeley (ai.berkeley.edu). Some slides were taken from Columbia University AI course]
https://st3.depositphotos.com/1005404/18747/i/1600/depositphotos_187473334-stock-photo-search-white-robot-and-lens.jpg
Uninformed
search
- Use no domain knowledge!

- Uninformed search strategies do not


take into account the location of the
goal.

- Intuitively, these algorithms ignore


where they are going until they find a
goal and report success.

Uninformed agents searching for the goal.


Uninformed search
Use no domain knowledge!
Strategies:
1. Breadth-first search (BFS): Expand shallowest node
2. Depth-first search (DFS): Expand deepest node
3. Depth-limited search (DLS): Depth first with depth limit
4. Iterative-deepening search (IDS): DLS with increasing limit
5. Uniform-cost search (UCS): Expand least cost node
Breadth-first
search (BFS)
BFS: Expand shallowest first.
BFS Search
Pseudo-code
BFS
criteria?

This is a gif, wait for it to start 


Breadth-first search (BFS)
• Complete: Yes (if b is finite)
• Time: 1 + b + + + . . . + = O()
• Space: O()
◦ Note: If the goal test is applied at expansion rather than generation then O()

• Optimal: Yes (if cost = 1 per step).


• Implementation: fringe: FIFO (Queue)
How bad is BFS?

Time and Memory


requirements for breadth-
first search for a branching
factor b=10; 1 million
nodes per second; 1,000
bytes per node.
Memory requirement &
exponential time
complexity are the biggest
handicaps of BFS!
Question: If time and space complexities are exponential,
why use BFS?
Depth-first
search (DFS)
DFS: Expand deepest first.
DFS Search
Pseudo-code.
DFS
criteria?
This is a gif, wait for it to start 
Depth-first search (DFS)
• Complete: No, fails in infinite-depth spaces & spaces with loops
◦ Modify to avoid repeated states along path.
◦ ⇒ complete in finite spaces

• Time: O(): 1 + b + + + . . . + = O()


◦ Bad if m is much larger than d but if solutions are dense may be much faster than BFS.

• Space: O(bm) linear space complexity!


◦ (needs to store only a single path from the root to a leaf node, along with the remaining
unexpanded sibling nodes for each node on the path, hence the m factor.)
• Optimal: No
• Implementation: fringe: LIFO (Stack)
How bad is DFS?
For depth = 16 we go
down from 10 exabytes
in BFS to ??? in DFS.

156 kilobytes!
Quiz: DFS vs BFS
When will BFS outperform DFS?

When will DFS outperform BFS?

[Demo: dfs/bfs maze water (L2D6)]


Video of Demo Maze Water DFS/BFS
(part 1)
Video of Demo Maze Water DFS/BFS
(part 2)
Depth-limited search
• DFS with depth limit l (nodes at level l has no successors).
• Select some limit L in depth to explore with DFS

https://slideplayer.com/slide/12719512/
If have some knowledge about the
problem, may be we don’t need to
go to a full depth.

For example, if we know that any


city can be reached from another
city in at most L steps, with L < 36,
we can stop expanding at 36th step.
Depth-limited
search
Pseudo-code.
Iterative-deepening search
• Combines the benefits of BFS and DFS.
• Idea: Iteratively increase the search limit until the depth of the shallowest
solution d is reached.
• Applies DLS with increasing limits.
• The algorithm will stop if a solution is found or if DLS returns a failure (no
solution).
• Because most of the nodes are on the bottom of the search tree, it not a big
waste to iteratively re-generate the top
• Let’s take an example with a depth limit between 0 and 3.
Iterative Deepening
Idea: get DFS’s space advantage with BFS’s time
/ shallow-solution advantages
b
◦ 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. …..

Isn’t that wastefully redundant?


◦ Generally most work happens in the lowest level
searched, so not so bad!
Iterative Deepening
Limit = 0
Depth-
limited
search
(Limit =
1)
Depth-
limited
search
(Limit = 2)
Depth-
limited
search
(Limit = 3)
Uniform-cost
search
• The arcs in the search
graph may have weights
(different cost attached).
How to leverage this
information?

https://ds055uzetaobb.cloudfront.net/image_optimizer/5f3b305766eb8a8847f54619c1e697f36cd7b1e6.png
For this
problem
• BFS will find the shortest
path which may be costly.
• What if we want the
cheapest not shallowest
solution?
• Modify BFS: Prioritize by
cost not depth → Expand
node n with the lowest path
cost g(n)
• Explores increasing costs.
Uniformed-
cost search
Pseudo-code
Uniform-cost search
Let’s say we need to go from Baku to
Sheki. 70
Sheki Ganja

BFS would find route: Baku -> Sumgayit ->

230
Sheki, because it need to expand only

350
twice. Total distance = 30 + 350 = 380

UCS would find route: Sumgayit Xirdalan


Baku ->Xirdalan -> Ganja -> Sheki,
30
because it expands the least-cost node 10
first. Total distance = 10 + 230 + 70 = 310, Baku
which is lower than BFS route.
Uniform-cost search
• Complete: Yes Assuming best solution has a finite cost and minimum arc cost is positive.
• Time: O()
◦ Suppose C∗: cost of the optimal solution
◦ Every action costs at least ϵ (bound on the cost)
◦ The effective depth is roughly C∗/ϵ (how deep the cheapest solution could be).

• Space: O() (exponential in effective depth)


• Optimal: Yes
• Implementation: fringe = queue ordered by path cost g(n)
Uniform-cost
search
Strategy: expand lowest
path cost
The good: UCS is complete
and optimal!
The bad:
- Explores options in every
“direction”
- No information about goal
location
Uniform Cost Search
2 a G
Strategy: expand a cheapest b c 3
node first: 1 8 2
2 e
3 d f
Fringe is a priority queue 9 2
S h 8
(priority: cumulative cost) 1
1 p q r
15
Uniform Cost Search
2 a G
Strategy: expand a cheapest b c 3
node first: 1 8 2
2 e
3 d f
Fringe is a priority queue 9 2
S h 8
(priority: 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
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?
(part 1)
Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 2)
Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 3)
Examples using the map
Start: Las Vegas
Goal: Calgary

BFS

Order of Visit: Las Vegas, Los Angeles, Salt Lake City, El Paso, Phoenix, San Francisco,
Denver, Helena, Portland, Dallas, Santa Fe, Kansas City, Omaha, Calgary.
Examples using the map
Start: Las Vegas
Goal: Calgary

DFS

Order of Visit: Las Vegas, Los Angeles, El Paso, Dallas, Houston, New Orleans, Atlanta,
Charleston, Nashville, Saint Louis, Chicago, Duluth, Helena, Calgary.
Examples using the map
Start: Las Vegas
Goal: Calgary

UCS

Order of Visit: Las Vegas, Los Angeles, Salt Lake City, San Francisco, Phoenix, Denver, Helena,
El Paso, Santa Fe, Portland, Seattle, Omaha, Kansas City, Calgary.
8 Puzzle
https://kartikkukreja.files.wordpress.com/2015/06/8puzzle1.jpg
Example DFS

https://www.darpa.mil/ 43
Example
BFS

https://www.darpa.mil/ 44
Summary of algorithms

You might also like