0% found this document useful (0 votes)
248 views18 pages

Lecture 3 Search Strategies in Artificial Intelligence

Here are the key points about iterative deepening depth-first search: - It combines DFS and BFS by gradually increasing the depth limit in each iteration. - In each iteration, it performs a DFS up to the current depth limit. - After each iteration, it increases the depth limit and performs DFS again. - This continues until the goal node is found. - It is useful for large search spaces where the depth of the goal is unknown. - It has the completeness of BFS but requires less memory than BFS since it only stores a single path at each depth level. - The time complexity is O(b^d) where b is branching factor and d is depth

Uploaded by

M. Talha Nadeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
248 views18 pages

Lecture 3 Search Strategies in Artificial Intelligence

Here are the key points about iterative deepening depth-first search: - It combines DFS and BFS by gradually increasing the depth limit in each iteration. - In each iteration, it performs a DFS up to the current depth limit. - After each iteration, it increases the depth limit and performs DFS again. - This continues until the goal node is found. - It is useful for large search spaces where the depth of the goal is unknown. - It has the completeness of BFS but requires less memory than BFS since it only stores a single path at each depth level. - The time complexity is O(b^d) where b is branching factor and d is depth

Uploaded by

M. Talha Nadeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Week 3

Search Strategies
Dr. Fazeel Abid
Artificial Intelligence
AssistantBy Professor
The University of Lahore
What is Search & Search Algorithm?
In Artificial Intelligence, rational agents perform some kind of search algorithm in the
background to achieve their tasks.
“Search is the systematic examination of states to find path from the start/root state to the goal
state”
A search problem consists of :
State Space. 
Set of all possible states where you can be.
Start State. 
The state from where the search begins.
Goal Test. 
A function that looks at the current state returns whether or not it is the goal state.
The Solution to a search problem is a sequence of actions, called plan that transforms the start
state to the goal state.
This plan is achieved through search algorithms.
Search Terminology & Search Strategies
Problem Space 
It is the environment in which the search takes place.
Problem Instance 
It is Initial state + Goal state.
Problem Space Graph 
It represents problem state. States are shown by nodes and
operators are shown by edges.
Space Complexity 
The maximum number of nodes that are stored in memory.
Time Complexity 
The maximum number of nodes that are created.
Admissibility 
A property of an algorithm to always find an optimal solution.
Branching Factor 
The number of child nodes in the problem space graph.
Depth 
Length of the shortest path from initial state to goal state.
Types of search algorithms
Based on the search problems we can classify the search algorithms into uninformed and informed search.
Informed Search
Uninformed Search
Informed search algorithms use domain knowledge in which problem information is
 The uninformed search algorithm does not contain any available which can guide the search. Informed search strategies can find a solution more

domain knowledge such as closeness, the location of goal. efficiently than an uninformed search strategy.

Informed search is also called a Heuristic search.


 It operates in a brute-force way as it only includes
A heuristic is a way which might not always be guaranteed for best solutions but
information about how to traverse the tree and how to guaranteed to find a good solution in reasonable time.
Informed search can solve much complex problem which could not be solved in
identify leaf and goal nodes. another way.
An example of informed search algorithms is a traveling salesman problem.
 Uninformed search applies a way in which search tree is  Greedy Search, Hill Climbing,
 A* Search, Beam Search etc.
searched without any information about the search space it
is also called blind search.
 It examines each node of the tree until it achieves the goal
node.
 Time Consuming, More Complexity (Time & Space),
Optimal Solution.
Breadth-First-Search In the below tree structure, traversing of the tree
using BFS algorithm from the root node S to goal
 Breadth-first search is the most common search strategy for node K
traversing a tree or graph.
 This algorithm searches breadthwise in a tree or graph, so it is
called breadth-first search.
 BFS algorithm starts searching from the root node of the tree and
expands all successor node at the current level before moving to
nodes of next level.
 The breadth-first search algorithm is an example of a general-
graph search algorithm.
 Breadth-first search implemented using FIFO queue data
structure.
Advantages:
 BFS will provide a solution if any solution exists.
 If there are more solutions, then BFS will provide solution with least number of steps.
Disadvantages:
 Requires lots of memory since each level saved into memory to expand the next level.
 Needs lots of time if the solution is far away from the root node.
Breadth-First-Search
BFS search algorithm traverse in layers, so it will follow the
path which is shown by the dotted arrow, and the traversed
path will be: Time Complexity: Time Complexity of BFS algorithm can be
S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K obtained by the number of nodes traversed in BFS until the
shallowest Node.

Space Complexity: Space complexity of BFS algorithm is given


by the Memory size of frontier which is O(bd)

Completeness: BFS is complete, which means if the shallowest


goal node is at some finite depth, then BFS will find a solution.

Optimality: BFS is optimal.
Depth-First-Search
• Depth-first search is a recursive algorithm for traversing
a tree or graph data structure. In the below search tree, we have shown the flow of
depth-first search.
• It is called the depth-first search because it starts from the
root node and follows each path to its greatest depth
node before moving to the next path.
• DFS uses a stack (LIFO) data structure for its
implementation.
• The process of the DFS algorithm is similar to the BFS
algorithm.
Advantage
Less memory as it only needs to store a stack of the nodes
Less time to reach to the goal node than BFS algorithm (if
it traverses in the right path).
Disadvantage
Many states keep re-occurring, and there is no guarantee of
finding the solution.
Deep down searching and may go to the infinite loop.
Depth-First-Search
• DFS will follow the order
• Root node--->Left node ----> right node.
Completeness: DFS search algorithm is complete within finite
• Searching from root node S, and traverse A, state space as it will expand every node within a limited search
then B, D and E, after traversing E, will tree.
backtrack the tree as E has no other successor Time Complexity: Time complexity of DFS will be equivalent
and still goal node is not found. After to the node traversed by the algorithm.
backtracking traverse node C and then G,
terminate as it found goal node. Space Complexity: DFS algorithm needs to store only single
path from the root node, hence space complexity of DFS
is O(bd)

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.
Depth-Limited-Search

• A depth-limited search algorithm is similar to depth-first search


with a predetermined limit.
• Depth limited search can solve the drawback of the infinite path
in the Depth-first search.
• In this algorithm, the node at the depth limit will treat as it has no
successor nodes further.
• Depth-limited search can be terminated with two Conditions of
failure:
 Standard failure value: It indicates that problem does not have any
solution.
 Cutoff failure value: It defines no solution for the problem within a given
depth limit.
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

Completeness: DLS search algorithm is complete if the


solution is above the depth-limit.

Time Complexity: Time complexity of DLS algorithm


is O(bd).

Space Complexity: Space complexity of DLS algorithm is


O(b×d).

Optimal: Depth-limited search can be viewed as a special


case of DFS, and it is also not optimal.
Recall Your Self! Grab Your Sessional Marks
• What are the two phases of Problem Solving Agents, explain?
• What are the three steps involved in Problem Formulation?
• How to Formulate the Problem, Justify your answer with example Other than
Puzzle/ Vacuum cleaner/ Automated Driver.
• What is a Plan with respect to Search?
• Explain Following Search Terminologies?
 State Space, Problem Space Graph, Branching Factor, Depth
• Draw a Single Graph/Tree for DFS/BFS/DLS and Illustrate traversing for each
search strategy.
Iterative Deepening Depth-First-Search

The iterative deepening is a combination of DFS and BFS


algorithms.
This search algorithm finds out the best depth limit and
does it by gradually increasing the limit until a goal is
found.
This algorithm performs depth-first search up to a certain
"depth limit", and it keeps increasing the depth limit after
each iteration until the goal node is found.
The iterative search algorithm is useful uninformed search
when search space is large, and depth of goal node is
unknown
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 repeats all the work of the
previous phase.
Iterative Deepening Depth-First-Search
Following tree structure is iterative deepening depth-first search which performs various iterations until it does not find the goal
node. The iteration performed by the algorithm is given as:

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(b d).
Space Complexity
The space complexity of IDDFS will be O(b*d).
Optimal
IDDFS algorithm is optimal.
Bidirectional Search

Bidirectional search runs two simultaneous searches, one


form initial state called as forward-search and other from
goal node called as backward-search, to find the goal node.
Bidirectional search replaces one single search graph with
two small subgraphs in which one starts the search from an
initial vertex and other starts from goal vertex.
The search stops when these two graphs intersect each
other.
Bidirectional search can use search techniques such as BFS,
DFS, DLS, etc.
Advantages
 Bidirectional search is fast.
 Bidirectional search requires less memory
Disadvantages
 Implementation of the bidirectional search tree is difficult.
 In bidirectional search, one should know the goal state in
advance.
Bidirectional Search
• In below search tree, bidirectional search algorithm is applied which divides one graph/tree into
two sub-graphs. It starts traversing from node 1 in the forward direction and starts from goal
node 16 in the backward direction.
Completeness 
Bidirectional Search is complete if we use BFS in
both searches.
Time Complexity 
Time complexity of bidirectional search using BFS
is O(b d).
Space Complexity
Space complexity of bidirectional search is O(b d)
Optimal
Bidirectional search is Optimal.
Uniform-cost-Search

• Uniform-cost search is a searching


algorithm used for traversing a weighted
tree or graph.
• This algorithm comes when a different
cost is available for each edge.
• The goal is to find a path to the goal node
with lowest cumulative cost.
• Expands nodes according to their path Advantages
 Uniform cost search is optimal because at every
costs form the root node.
state the path with the least cost is chosen.
• Can be used to solve any graph/tree where Disadvantages
the optimal cost is in demand.  It does not care about the number of steps
• Implemented by the priority queue. involve in searching and only concerned about
path cost.
• Maximum priority to the lowest  This algorithm may be stuck in an infinite loop.
cumulative cost.
Uniform-Cost-Search

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 e is each step to
get closer to the goal node O(b C/e).
Space Complexity
The same logic is for space complexity so, the space
complexity of Uniform-cost search is O(b C/e).
Optimal
Uniform-cost search is always optimal as it only selects a
path with the lowest path cost.
Assignment # 2 (1.5 marks)

Implementation of Uninformed Search Strategies In Python


Especially…
Depth First Search
Breadth First Search
Uniform Cost Search
Dead Line For Submission
22-10-2020

You might also like