COMPUTERLESSON
HARDWARE
3
Search Strategies I
(Uninformed Search)
READING RESOURCES
• Müller. A. C., & Guido, S. (2016). Introduction to
Machine Learning with Python. O'Reilly Media. Inc.
• AI and ML Playlist
https://www.youtube.com/playlist?list=PLrjkTql3jnm_yol-ZK1QqPSn5YSg0NF9r
• AI and ML Tutorial
https://www.javatpoint.com/artificial-intelligence-tutorial
• Search Strategies
https://www.youtube.com/watch?v=bSv4CWMTeR0&t=64s
https://www.youtube.com/watch?v=8pTjoFiICg8
LESSON OUTLINE
• General Tree Search Principles
• Types of Search Algorithms
• Uninformed Search Strategies
• Breadth-First Search Algorithm
• Depth-First Search Algorithm
• Depth-Limited Search Algorithm
• Uniform-Cost Search Algorithm
• Iterative Deepening Depth-First Search Algorithm
• Bidirectional Search Algorithm
General Tree Search Principles
• In Summary Searching in AI can be
summarized as follows:
• A Search Problem
• States
• Actions and Costs
• Successor Functions
• Start State and a Goal State
Types of Search Algorithms
Search Algorithm
Uninformed/Blind Informed/Heuristic
Search Algorithms Search Algorithms
Iterative
Depth-First Breadth-First Depth-Limited Uniform-Cost Bidirectional Best-First/Greedy A* Search
Deepening Depth-
Search Search Search Algorithm Search Algorithm Search Algorithm Search Algorithm Algorithm
First Search
Uninformed Search Algorithms
• Uniformed Search algorithms look through the Search Space
for all possible solutions of the problem without having any
additional knowledge about the search space
• Uniformed Search algorithms only contain information about
how to move from one part of the search tree to another
• When using Uninformed Search algorithms, the search tree is
built without any information about the Search Space
• Uninformed Search algorithms examine each node in the
Search Tree until it achieves the goal
Uninformed Search Algorithms
• The Six main types of algorithms used in Uninformed or Blind
Search. They are
• Depth-First Search
• Breadth-First Search
• Iterative Deepening Depth-First Search
• Depth-Limited Search
• Uniform-Cost Search Algorithm
• Bidirectional Search
Depth-First Search
• It is a recursive algorithm for traversing a
tree graph
• It starts from the root node
• It goes through the deepest node until the
goal is reached
• It breaks ties alphabetically
Depth-First Search
• Advantage
• DFS requires very less memory as it only needs to store a stack of the nodes on the
path from root node to the current node.
• It takes less time to reach to the goal node than BFS algorithm (if it traverses in the
right path).
• Disadvantage
• There is the possibility that many states keep re-occurring, and there is no
guarantee of finding the solution.
• DFS algorithm goes for deep down searching and sometime it may go to the infinite
loop.
Depth-First Search Trial
Strategy
a. Convert State Space Graph into a
Search Tree
b. Expand a deepest node first
c. Call the Goal Function at each
dead end
d. If Goal is not achieved move to
the next deepest node
Implementation
a. Fringe is a LIFO stack
Depth-First Search
• Advantage
• DFS requires very less memory as it only
needs to store a stack of the nodes on the
path from root node to the current node.
• It takes less time to reach to the goal node
than BFS algorithm (if it traverses in the
right path).
• Disadvantage
• There is the possibility that many states
keep re-occurring, and there is no
guarantee of finding the solution.
• DFS algorithm goes for deep down
searching and sometime it may go to the
infinite loop.
Depth-First Search
• Completeness
• DFS search algorithm is complete within finite state space as
it will expand every node within a limited search tree.
• Time Complexity
• Time complexity of DFS will be equivalent to the node
traversed by the algorithm. It is given by: T(b)= 1+ b 2+
b3 +.........+ bm=O(bm)
• Where, m= maximum depth of any node and this
can be much larger than d (Shallowest solution
depth)
• Space Complexity
• DFS algorithm needs to store only single path from the root
node, hence space complexity of DFS is equivalent to the size
of the fringe set, which is O(bm).
• Optimal
• DFS search algorithm is non-optimal, as it may generate a
large number of steps or high cost to reach to the goal node.
Breadth-First Search
• It is the most common informed search
strategy
• It starts from the root node of the tree
• It expands to all successor nodes at the
same level before moving to nodes on the
next level
• It is implemented using the FIFO queue data
structure
Breadth-First Search Trial
Strategy
a. Convert State Space Graph into a
Search Tree
b. Expand the nodes at each level
horizontally
c. Call the Goal Function at each dead end
d. If Goal is not achieved move to the next
level set of nodes
Implementation
a. Fringe is a FIFO stack
Breadth-First Search
• Advantages:
• BFS will provide a solution if any
solution exists.
• If there are more than one solutions
for a given problem, then BFS will
provide the minimal solution which
requires the least number of steps.
• Disadvantages:
• It requires lots of memory since each
level of the tree must be saved into
memory to expand the next level.
• BFS needs lots of time if the solution is
far away from the root node
Depth-Limited Search Algorithm
• It is similar to the Depth-First search algorithm but
has a predetermined limit
• It solves the infinite path problem in the Depth-
first search algorithm
• It is terminated with two failure conditions
• Standard failure value which indicates that the
problem has no solution
• Cut off failure value which defines no solution
for a problem within a given depth limit
Depth-Limited Search Algorithm
• It is similar to the Depth-First search algorithm but
has a predetermined limit
• It solves the infinite path problem in the Depth-
first search algorithm
• It is terminated with two failure conditions
• Standard failure value which indicates that the
problem has no solution
• Cut off failure value which defines no solution
for a problem within a given depth limit
Depth-Limited Search Algorithm
• Advantages:
– Depth-limited search is Memory
efficient.
• Disadvantages:
– Depth-limited search also has a
disadvantage of incompleteness.
– It may not be optimal if the problem has
more than one solution.
Depth-Limited Search Algorithm
• 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
even if ℓ>d.
Uniform-Cost Search Algorithm
• It is used for the special case of a weighted tree or
graph
• There is a different cost for each edge
• It is used to find the best path using the lowest
cumulative cost to the goal node
• Costs are predetermined using predetermined
historical values
Uniform-Cost Search Algorithm
Strategy
a. Convert State Space Graph into a Search Tree
b. Expand the nodes at each level based on the
cost of the node
c. Call the Goal Function at each dead end
d. If Goal is not achieved move to the next least-
cost nodes
Implementation
a. Fringe is a priority queue (priority: cumulative
cost)
Uniform-Cost Search Algorithm
Advantages:
•Uniform cost search is optimal because at
every state the path with the least cost is
chosen.
Disadvantages:
•It does not care about the number of steps
involved in searching and only concerned
about path cost. Due to which this algorithm
may be stuck in an infinite loop.
Uniform-Cost Search Algorithm
Completeness
• Uniform-cost search is complete, such as if there is a solution, UCS will find it.
Time Complexity:
• Let C* is Cost of the optimal solution, and ε is each step to get closer to the
goal node. Then the number of steps is = C*/ε+1. Here we have taken +1, as
we start from state 0 and end to C*/ε.
Hence, the worst-case time complexity of Uniform-cost search isO(b1 + [C*/ε])/.
Space Complexity
• The same logic is for space complexity so, the worst-case space complexity of
Uniform-cost search is O(b1 + [C*/ε]).
Optimal
• Uniform-cost search is always optimal as it only selects a path with the lowest
path cost.
Iterative Deepening Depth-Search Algorithm
• It is a combination of Breadth-First Search and Depth-First Search
• It finds out the best depth limit by gradually increasing the limit until
a goal is found
• It combines the benefits of Breadth-first search's fast search and
depth-first search's memory efficiency.
• It is a useful uninformed search when search space is large, and
depth of goal node is unknown.
Iterative Deepening Depth-Search Algorithm
Advantages:
• It combines the benefits of BFS and
DFS search algorithm in terms of fast
search and memory efficiency.
Disadvantages:
• The main drawback of IDDFS is that it
1'st Iteration-----> A
repeats all the work of the previous 2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
phase. In the fourth iteration, the algorithm will find the goal node.
Iterative Deepening Depth-Search Algorithm
Completeness
• This algorithm is complete is if the
branching factor is finite.
Time Complexity
• Let's suppose b is the branching factor and
depth is d then the worst-case time
complexity is O(bd).
Space Complexity
• The space complexity of IDDFS will
be O(bd).
Optimal:
1'st Iteration-----> A
• IDDFS algorithm is optimal if path cost is a 2'nd Iteration----> A, B, C
non- decreasing function of the depth of 3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
the node In the fourth iteration, the algorithm will find the goal no
Bidirectional Search Algorithm
• It runs two simultaneous searches; one from the initial
state(forward-search) and the other from the goal node(backward
search) to find the goal node
• The search stops when both searches intersect
• Bidirectional search can use search techniques such as
BFS, DFS and DLS
Bidirectional Search Algorithm
Advantages:
• Bidirectional search is fast.
• Bidirectional search requires less
memory
Disadvantages:
• Implementation of the bidirectional
search tree is difficult.
• In bidirectional search, one should
This algorithm divides one graph/tree into two sub-
graphs. It starts traversing from node 1 in the
know the goal state in advance. forward direction and starts from goal node 16 in
the backward direction.
Bidirectional Search Algorithm
Completeness
• Bidirectional Search is
complete if we use BFS in both
searches.
Time Complexity
• Time complexity of bidirectional
search using BFS is O(bd).
Space Complexity
• Space complexity of
bidirectional search is O(bd).
Optimal
• Bidirectional search is Optimal.