Lecture04 Uninformed Search (Part 2)

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 39

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 (how
much time it takes to find the solution)
space complexity – maximum number of nodes in memory
(how much memory is needed)

Solving Problems By Searching – Uninformed Searches


Parameters to Measure
Complexities
Time and space complexity are measured in terms of
b – maximum branching factor of the search
tree (number of child nodes at each
nodes/number of operators)
d – depth of the least-cost solution (optimal
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.
 Breadth-first search
 Uniform-cost search
 Depth-first search
 Depth-limited search
 Iterative deepening search
 Bidirectional search
 Constraint Satisfaction Search
 Uniform cost search (for minimum cost path problem)
Solving Problems By Searching – Uninformed Searches
Breadth-first search

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
Solving Problems By Searching – Uninformed Searches
Breadth-first Search
# State Depth Parent # Visit
1 Arad 0 -- N (not visited)
2 Zerind 1 1 N
3 Sibiu 1 1 N
4 Timisoara 1 1 N
5 Arad - V Ignore since it is
visted
6 Oradea 2 2 N
7 Lugoj 2 4 N
8 Fagaras 2 3 N
9 Rimnicu Vlicea 2 3 N

10 Zerind - V Ignore since it is


visted
11 Sibiu - V Ignore since it is
visted

12 Mehadia 3 7 N

13 Bucharest 3 8 Goal

Solving Problems By Searching – Uninformed Searches


Properties of Breadth-first Search

 Complete: Yes (if b is finite)~ means solution is reach if it


exist
 Optimal: Yes (if cost = 1 per step); not in general
 Time:1+ b + b2 + b3 + b4 + … + bd+1 −b = O(bd+1)
 Exponential in the depth of the solution d
 Space: O(bd+1) -- Keeps every node in memory
 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 Complexity (same
for memory complexity)

Depth Number of nodes


0 1
1 21 = 2
2 22 = 4
3 23 = 8
d 2d = b d
Total nodes O(bd)

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


Depth First Search
 Deepest node is expanded first
 Only when the search hits a dead end (a nongoal node with
no expansion) search go back and expands nodes at
shallower levels.
Arad

Zerind Sibiu Timisoara

Arad-Zerind-Arad again,
Arad Oradea form a cycle search

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
 Complete: No. Fails in infinite-depth spaces,
spaces with loops. Modify to avoid repeated
states on path
 Optimal: No. The found solution may not be the
optimal.
 Time: 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.
 Space: O(bm) , i.e., linear in depth

Let b: Branching factor


m: Maximum Depth
Solving Problems By Searching – Uninformed Searches
Time Complexity

Reference source:
https://people.cs.pitt.edu/~milos/courses/cs1571-Fall02/lectures/Class3.pdf
Solving Problems By Searching – Uninformed Searches
Space Complexity

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

Limit l

Time complexity: O(bl)


Memory complexity: O(bl)

Solving Problems By Searching – Uninformed Searches


Iterative Deepening Search
Repeated depth-limited search with increasing depth
Means that: try all depth limits in an increasing order by searching
depth limit l=0, then l=1, l = 2 till the solution is reached

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. Solution is reached if exists.


 Optimal: Yes, for constant edge cost
 Time: (d+1)b0 + db1 + (d-1)b2 +… +3bd-2+2bd-1+
1bd =O(bd)
 Exponential in the depth of solution d worse than
BFS
 Space: O(bd)

Solving Problems By Searching – Uninformed Searches


Properties of Iterative
Deepening Search
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


Uniform-cost Search
 Algorithm that finds a shortest path: Dijkstra’s algorithm
 The strategy is named as Uniform Cost Search in AI

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 >= ε.

 Optimal: Yes (nodes are expanded in order of g(n)).

 Time: ( C */  )
O(b )
 Space:
 For both time and space complexity: number of nodes with the
cost g(n) smaller than the optimal cost

Note: Breadth-First is equivalent to Uniform-Cost Search with edge cost equal a


constant.

Solving Problems By Searching – Uninformed Searches


Bi-Directional Search
 Find path from initial state to the unique goal state
 Aim to find shortest path
 Search in two direction
 From initial state (forward search)
 From goal state (backward search, use inverse operators for the goal-directed search)
 Need to merge solution (compare whether both reach the same solution)
 Cut the search tree by half

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