Professional Documents
Culture Documents
Solving Problems by Searching: Associate Professor Email
Solving Problems by Searching: Associate Professor Email
Searching
Dr. Azhar Mahmood
Associate Professor
Email: azhar.mahmood@cust.edu.pk
Uninformed Search Strategies
• Uninformed search
– no information about the number of steps
– or the path cost from the current state to the goal
– search the state space blindly
• Depth-first search
– Depth-limited search
– Iterative deepening search
Breadth-first search
• The root node is expanded first (FIFO)
• All the nodes generated by the root node are then
expanded
• And then their successors and so on
Breadth-first search
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
2 3 FRINGE = (1)
4 5 6 7
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
2 3 FRINGE = (2, 3)
4 5 6 7
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
2 3 FRINGE = (3, 4, 5)
4 5 6 7
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
2 3 FRINGE = (4, 5, 6, 7)
4 5 6 7
Breadth-first Search (Analysis)
• Breadth-first search
– Complete – find the solution eventually
– Optimal, if step cost is 1
The disadvantage
– if the branching factor of a node is large,
– for even small instances (e.g., chess)
• the space complexity and the time complexity are
enormous
Properties of Breadth-First Search
• Complete? Yes (if b is finite)
• Time?
– Imagine searching a uniform tree where every state has b successors.
– The root of the search tree generates b nodes at the first level, each of which generates b
more nodes, for a total of b2 at the second level.
– Each of these generates b more nodes, yielding b 3 nodes at the third level, and so on.
Now suppose that the solution is at depth d. In the worst case, it is the last node generated
at that level.
– Then the total number of nodes generated is b + b2 + b3 + ···+ bd = O(bd)
– If the algorithm were to apply the goal test to nodes when selected for expansion, rather
than when generated, the whole layer of nodes at depth d would be expanded before the
goal was detected and the time complexity would be O(b d+1).)
– b+b2+b3+… +bd = O(bd+1)
• Space? :O(bd+1) (keeps every node in memory)
• Optimal? Yes (if cost = 1 per step)
Uniform Cost Search
• Breadth-first finds the shallowest goal state
– but not necessarily be the least-cost solution
– work only if all step costs are equal
Q Visited
1 A A
2
3
4
5
Depth-first Search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Is B a goal state?
Q Visited
1 A A
2 BC ABC
3
4
5
Depth-first Search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
•
Is D = goal state?
Q Visited
1 A A
2 BC ABC
3 DEC ABCD
4
5
Depth-first Search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Queue=[H,I,E,C]
Is H = goal state?
Q Visited
1 A A
2 BC ABC
3 DEC ABCDE
4 HIEC ABCDEHI
5
Depth-first Search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at fron
Is I = goal state?
Q Visited
1 A A
2 BC ABC
3 DEC ABCDE
4 HIEC ABCDEHI
5 IEC ABCDEHI
ABCDEHI
Depth-first Search
• Expand deepest unexpanded node
– fringe = LIFO queue, i.e., put successors at front
• Implementation:
Is E = goal state?
Q Visited
1 A A
2 BC ABC
3 DEC ABCDE
4 HIEC ABCDEHI
5 IEC ABCDEHI
6 EC ABCDEHI
7
Depth-first Search
Queue Visited
1 A A
4 HIEC ABCDEHI
5 IEC ABCDEHI
6 EC ABCDEHI
7 JKC ABCDEHIJK
8 KC ABCDEHIJK
Is K = goal state?
9 C ABCDEHIJK
10 FG ABCDEFHIJK
11 LMG ABCDEFGHIJKLM
12 MG ABCDEFGHIJKLM
13 G ABCDEFGHIJKLM
14 NO ABCDEFGHIJKLM
15 O ABCDEFGHIJKLMN
16 Empty ABCDEFGHIJKLMNO
Depth-first Search (Analysis)
• Not complete
– because a path may be infinite or looping
– then the path will never fail and go back try another
option
• Not optimal
– it doesn't guarantee the best solution
• It overcomes
– the time and space complexities
Properties of Depth-first Search
• Complete? No: fails in infinite-depth spaces, spaces
with loops
– Modify to avoid repeated states along path
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Depth-Limited Search
= depth-first search with depth limit l,
i.e., nodes at depth l have no successors
Recursive implementation:
29
Iterative Deepening Search
31
Iterative Deepening Search L=1
•
•
•
Summary of Algorithms
37
Summary
• Problem formulation usually requires abstracting
away real-world details to define a state space that
can feasibly be explored
38
Reading
• Artificial Intelligence: A Modern Approach, 3rd
edition
– Chapter 3: Solving problem by Searching
– Section 3.1- 3.4
• Informed/Heuristic Search
– Greedy best-first search
– A* search
– Heuristic functions