Lec04
Lec04
Lec04
Artificial Intelligence
Lecture 4
Solving Problems by Searching
(Part II)
1
Contents
4.1 Uninformed Search Strategy
4.1.1 Breadth-first search
4.1.2 Uniform-cost search
4.1.3 Depth-first search
4.1.4 Depth-limited search
4.1.5 Iterative deepening search
4.1.6 Bidirectional search
4.2 Comparison of Search Algorithms
4.3 Application of Breadth-first/Depth-first Search to 8- Puzzle
Problem
4.4 Techniques for Avoiding Repeated States
4.5 Searching With Partial Information
2
Depth-limited search
Iterative deepening search
Bidirectional search
Breadth-first search
Root node is expanded first
Breadth-first search
Implementation:
Use first-in-first-out (FIFO) queue to ensure that nodes that are
visited first will be expanded first
FIFO queue puts all newly generated nodes (successors) at the end
of the queue
shallow nodes are expanded before deeper nodes
Breadth-first search
Implementation:
Implementation: fringe is a FIFO queue
Fringe - nodes in a queue
waiting to be explored
1
2
4
FRINGE = (1)
3
5
7
Goal
9
8
Breadth-first search
Implementation:
1
2
4
FRINGE = (2, 3)
3
5
9
9
Breadth-first search
Implementation:
1
2
4
FRINGE = (3, 4, 5)
3
5
9
10
Breadth-first search
Implementation:
1
2
4
FRINGE = (4, 5, 6, 7)
3
5
9
11
Breadth-first search
Implementation:
1
2
4
FRINGE = (5, 6, 7, 8)
3
5
9
12
Breadth-first search
Implementation:
1
2
4
FRINGE = (6, 7, 8)
3
5
9
13
Breadth-first search
Implementation:
1
2
4
FRINGE = (7, 8, 9)
3
5
9
14
Breadth-first search
Implementation:
1
2
4
FRINGE = (8, 9)
3
5
7
Goal
9
15
Breadth-first search
Properties of breath-first search
Completeness: Yes (if b is finite, d is finite)
Optimality: Yes (when all actions have the same cost); not in
general
16
Breadth-first search
Time and Memory Requirements
is the no. of its
Assumptions:
neighbors
Branching factor b =10;
Time 10,000 nodes generated/ second;
Space - 1000 bytes / node
17
18
Zerind
75
140
118
Sibiu
140
75
71
Arad
150
Oradea
146
Timisoara
118
118
Arad
236
19
111
Lugoj
229
80 < 99
Cost = 80 + 97 = 177
Sibiu-Fagaras-Bucharest
= 99+211 = 310
Sibiu-Rimnicu Vilcea-Pitesti
= 80+97+101 = 278
Discard
this path
Sibiu-Rimnicu Vilcea-Pitesti
= 80+97+101 = 278
g-cost = 278;
Note:
Uniform-cost search is guided by path costs rather than depths, so its
complexity cannot be categorized in terms of b and d.
25
26
Depth-first Search
Always expands one of the nodes at the deepest level of the tree.
Only when the search hits a deadend (a non-goal node with no
expansion) search goes back and expands nodes at shallower levels.
Depth-first Search
Expand deepest unexpanded node.
Implementation: fringe is a LIFO (Last In First Out) queue
(also known as stack)
- QueueingFn: put successors at the front of the queue (LIFO)
Arad
Zerind
Arad
Zerind Sibiu
Sibiu
Timisoara
Note: Depth-first search can
perform infinite cycles excursions.
Need a finite, non-cyclic search
space or repeated-state checking.
Oradea
Timisoara
28
Depth-first Search
29
Depth-first Search
30
Depth-first Search
31
Depth-first Search
32
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
33
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
34
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
35
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
36
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
37
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
38
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
39
Depth-first Search
Nodes that have been expanded
and have no descendants in the
fringe can be removed from the
memory (shown in black)
Goal node
40
41
Depth-first Search
Implementation
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue (=stack)
1
2
4
FRINGE = (1)
Goal node
42
Depth-first Search
Implementation
1
2
FRINGE = (2, 3)
43
Depth-first Search
Implementation
Depth-first search uses
LIFO queue (stack)
1
2
FRINGE = (4, 5, 3)
44
Depth-first Search
Implementation
1
2
45
Depth-first Search
Implementation
1
2
46
Depth-first Search
Implementation
1
2
47
Depth-first Search
Implementation
1
2
48
Depth-first Search
Implementation
1
2
49
Depth-first Search
Implementation
1
2
50
Depth-first Search
Implementation
1
2
51
Depth-first Search
Implementation
1
2
52
Depth-first Search
Implementation
1
2
53
Depth-first Search
Implementation
1
2
Goal node
54
Depth-first Search
Properties of depth-first search
Complete? No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated states along path
complete in finite spaces
Time? O(bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than breadthfirst
m is the maximum depth of any node
Space? O(bm), i.e., linear space!
Optimal? No
If the left subtree is of unbounded depth but contains no solution,
depth-first search would never terminate and so it is not complete.
55
Depth-limited search
Supply depth-first search with a predetermined depth limit l
Solves the infinite-path problem of depth-first search.
But, introduces incompleteness:
if l < d (the shallowest goal is beyond the depth limit) then
incompleteness results
k
Depth-limited search
Recursive implementation of depth-limited search
57
is complete?
Has linear space complexity?
Has time complexity of O(bd)?
58
59
Let b = 10 and d = 5,
N(IDS) = 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
N(BFS) = 10 + 100 + 1,000 + 10,000 + 100,000 + 999,990 = 1,111, 100
Complete: Yes
Optimal:
Yes for constant edge cost
Time:
db1 + (d-1)b2 + +3b d-2+2b d-1+ 1bd = O(bd)
Space:
O(bd)
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
62
63
Bidirectional Search
Initial State
Final State
* Completeness: yes
d/2
* Optimality: yes
O(bd) vs. O(bd/2) ? with b=10 and d=6 results in 1,111,111 vs. 2,222
64
65
67
68
- Fully observable
- Deterministic
70
71
The End
72