You are on page 1of 30

TAI2151 – Artificial Intelligence

Fundamentals

Lecture 4 – Solving Problems


by Searching (Uninformed
Searches)
Part 2

Solving Problems By Searching – Uninformed Searches


Search Strategies
A search strategy is defined by picking the order of node expansion.

Strategies are evaluated along the following dimensions:


completeness – does it always find a solution if one exists?
optimality – does it always find a least-cost solution?
time complexity – number of nodes generated/expanded
space complexity – maximum number of nodes in memory

Time and space complexity are measured in terms of


b – maximum branching factor of the search tree
d – depth of the least-cost solution
m – maximum depth of the state space (may be )

Solving Problems By Searching – Uninformed Searches


Uninformed Search Strategies
Uninformed (blind) strategies use only the information
available in the problem definition and have no information about
number of steps or the path cost from current state to the goal
state ( only they can distinguish a goal state from nongoal state.)
vs.
informed search techniques which might have additional
information
(e.g. a compass).
• Breadth-first search
• Uniform-cost search
• Depth-first search
• Depth-limited search
• Iterative deepening search
• Bidirectional search
• Constraint Satisfaction Search

Solving Problems By Searching – Uninformed Searches


Breadth-first search FIFO

All the nodes generated at depth d in the search tree are expanded
before the nodes at depth d+1.

Breadth-first search trees after 0, 1, 2, and 3 node expansions.

Solving Problems By Searching – Uninformed Searches


Breadth first search - Example

Solving Problems By Searching – Uninformed Searches


Breadth-first Search
• Expand shallowest unexpanded node
• Implementation:
• QUEUEING-FN = put successors at end of queue.

Arad

Zerind Sibiu Timisoara

Arad Oradea Arad Oradea Fagaras Rimnicu Arad Lugoj


Vilcea
Solving Problems By Searching – Uninformed Searches
Properties of Breadth-first Search

• Complete: Yes (if b is finite)


Yes (if cost = 1 per step); not in general
• Optimal: 1+ b + b2 + b3 + b4 + … + bd+1 −b = O(bd+1)
O(bd+1) -- Keeps every node in memory
• Time:
• Space: Note: Space is the big problem; can easily generate 1MB/sec so 24 hrs =
86GB

Solving Problems By Searching – Uninformed Searches


Breadth-First Search: Time & Memory

• Branching (b) =10


• 1000 nodes per second
• 100 bytes per node

Solving Problems By Searching – Uninformed Searches


Romania with Edge Costs

Solving Problems By Searching – Uninformed Searches


Uniform-cost Search (Dijkstra, 1959)
• Let g(n) be path cost of node n.
• Expand least-cost unexpanded node
• Implementation:
• QUEUEING-FN = insert in order of increasing path length

Arad

75 118
140
Zerind Sibiu Timisoara

75 140 118

75 111
71 118
Arad Oradea Arad Lugoj
150 146 236 229

Solving Problems By Searching – Uninformed Searches


Uniform cost search finds the cheapest solution provided a simple
requirement is met: the cost of a path must never decrease as we go
along the path.

The problem is to get from S to G.

Solving Problems By Searching – Uninformed Searches


Properties of Uniform-Cost Search

• Complete: Yes if arc costs >= ε.


Yes (nodes are expanded in order of g(n)).
• Optimal:
• Time: ( C */  )
• Space: O( is equivalent
Note: Breadth-First b
equal a constant.
) to Uniform-Cost Search with edge cost

Solving Problems By Searching – Uninformed Searches


Depth-First Search

• Depth-first search always expands one of the nodes at the deepest level of the tree.

• Only when the search hits a dead end (a nongoal node with no expansion) search go
back and expands nodes at shallower levels.

Solving Problems By Searching – Uninformed Searches


DFS - Example

Solving Problems By Searching – Uninformed Searches


Depth-First Search
• Expand deepest unexpanded node.
• Implementation
• QUEUEING-FN = insert successors (newly generated states) at front
of queue
Arad

Zerind Sibiu Timisoara

Arad Oradea Note: Depth-first search can


perform infinite cycles excursions.
Need a finite, non-cyclic search
Timisoara
Arad Sibiu space or repeated-state checking.
Solving Problems By Searching – Uninformed Searches
Properties of Depth-First Search
No: Fails in infinite-depth spaces, spaces with loops. Modify to avoid
• Complete: repeated states on path
→ Complete in finite spaces
No

• Optimal: O(bm): terrible if m (maximum depth) is much larger than d, but if


solutions are dense may be much faster than breadth-first search.
O(bm) , i.e., linear in depth
• Time:

• Space:

Let b: Branching factor


m: Maximum Depth
Solving Problems By Searching – Uninformed Searches
Writing Depth-First Search as a Recursive
Procedure
Procedure DEPTH-FIRST (N)
Begin
If N=Goal Then
Return (“SUCCESS”)
ELSE
For C in CHILDREN (N) DO
DEPTH-FIRST(C)
Return(“FAILURE”)
End

Note: In recursive implementation, the program stack acts as


the queue.

Solving Problems By Searching – Uninformed Searches


Depth-Limited Search
• Depth-Limited Search = depth-first search with
depth limit l.

• Implementation:
• Nodes at depth l have no successors

Solving Problems By Searching – Uninformed Searches


Iterative Deepening Search
Repeated depth-limited search with increasing depth

Solving Problems By Searching – Uninformed Searches


IDS - Example

Solving Problems By Searching – Uninformed Searches


IDS – Example (cont.)

Solving Problems By Searching – Uninformed Searches


IDS – Example (cont.)

Solving Problems By Searching – Uninformed Searches


IDS – Example (cont.)

Solving Problems By Searching – Uninformed Searches


Iterative Deepening Search: depth=0

Arad

Solving Problems By Searching – Uninformed Searches


Iterative Deepening Search: depth=1

Arad

Zerind Sibiu Timisoara

Solving Problems By Searching – Uninformed Searches


Iterative Deepening Search: depth=2

Arad

Zerind Sibiu Timisoara

Arad Oradea Arad Oradea Fagaras Rimnicu Arad Lugoj


Vilcea

Solving Problems By Searching – Uninformed Searches


Properties of Iterative Deepening Search
• Complete: Yes
Yes for constant edge cost
• Optimal: (d+1)b0 + db1 + (d-1)b2 +… +3bd-2+2bd-1+ 1bd =O(bd)

• Time: O(bd)

• Space:
Notes:
• Maximum space is same as depth-first
• Time complexity is the same order as breadth-first, and when branching factor
is large, time is very close even with repeated searches:
Example: b=10, d=5: BFS -> 111,111 expansions
IDS -> 123,456 expansions
binary trees: IDS twice as long as depth-first

Solving Problems By Searching – Uninformed Searches


Conclusions
• Interesting problems can be cast as search problems, but
you’ve got to set up state space
• Iterative Deepening Search is pretty effective in space and
time.

Summary

Solving Problems By Searching – Uninformed Searches


Conclusions Continued ...
• 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
• There are various strategies for “uninformed search”
– breadth-first
– Uniform cost search
– depth-first
– iterative deepening
– bidirectional search
– Constraint satisfaction Search ()
• Repeated states can lead to infinitely large search trees
– we looked at methods for detecting repeated states

Solving Problems By Searching – Uninformed Searches


Conclusions Continued ...

• All of the search techniques so far are “blind” in that they do not look at how far
away the goal may be: next we will look at informed or heuristic search, which
directly tries to minimize the distance to the goal.

• Example we saw: greedy search

Solving Problems By Searching – Uninformed Searches

You might also like