Problem Solving by Searching
Problem Solving by Searching
SEARCHING
TABLE OF
CONTENTS
• Problem - solving agents
• Problem types
• Problem formulation
• Example problems
• Basic search algorithms
Search
Problem STATE SPACE START
A search algorithm
ta ke s a p ro b le m a s
Th e s e t o f a ll
SPACE
a n in p u t a n d
re tu rn s a s o lu tio n in
p o s s ib le s ta te s Th e s e a rc h p ro b le m b e g in s
wh e re th e a g e n t
th e fo rm o f a c tio n c a n b e fo rm s a fro m a s p e c ific s ta rt s ta te ,
a g e n t wh ic h a c ts
. a g e n t c o m m e n c e s its
a s a s ta rtin g p o in t e xp lo ra tio n .
fo r th e a g e n t’s
e xp lo ra tio n
SEARCHING FOR SOLUTION
• search tree- possible action sequences starting at the initial state
• Nodes- states
• parent node
• Child node
• FRONTIER - The set of all leaf nodes available for expansion at any given point
Formulate goal:
be in Bucharest
Formulate problem:
states: various cities
actions: drive between cities
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
•Transition(Sibiu, Go(Fagaras)) → Fagaras
•Transition(Fagaras, Go(Bucharest)) → Bucharest
states?
actions?
goal test?
path cost?
THANK YOU!
Search Strategy
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?
TIME COMPLEXITY: number of nodes generated
SPACE COMPLEXITY: maximum number of nodes in
memory
OPTIMALITY: does it always find a least-cost solution?
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 ∞)
h
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
–fringe is a FIFO queue, i.e., new
successors go at end
Search Strategy
Search Strategy
Complete? Yes (if b is finite)
Time? = O(b )
d
Time Complexity
What is the time complexity of DFS?
The time complexity of DFS is O(b^m), where b is the branching factor (the maximum number of successors of any node), and m is the maximum
depth of the search tree.
Space Complexity
What is the space complexity of DFS?
The space complexity of DFS is O(bm) . This is because, at most, DFS needs to store the deepest path it is exploring, which can be up to m nodes
deep, with each node having up to b children.
Optimality
Is DFS optimal?
No, DFS is not optimal. DFS does not guarantee finding the least-cost solution or the shortest path. It might find a solution, but that solution is not
necessarily the best one.
Depth-limited search
• The embarrassing failure of depth-first search in
infinite state spaces can be alleviated by supplying
depth-first search with a predetermined depth
limit.
• Completeness: DLS search algorithm is complete if the solution is above the depth-
limit.
• Time Complexity: Time complexity of DLS algorithm is O(bℓ).
• Space Complexity: Space complexity of DLS algorithm is O(b×ℓ).
• Optimal: Depth-limited search can be viewed as a special case of DFS, and it is also
not optimal
Iterative deepening search
• Iterative Deepening Search (IDS) is a search strategy that aims to combine the advantages of both Depth-
First Search (DFS) and Breadth-First Search (BFS). Here are the key points about IDS:
• Gradual Depth Increase: IDS starts with a depth limit of 0 and gradually increases the depth limit until the
goal node is found. It explores all nodes at a given depth limit before increasing the limit.
• Benefits of IDS:
• Memory Efficiency: Similar to DFS, IDS has modest memory requirements of O(bd), where b is the
branching factor and d is the depth of the shallowest goal node. This is because it only keeps track of nodes
at the current depth limit.
• Completeness: IDS is complete if the branching factor bbb is finite. This means it will eventually find a
solution if one exists.
• Optimality: IDS is optimal for finding the shortest path in a tree/graph where the path cost is non-
decreasing with depth. This is because it explores nodes level by level, similar to BFS.
function ITERATIVE-DEEPENING-SEARCH(problem) returns a solution, or
failure
for depth = 0 to ∞ do result ← DEPTH-LIMITED-SEARCH(problem, depth)
if result = cutoff then return result
Properties of iterative deepening
search
• Complete? Yes
•
• Time? O(bd)
•
• Space? O(bd)
•
• Optimal? Yes, if step cost = 1
Bi-Directional search algorithm