0% found this document useful (0 votes)
5 views40 pages

Unit II

The document discusses various search algorithms used in Artificial Intelligence, categorizing them into uninformed and informed searches. It details specific algorithms such as Breadth First Search, Depth First Search, and A* Search, along with their properties like time complexity, space complexity, completeness, and optimality. Additionally, it covers heuristic functions and the challenges faced in hill climbing algorithms.

Uploaded by

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

Unit II

The document discusses various search algorithms used in Artificial Intelligence, categorizing them into uninformed and informed searches. It details specific algorithms such as Breadth First Search, Depth First Search, and A* Search, along with their properties like time complexity, space complexity, completeness, and optimality. Additionally, it covers heuristic functions and the challenges faced in hill climbing algorithms.

Uploaded by

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

ARTIFICIAL INTELLIGENCE

UNIT II
PREPARED BY
VARSHA HIMTHANI
ASSISTANT PROESSOR
JECRC UNIVERSITY
SEARCH ALGORITHMS
• In Artificial Intelligence, Search techniques are universal problem-solving
methods.

• Problem-solving agents in AI mostly used these search strategies or algorithms


to solve a specific problem and provide the best result.

Properties of Search Algorithms:

• Space and Time complexity

• Optimality

• Completeness
VARSHA HIMTHANI
JECRC UNIVERSITY
TYPES OF SEARCH ALGORITHM
Uninformed Search
• Uninformed search is also called Blind search.

• It examines each node of the tree until it achieves the goal node.

Informed Search
• Informed search is also called a Heuristic search.

• Informed search algorithms use domain knowledge.

• problem information is available which can guide the search.

• Informed search strategies can find a solution more efficiently than an uninformed
search strategy.

VARSHA HIMTHANI
JECRC UNIVERSITY
SEARCH ALGORITHMS

Uninformed Search Informed Search


1) Breath First Search 1) Heuristic Functions
2) Best First Search
2) Depth First Search
3) Hill Climbing Algorithm
3) Depth Limited Search
4) A* Algorithm
4) Iterative Deepening (IDA) 5) AO* Algorithm

VARSHA HIMTHANI
JECRC UNIVERSITY
BREADTH FIRST SEARCH
• BFS starts at the tree root (or some arbitrary node of a graph, sometimes
referred to as a ‘search key’), and explores all of the neighbor nodes at the
present depth prior to moving on to the nodes at the next depth level.

VARSHA HIMTHANI
JECRC UNIVERSITY
BREADTH FIRST SEARCH
Time complexity: Equivalent to the number of nodes traversed in BFS until the
shallowest solution. [O(bd)]
Space complexity: Equivalent to how large can the fringe get.
Completeness: BFS is complete, meaning for a given search tree, BFS will come
up with a solution if it exists.

Optimality: BFS is optimal as long as the costs of all edges are equal.

VARSHA HIMTHANI
JECRC UNIVERSITY
DEPTH FIRST SEARCH
The algorithm starts at the root node (selecting some arbitrary node as the root
node in the case of a graph) and explores as far as possible along each
branch before backtracking.

Path: S→A→B→C→G

VARSHA HIMTHANI
JECRC UNIVERSITY
DEPTH FIRST SEARCH
• Time complexity: Equivalent to the number of nodes traversed in
DFS. [O(nm)]
• Space complexity: DFS algorithm needs to store only single path from
the root node. [O(bm)]

• Completeness: DFS is complete if the search tree is finite, meaning for


a given finite search tree, DFS will come up with a solution if it exists.

• Optimality: DFS is not optimal, meaning the number of steps in reaching


the solution, or the cost spent in reaching it is high.

VARSHA HIMTHANI
JECRC UNIVERSITY
DEPTH LIMITED SEARCH
The algorithm starts at the root node (selecting some arbitrary node as the root
node in the case of a graph) and explores as far as possible along each
branch before backtracking.

Depth limit = 2

VARSHA HIMTHANI
JECRC UNIVERSITY
DEPTH LIMITED SEARCH
• Time and space complexity: Same as DFS.

• Completeness: DFS is not complete DFS will not come up with a


solution if the solution exist out of the limit.

• Optimality: DFS is not optimal, meaning the number of steps in reaching


the solution, or the cost spent in reaching it is high.

VARSHA HIMTHANI
JECRC UNIVERSITY
ITERATIVE DEEPENING SEARCH ALGORITHM
• Also called Iterative Deepening Depth First Search (IDDFS)

• IDS combines depth-first search’s space-efficiency and breadth-first search’s


fast search.

• IDDFS calls DFS for different depths starting from an initial value. In every
call, DFS is restricted from going beyond given depth. So basically we do
DFS in a BFS fashion.

VARSHA HIMTHANI
JECRC UNIVERSITY
Disadvantage of DFS
DFS first traverses nodes going through one adjacent of root, then next adjacent.
The problem with this approach is, if there is a node close to root, but not in first
few subtrees explored by DFS, then DFS reaches that node very late.

VARSHA HIMTHANI
JECRC UNIVERSITY
Disadvantage of BFS
BFS goes level by level, but requires more space. The space required by DFS
is O(d) where d is depth of tree, but space required by BFS is O(n) where n is
number of nodes in tree.

VARSHA HIMTHANI
JECRC UNIVERSITY
ITERATIVE DEEPENING SEARCH ALGORITHM

VARSHA HIMTHANI
JECRC UNIVERSITY
ITERATIVE DEEPENING SEARCH ALGORITHM

• We visit top level nodes multiple times.

• The last (or max depth) level is visited once, second last level is visited twice,
and so on.

• It may seem expensive, but it turns out to be not so costly, since in a tree
most of the nodes are in the bottom level.

• So it does not matter much if the upper levels are visited multiple times.

VARSHA HIMTHANI
JECRC UNIVERSITY
INFORMED SEARCH: HEURISTIC
• Heuristic (from Greek "I find, discover") is a technique designed for solving a
problem more quickly when classic methods are too slow, or for finding an
approximate solution when classic methods fail to find any exact solution.

• Heuristic is a function which is used in Informed Search, Heuristic Function is a


function that estimates the cost of getting from one place to another.

• It finds the most promising path. In a way, it can be considered a shortcut.

• Heuristic, is a function that ranks alternatives in search algorithms at each


branching step based on available information to decide which branch to follow.

VARSHA HIMTHANI
JECRC UNIVERSITY
HEURISTIC FUNCTION

• Heuristic function estimates how close a state is to the goal.

• It is represented by h(n), and it calculates the cost of an optimal path between the
pair of states.

• The value of the heuristic function is always positive.

Types

• Admissible Heuristic If H(n) <= H’(n)


(Here, H’(n) represents Actual cost)
• Non-Admissible Heuristic If H(n) > H’(n)

VARSHA HIMTHANI
JECRC UNIVERSITY
HEURISTIC FUNCTION: EXAMPLE

H(n)=2
X
Source
There are many methods used to
1
H(n)=1
calculate heuristic function like
Y Euclidean distance, Manhattan
1 distance, Number of misplaced tiles
etc.
Z

Goal
BEST FIRST SEARCH
• Best first search uses the concept of a priority queue and heuristic
search.
• Both BFS and DFS blindly explore paths without considering any cost
function.
• The idea of Best First Search is to use an evaluation function to decide
which adjacent is most promising and then explore.
• We use a priority queue to store costs of nodes. So the implementation is a
variation of BFS, we just need to change Queue to Priority Queue.

VARSHA HIMTHANI
JECRC UNIVERSITY
BEST FIRST SEARCH: EXAMPLE

Path: S- B- F- G

VARSHA HIMTHANI
JECRC UNIVERSITY
BEST FIRST SEARCH

Time complexity: Equivalent to the number of nodes traversed in BFS until the
shallowest solution. [Worst case O(log n)]
Space complexity: Equivalent to how large can the fringe get.
Completeness: BFS is complete, meaning for a given search tree, BFS will
come up with a solution if it exists.
Optimality: BFS is optimal. Performance of the algorithm depends on how well
the cost or evaluation function is designed.

VARSHA HIMTHANI
JECRC UNIVERSITY
HILL CLIMBING ALGORITHM
•Hill climbing algorithm is a local search algorithm which continuously moves in
the direction of increasing elevation/value to find the peak of the mountain or
best solution to the problem.
•It terminates when it reaches a peak value where no neighbor has a higher
value.
•Hill climbing algorithm is a technique which is used for optimizing the
mathematical problems.
•One of the widely discussed examples of Hill climbing algorithm is Traveling-
salesman Problem in which we need to minimize the distance traveled by the
salesman.
VARSHA HIMTHANI
JECRC UNIVERSITY
HILL CLIMBING ALGORITHM
•Greedy approach: It is also called greedy local search as it only looks to its
good immediate neighbor state and not beyond that.
•A node of hill climbing algorithm has two components which are state and
value.
•No backtracking: It does not backtrack the search space, as it does not
remember the previous states.
•In this algorithm, we don't need to maintain and handle the search tree or
graph as it only keeps a single current state.

VARSHA HIMTHANI
JECRC UNIVERSITY
HILL CLIMBING ALGORITHM

• Local Maximum: Local maximum is a state


which is better than its neighbor states, but
there is also another state which is higher
than it.
• Global Maximum: Global maximum is the
best possible state of state space landscape. It
has the highest value of objective function.
• Current state: It is a state in a landscape
diagram where an agent is currently present.
• Flat local maximum: It is a flat space in the
landscape where all the neighbor states of
current states have the same value.

VARSHA HIMTHANI
JECRC UNIVERSITY
TYPES OF HILL CLIMBING ALGORITHM

• Simple hill Climbing:

• Steepest-Ascent hill-climbing:

• Stochastic hill Climbing:

VARSHA HIMTHANI
JECRC UNIVERSITY
SIMPLE HILL CLIMBING

Simple hill climbing is the simplest way to implement a hill climbing


algorithm. It only evaluates the neighbor node state at a time and selects
the first one which optimizes current cost and set it as a current state. It
only checks it's one successor state, and if it finds better than the current state,
then move else be in the same state.

VARSHA HIMTHANI
JECRC UNIVERSITY
STEEPEST-ASCENT HILL CLIMBING

The steepest-Ascent algorithm is a variation of simple hill climbing algorithm.


This algorithm examines all the neighboring nodes of the current state and
selects one neighbor node which is closest to the goal state. This algorithm
consumes more time as it searches for multiple neighbors

VARSHA HIMTHANI
JECRC UNIVERSITY
STOCHASTIC HILL CLIMBING

Stochastic hill climbing does not examine for all its neighbor before moving.
Rather, this search algorithm selects one neighbor node at random and
decides whether to choose it as a current state or examine another state.

VARSHA HIMTHANI
JECRC UNIVERSITY
PROBLEMS IN HILL CLIMBING ALGORITHM
• 1. Local Maximum: A local maximum is a peak state in the landscape which
is better than each of its neighboring states, but there is another state also
present which is higher than the local maximum.

VARSHA HIMTHANI
JECRC UNIVERSITY
PROBLEMS IN HILL CLIMBING ALGORITHM:

• Plateau: A plateau is the flat area of the search space in which all the
neighbor states of the current state contains the same value, because of this
algorithm does not find any best direction to move. A hill-climbing search
might be lost in the plateau area.

VARSHA HIMTHANI
JECRC UNIVERSITY
PROBLEMS IN HILL CLIMBING ALGORITHM

• Ridges: A ridge is a special form of the local maximum. It has an area which
is higher than its surrounding areas, but itself has a slope, and cannot be
reached in a single move.

VARSHA HIMTHANI
JECRC UNIVERSITY
A* SEARCH ALGORITHM
• A * algorithm is a searching algorithm that searches for the shortest path
between the initial and the final state.

• A* Search algorithm is one of the best and popular technique used in path-
finding and graph traversals.

• Many games and web-based maps use this algorithm to find the shortest
path very efficiently (approximation).

VARSHA HIMTHANI
JECRC UNIVERSITY
A* SEARCH ALGORITHM
• A* Search Algorithm does is that at each step it picks the node according to a
value-‘f’ which is a parameter equal to the sum of two other parameters –

• At each step it picks the node/cell having the lowest ‘f’, and process that
node/cell.
VARSHA HIMTHANI
JECRC UNIVERSITY
A* SEARCH ALGORITHM: EXAMPLE
In the given graph orange color numbers
on vertices shows the heuristic values
and the black color numbers on edges
shows the movement cost. In this, a is
source and z is goal node.

VARSHA HIMTHANI
JECRC UNIVERSITY
AO* SEARCH ALGORITHM

VARSHA HIMTHANI
JECRC UNIVERSITY
AO* SEARCH ALGORITHM

VARSHA HIMTHANI
JECRC UNIVERSITY
AO* SEARCH ALGORITHM

VARSHA
VARSHA HIMTHANI
HIMTHANI
JECRC
JECRC UNIVERSITY
UNIVERSITY
AO* SEARCH ALGORITHM: EXAMPLE

VARSHA HIMTHANI
JECRC UNIVERSITY
AO* SEARCH ALGORITHM: EXAMPLE

VARSHA HIMTHANI
JECRC UNIVERSITY
THANK
YOU

You might also like