2. 2
Types of search strategies
Blind/ Uninformed search
Informed/ Heuristic based search
Any path/ non-optimal search
Optimal path search
3. 3
Performance measures
• Completeness:Is the algorithm guaranteed to
find a solution when there is one?
• Optimality:Does the strategy find the
optimal solution?
• Time complexity:How long does it take to
find a solution?
• Space Complexity:How much memory is
needed to perform the search?
4. Simple Search Algorithm
Let S be the start state
1. Initialize Q with the start node Q=(S) as only
entry; set Visited = (S)
2. If Q is empty, fail. Else pick node X from Q
3. If X is a goal, return X, we’ve reached the
goal
4. (Otherwise) Remove X from Q
5. Find all the children of node X not in Visited
6. Add these to Q; Add Children of X to
Visited
7. Go to Step 2
19. BFS: Example
S
BA
E FDC
G H
Q Visited
2 A,B S,A,B
3 B,C,D S,A,B,C,D
4 C,D,E,F S,A,B,C,D,E,F
5 D,E,F,G,H S,A,B,C,D,E,F,G,H
6
20. BFS: Example
S
BA
E FDC
G H
Q Visited
3 B,C,D S,A,B,C,D
4 C,D,E,F S,A,B,C,D,E,F
5 D,E,F,G,H S,A,B,C,D,E,F,G,H
6 E,F,G,H S,A,B,C,D,E,F,G,H
7
21. BFS: Example
S
BA
E FDC
G H
Q Visited
4 C,D,E,F S,A,B,C,D,E,F
5 D,E,F,G,H S,A,B,C,D,E,F,G,H
6 E,F,G,H S,A,B,C,D,E,F,G,H
7 F,G,H S,A,B,C,D,E,F,G,H
8
22. BFS: Example
S
BA
E FDC
G H
Q Visited
5 D,E,F,G,H S,A,B,C,D,E,F,G,H
6 E,F,G,H S,A,B,C,D,E,F,G,H
7 F,G,H S,A,B,C,D,E,F,G,H
8 G,H S,A,B,C,D,E,F,G,H
9
23. BFS: Example
S
BA
E FDC
G H
Q Visited
6 E,F,G,H S,A,B,C,D,E,F,G,H
7 F,G,H S,A,B,C,D,E,F,G,H
8 G,H S,A,B,C,D,E,F,G,H
9 H S,A,B,C,D,E,F,G,H
10
24. BFS: Example
S
BA
E FDC
G H
Q Visited
6 E,F,G,H S,A,B,C,D,E,F,G,H
7 F,G,H S,A,B,C,D,E,F,G,H
8 G,H S,A,B,C,D,E,F,G,H
9 S,A,B,C,D,E,F,G,H
10 S,A,B,C,D,E,F,G,H
25. BFS: Example
S
BA
E FDC
G H
Q Visited
1 S S
2 A,B S,A,B
3 B,C,D S,A,B,C,D
4 C,D,E,F S,A,B,C,D,E,F
5 D,E,F,G,H S,A,B,C,D,E,F,G,H
6 E,F,G,H S,A,B,C,D,E,F,G,H
7 F,G,H S,A,B,C,D,E,F,G,H
8 G,H S,A,B,C,D,E,F,G,H
9 H S,A,B,C,D,E,F,G,H
10 S,A,B,C,D,E,F,G,H
26. 26
Properties of Breadth-first
search
• Complete? Yes (if b is finite)
• Time? 1+b+b2+b3+… +bd = O(bd)
• Space? O(bd+1) (keeps every node in memory)
• Optimal? Yes (if cost = 1 per step)
• Space is the bigger problem (more than time).
27. 27
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
breadth-first
• Space? O(bm) (linear)
• Optimal? NO!
28. Problem with BFS
• Imagine searching a tree with branching
factor 8 and depth 10. Assume a node
requires just 8 bytes of storage. The
breadth first search might require up to:
= (8)10 nodes
= (23)10 X 23 = 233 bytes
= 8,000 Mbytes
= 8 Gbytes