You are on page 1of 35

ARTIFICIAL INTELLIGENCE (CSC 477)

SEARCH ALGORITHMS

2023/2024

Lec 2 CSC 477 2023/2024 1 / 35


Search Algorithms

Definition of search algorithms in AI


Search algorithms are a family of algorithms that are used to
systematically explore a search space in order to find a solution to a
problem.

A search problem can have three main factors:


Search Space: Search space represents a set of possible solutions,
which a system may have.

Start State: It is a state from where agent begins the search.

Goal test: It is a function which observe the current state and returns
whether the goal state is achieved or not.

Lec 2 CSC 477 2023/2024 2 / 35


Search Algorithms

Why search algorithms are important in AI


Pathfinding
Information retrieval
Puzzle-solving
Data mining
Artificial intelligence
Natural language processing
Robotics
Image processing
Database management

Lec 2 CSC 477 2023/2024 3 / 35


Search Algorithms

Properties of Search Algorithms


Completeness – Is a solution guaranteed to be found if at least one
solution exists?

Optimality – Is the solution found guaranteed to be the best (or


lowest cost) solution if thereexists more than one solution?

Time Complexity – The upper bound on the time required to find a


solution, as a function of the complexity of the problem.

Space Complexity – The upper bound on the storage space


(memory) required at any point during the search, as a function of
the complexity of the problem.

Lec 2 CSC 477 2023/2024 4 / 35


Search Algorithms

Types of Search Algorithms


Uninformed Search(Blind Search)

Informed Search (Heuristic Search)

Lec 2 CSC 477 2023/2024 5 / 35


Search Algorithms

Uninformed Search
They do not have any domain-specific knowledge

Lec 2 CSC 477 2023/2024 6 / 35


Search Algorithms

Uninformed Search Algorithms


Breadth-First Search (BFS)
Depth-First Search (DFS)
Depth-Limited Search (DLS)
Uniform Cost Search.
Iterative Deepening Search (IDS)

Lec 2 CSC 477 2023/2024 7 / 35


Uninformed Search Algorithms

Breadth-First Search (BFS)


BFS is the most common search strategy for 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.
BFS implemented using FIFO queue data structure.

Lec 2 CSC 477 2023/2024 8 / 35


Uninformed Search Algorithms

Lec 2 CSC 477 2023/2024 9 / 35


Uninformed Search Algorithms
Breadth-First Search (BFS)

Lec 2 CSC 477 2023/2024 10 / 35


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
Requires lots of memory since each level of the tree must be
stored/saved into memory to expand each the next level.

Requires lots of time if the solution is far from the root node.

Lec 2 CSC 477 2023/2024 11 / 35


Breadth-First Search

Applications Of Breadth-First Search Algorithm


GPS Navigation systems: BFS is one of the best algorithms used to
find neighboring locations by using the GPS system.

Broadcasting: Networking makes use of what we call as packets for


communication. These packets follow a traversal method to reach
various networking nodes. One of the most commonly used traversal
methods is Breadth-First Search. It is being used as an algorithm that
is used to communicate broadcasted packets across all the nodes in a
network.

Lec 2 CSC 477 2023/2024 12 / 35


Uninformed Search Algorithms

Depth-First Search (DFS)


Depth-first search is a recursive algorithm for traversing a tree or
graph data structure.

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 data structure for its implementation.

Lec 2 CSC 477 2023/2024 13 / 35


Uninformed Search Algorithms

Lec 2 Figure
CSC 3:
477DFS 2023/2024 14 / 35
Uninformed Search Algorithms
Depth-First Search (DFS)

Lec 2 CSC 477 2023/2024 15 / 35


Depth-First Search

Advantages
DFS requires less memory since only the nodes on the current path
are stored.

DFS may find a solution without examining much of the search space

Disadvantages
It may generate a large number of steps or higher cost to reach the
goal node.

Without a depth bound one may not find a solution even if one exist

Lec 2 CSC 477 2023/2024 16 / 35


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

DFS uses a stack data structure for its implementation.


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.
Lec 2 CSC 477 2023/2024 17 / 35
Uninformed Search Algorithms

Lec 2 Figure 5: Depth Limited Search.


CSC 477 2023/2024 18 / 35
Uninformed Search Algorithms
Depth Limited Search.

Lec 2 CSC 477 2023/2024 19 / 35


Depth-Limited Search

Advantages
Memory efficient.

Disadvantages
Incompleteness.

Not Optimal

Lec 2 CSC 477 2023/2024 20 / 35


Uninformed Search Algorithms

Uniform-cost Search Algorithm


Uniform-cost search is a searching algorithm used for traversing a
weighted tree or graph.
This algorithm comes into play when a different cost is available for
each edge.

The primary goal of the uniform-cost search is to find a path to the


goal node which has the lowest cumulative cost.
Uniform-cost search expands nodes according to their path costs from
the root node.
It can be used to solve any graph/tree where the optimal cost is in
demand.
A uniform-cost search algorithm is implemented by the priority queue.
It gives maximum priority to the lowest cumulative cost.
Lec 2 CSC 477 2023/2024 21 / 35
Uninformed Search Algorithms

Lec 2 CSC 477 2023/2024 22 / 35


Uninformed Search Algorithms
Uniform-cost Search Algorithm.

Lec 2 CSC 477 2023/2024 23 / 35


Uniform-cost Search

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 involve in searching and
only concerned about path cost. Due to which this algorithm may be
stuck in an infinite loop.

Lec 2 CSC 477 2023/2024 24 / 35


Uninformed Search Algorithms

Iterative deepening depth-first Search


The iterative deepening algorithm 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.

This Search algorithm combines the benefits of Breadth-first search’s


fast search and depth-first search’s memory efficiency.
The iterative search algorithm is useful uninformed search when
search space is large, and depth of goal node is unknown.

Lec 2 CSC 477 2023/2024 25 / 35


Uninformed Search Algorithms

Figure 9: IDDFS
Lec 2 CSC 477 2023/2024 26 / 35
Uninformed Search Algorithms
Iterative deepening depth-first Search.

Lec 2 CSC 477 2023/2024 27 / 35


Iterative deepening depth-first Search

Advantages
Itcombines 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.

Lec 2 CSC 477 2023/2024 28 / 35


Search Algorithms

Informed Search Algorithms


Best-First Search (BFS)

A* Search

Lec 2 CSC 477 2023/2024 29 / 35


Informed Search Algorithms

Best-First Search (Greedy Search)


Greedy best-first search uses the properties of both depth-first search
and breadth-first search.

Greedy best-first search traverses the node by selecting the path


which appears best at the moment. The closest path is selected by
using the heuristic function.

It uses the heuristic fxn h(n) <= h ∗ (n) where


h(n)= Heuristic Cost
h*(n) = Estimated cost

Lec 2 CSC 477 2023/2024 30 / 35


Best-First Search (Greedy Search)

steps to implement the best first search algorithm


Step 1: Choose an initiating node (suppose ‘n’) and place it in the
OPEN list.
Step 2: In case the initiating node is empty, stop and return failure.
Step 3: Eliminate the node n from the OPEN list which has the
lowest value of h(n) and place it on the CLOSE list.
Step 4: Expand the node and create its successors.
Step 5: Check each successor to see whether they are leading to the
goal.
Step 6: check each successor node n and find out whether any node
is the goal node or not. If any successor is the goal node,then return
success and terminate the search process. Else continue with step 7.

Lec 2 CSC 477 2023/2024 31 / 35


Best-First Search (Greedy Search)

steps to implement the best first search algorithm CONT.


Step 7: The algorithm analyzes every successor for the evaluation
function f(n). Later, it examines whether the nodes are in the OPEN
or CLOSED list. In case they do not find the node in either list, it
adds them to the OPEN list.
Step 8: Return to step 2 and iterate.

Lec 2 CSC 477 2023/2024 32 / 35


Best-First Search (Greedy Search)

Advantages
Greedy best-first search is more efficient compared with breadth-first
search and depth-first search.

Disadvantages
In the worst-case scenario, the greedy best-first search algorithm may
behave like an unguided DFS.

There are some possibilities for greedy best-first to get trapped in an


infinite loop.

The algorithm is not an optimal one.

Lec 2 CSC 477 2023/2024 33 / 35


Informed Search Algorithms

A* Search
A* Algorithm is one of the best and popular techniques used for path
finding and graph traversals.

A lot of games and web-based maps use this algorithm for finding the
shortest path efficiently.

It is essentially a best first search algorithm.

Lec 2 CSC 477 2023/2024 34 / 35


THANK YOU

Lec 2 CSC 477 2023/2024 35 / 35

You might also like