0% found this document useful (0 votes)
30 views89 pages

Chapter 2 Search Techniques

This document discusses search techniques and uninformed search algorithms. It begins with an introduction to problem solving and defining different types of problems. It then discusses performance measures for algorithms and searching as a problem solving technique. Several uninformed search algorithms are covered, including depth first search (DFS), breadth first search, and uniform cost search. DFS is described in more detail, including its implementation using a LIFO stack, examples, advantages, disadvantages, and performance measures.

Uploaded by

rahul.s221054101
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)
30 views89 pages

Chapter 2 Search Techniques

This document discusses search techniques and uninformed search algorithms. It begins with an introduction to problem solving and defining different types of problems. It then discusses performance measures for algorithms and searching as a problem solving technique. Several uninformed search algorithms are covered, including depth first search (DFS), breadth first search, and uniform cost search. DFS is described in more detail, including its implementation using a LIFO stack, examples, advantages, disadvantages, and performance measures.

Uploaded by

rahul.s221054101
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/ 89

Vidyavardhini’s College of Engineering and Technology

Department of Information Technology

Search Techniques
-Mrs. Anagha Patil
CO2: Apply an appropriate problem-solving
method and knowledge-representation scheme.

3/3/2024 Anagha Patil, VCET 2


Objectives :
• Problem Solving
• Performance Measures
• Searching
• Uninformed Search(Blind Search)
• Depth First Search
• Breadth First Search
• Uniform Cost Search

3/3/2024 Anagha Patil, VCET 3


Problem Solving
• Problem solving consists of using generic or ad hoc methods, in an
orderly manner, for finding solutions to problems.
• Problems can also be classified into two different types: ill-defined
and well-defined, from which appropriate solutions are to be made.
1. Ill-defined problems are those that do not have clear goals,
solution paths, or expected solution.
2. Well-defined problems have specific goals, clearly defined
solution paths, and clear expected solutions.

3/3/2024 Anagha Patil, VCET 4


Problem Types
1. Deterministic, fully observable ⇒ single-state problem
Agent knows exactly which state the problem will be in; it’s
solution is a sequence.
2. Non-observable ⇒ conformant problem
Agent may have no idea where it is; solution (if any) is a
sequence.
3. Nondeterministic and/or partially observable ⇒ contingency
problem percepts provide new information about current state.
4. Unknown state space ⇒ exploration problem (“online”) Solution is a
tree or policy often interrelated search, and execution.

3/3/2024 Anagha Patil, VCET 5


Steps for problem solving:

Implementation
Choosing
the solution
Identification
of solution
Analyze the
problem
Define the
problem

3/3/2024 Anagha Patil, VCET 6


Problem Solving Agent
• A goal formulation, based on the current situation and the
performance measure is required for problem solving.
• Problem formulation is the process of deciding what actions and
states to consider, given a goal.
• Searching is the most commonly used technique of problem solving.
A search algorithm takes a problem as input and returns a solution
in the form of an action sequence.
• Popularly solved problems based on AI: Chess, Travelling Salesman
problem, Tower of Hanoi problem, Water Jug problem, N-Queen
problem.
3/3/2024 Anagha Patil, VCET 7
Simple Problem Solving Agent

Function SIMPLE-PROBLEM-SOLVING- AGENT (percept) returns an action Persistent:


seq. an action sequence, initially empty,
state, some description of the current world state,
goal; a goal initially null,
problem, a problem formulation,
state  UPDATE-STATE(state percept)
If seq. is empty then
goal  FORMULATE-GOAL(State)
problem  FORMULATE-PROBLEM (State, goal)
seq.  SEARCH( problem}
If seq. = failure then return a null action action  FlRST(seq.)
seq.  REST(seq.) return action

3/3/2024 Anagha Patil, VCET 8


Performance Measures
• Performance measurement is the process of collecting, analysing
and / or reporting information regarding the performance of an
individual, group, organization, system or component.
• Moulin defines the term with a forward looking organizational
focus ‘the process of evaluating how well organizations are managed
and the value they deliver for the customers and other stakeholders’.
• The most common frameworks include :
(i) Balanced scorecard : It is used by organisations to manage the
implementation of corporate strategies.
(ii) Key performance indicator : It is a method for choosing
important / critical performance measures, usually in an organisational
content.
3/3/2024 Anagha Patil, VCET 9
Performance Measure for Algorithms
1. Time complexity : It is a measure of amount of time for an
algorithm to execute.
2. Space efficiency : It is a measure of the amount of memory
needed for an algorithm to execute.
3. Complexity theory : It is a study of algorithm performance.
4. Function dominance : It is a comparison of cost functions.

3/3/2024 Anagha Patil, VCET 10


Searching
• Search plays a major role in solving many artificial intelligence (AI)
problems.
• Search is a universal problem solving mechanism in AI.
• In many problems, sequence of steps required to solve a problem is
not known in advance but must be determined by systematic trial-
and-error exploration of alternatives.
• Search techniques try to "pre-play" the game by evaluating the
future states (game tree search) and may use also heuristic to prone
bad choices or speed things up.

3/3/2024 Anagha Patil, VCET 11


Properties of search algorithms
• Completeness: A search algo is said to be complete if it guarantees
to return a solution if at least any solution exists for any random
input.
• Optimality: If a solution found for an algorithm is guaranteed to be
the best solution among all other solutions, then such solution is
said to be the optimal solution.
• Time complexity: It is a measure of amount of time for an algorithm
to execute.
• Space complexity: It is a measure of the amount of memory needed
for an algorithm to execute.

3/3/2024 Anagha Patil, VCET 12


Types of Searching (Search algorithms)
• Uninformed (blind) search
• Does not contain any domain knowledge. (No info about search space)
• No additional information about the states beyond that provided in the
problem definition.
• Operates in Brute Force way.
• Successor states can be generated.
• Goal state and non-goal state can be distinguished.
• Informed (heuristic) search
• Uses domain knowledge.
• Know whether one non-goal state is more promising than other.
• A heuristic is a way which might not always be guarantees the best solution
but guarantees to find a good solution in reasonable time.
3/3/2024 Anagha Patil, VCET 13
Search Algorithms

Uninformed/Blind Search Informed/Heuristic Search

Breadth First Search Best First Search

Uniform Cost Search A* Search

Depth First Search AO* Search

Depth Limited Search Problem Reduction

Iterative Deeping Depth


Hill Climbing
First Search

Bidirectional Search
Algorithm

3/3/2024 Anagha Patil, VCET 14


Uninformed (blind) search techniques

1. Depth first search.


2. Breadth first search.
3. Uniform-cost search.
4. Depth-limited search.
5. Iterative deepening search.
6. Bidirectional search.

3/3/2024 Anagha Patil, VCET 15


Depth First Search(DFS)
• DFS expands the deepest node in the current fringe of the search
tree. The search proceeds immediately to the deepest level of the
search tree, where the nodes have no successors.

Fig. 2.1 Order in which nodes are visited in DFS


3/3/2024 Anagha Patil, VCET 16
Depth First Search(DFS)
• Implemented by a LIFO data structure, Stack.
• DFS is used in topological sorting, scheduling problems, cycle
detection in graphs and solving puzzles, other applications involve
analysing networks.
• e.g. testing, if a graph is bipartite.

3/3/2024 Anagha Patil, VCET 17


Example...

3/3/2024 Anagha Patil, VCET 18


Example...

Ans: S-A-D-B-C

Advantages:
• It requires very less memory.
• It takes less time to reach to the goal node than BFS.
Disadvantages:
• There is the possibility that many states keep re-occurring and there is no guarantee of
finding the solution.
• DFS algo goes for deep down searching and sometime it may go to the infinite loop.
3/3/2024 Anagha Patil, VCET 19
Performance measures of DFS
(i) Completeness : DFS is complete if the search tree is finite, it implies
that for a given finite search, DFS will have a solution if it exists.
(ii) Optimality : DFS is not optimal, it means that the number of steps in
reaching the solution, or the cost spent in reaching it is high.
(iii) Time complexity : The time complexity of DFS, if the entire tree is
traversed, is O (V) where V is the number of nodes.
For a directed graph, the sum of the sizes of the adjacency lists of all
nodes is E. So, the time complexity in this case is
O (V) + O (E) = O (V + E)
For an undirected graph, each edge appears twice.
(iv) Space complexity : For DFS, which goes along a single ‘branch’ all the
way down and uses a stack implementation, the height of the tree matters.
The space complexity for DFS is O (h) where h is the maximum height of the
tree.
3/3/2024 Anagha Patil, VCET 20
Breadth First Search(BFS)
• BFS is simple strategy in which the root node is expanded first, then all
the successors of the root node are expanded next, then their successors,
and so on.
• BFS involves search through a tree one level at a time. We traverse
through one entire level of children nodes first, before moving onto
traverse through the grand children nodes.
• Breadth first search is an algorithm for node that satisfies a given
property. It starts at the tree root and explores all nodes at the present
depth prior to moving on to nodes at the next depth level.
• BFS uses Queue-data structure for finding the shortest path. BFS can be
used to find single source shortest path in an un-weighted graph, because
in BFS, we reach a vertex with minimum number of edges from a source
vertex.

3/3/2024 Anagha Patil, VCET 21


Breadth First Search(BFS)
Advantages:
• BFS will provide a solution if any
solution exists.
• If there are more than one solution for
a given problem, then BFS will provide
minimal solution which requires the
least number of steps.

Disadvantages:
• It requires lot of memory.
• It needs lots of time if the solution is
Fig. Order in which nodes are visited in BFS
far away from the root node.

3/3/2024 Anagha Patil, VCET 22


Applications...
(1) Unweighted graphs : BFS algorithm can easily create the shortest path
and a minimum spanning tree to visit all the vertices of the graph in the
shortest time possible with high accuracy.
(2) P2P Networks : BFS can be implemented to locate all the nearest or
neighbouring nodes in a peer to peer network. This will find the required
data faster.
(3) Web Crawlers : Search engines or web crawlers can easily build
multiple levels of indexes by employing BFS. BFS implementation starts from
the source, which is the web page, and then it visits all the links from that
source.
(4) Navigation Systems : BFS can help find all the neighbouring locations
from the main or source location.
(5) Network Broadcasting : A broadcasted packet is guided by the BFS
algorithm to find and reach all the nodes it has the address for.

3/3/2024 Anagha Patil, VCET 23


Performance measures for BFS
• Time Complexity
Breadth-first search, being a brute search generates all the nodes for
identifying the goal. The amount of time taken for generating these nodes is
proportional to the depth d and branching factor b and is given by,
1+ b + b2 + b3 +..... + b^d ≃ b^d
Hence the time-complexity = O (b^d )
• Space Complexity
Unlike depth-first search wherein the search procedure has to remember
only the paths it has generated, breadth-first search procedure has to
remember every node it has generated. Since the procedure has to keep
track of all the children it has generated, the space-complexity is also a
function of the depth d and branching factor b. Thus space complexity
becomes,
Hence the space-complexity = O (bd)

3/3/2024 Anagha Patil, VCET 24


Uniform Cost Search
• Uniform-cost-search is an uninformed search algorithm that uses
the lowest cumulative cost to find a path from the source to the
destination.
• Uniform-cost search is similar to Dijkstra’s algorithm.
• Nodes are expanded, starting from the root, according to the
minimum cumulative cost. The uniform-cost search is then
implemented using a Priority Queue.
• It gives maximum priority to the lowest cumulative cost.
• Here, instead of inserting all vertices into a priority queue, we
insert only source, then one by one we insert nodes when needed.

3/3/2024 Anagha Patil, VCET 25


Algorithm
Step 1 : Insert Root Node into
Step 1 : from the the queue.
starting state we will visit the Step 2 : Repeat till queue is not
adjacent states and will empty.
choose the least costly state.
Step 3 : Remove the next
Step 2 : then we choose element with the highest priority, from
the next costly state from the queue.
the all un-visited and Step 4 : If the node is a
adjacent states of the visited destination node, then print the cost
states. and the path and exit, else insert all
Step 3 : In this way we the children of removed elements into
try to reach the goal state. the queue with their cumulative cost
as their priorities.

3/3/2024 Anagha Patil, VCET 26


Example A path from S to G1 –
{ S > A > G1 } whose cost is SA + AG1 = 5 + 9 = 14.

Write path from S to G2 with the Cost Using UCS Algo.


Write path from S to G3 with the Cost Using UCS Algo

3/3/2024 Anagha Patil, VCET 27


Advantages of U.C.S
1. It helps to find the path with the lowest cumulative cost inside a
weighted graph having a different cost associated with each of its edge
from the root node to the destination node.
2. It is considered to be an optimal solution since, at each state, the
least path is considered to be followed.

3/3/2024 Anagha Patil, VCET 28


Disadvantages of U.C.S
1. The open list is required to be kept sorted as priorities in priority
queue needs to be maintained.
2. The storage required is exponentially large as it does not care
about no. of steps involved.
3. The algorithm may be stuck in an infinite loop as it considers
every possible path going from the root node to the destination node
with low cost.

3/3/2024 Anagha Patil, VCET 29


Performance measures
• Uniform cost search is complete, when UCS finds the solution, (if there is a
solution).
• Uniform-cost search is always optimal as it only selects a path with the lowest
path cost.

• The time complexity needed to run uniform cost search is: O(b(1 + C / ε))
Where: b - branching factor, C - optimal cost, ε - cost of each step
3/3/2024 Anagha Patil, VCET 30
Depth Limited Search(DLS)
• In infinite state spaces, depth-first search method fails. This failure
can be alleviated by supplying depth-first search with a pre -
determined depth limit l.
• Nodes at depth l are treated as if they have no successors.
• Thus depth-first search can be viewed as a special case of depth-
limited search with l = ∞.
• Depth-limited search can terminate with two kinds of failure :
(i) the standard failure value which indicates no solution;
(ii) the cut-off failure value which indicates no solution within the
depth-limit.

3/3/2024 Anagha Patil, VCET 31


Advantages
1. Depth limited search is better than DFS as it requires less time
and memory space.
2. DFS assures that the solution will be found if it exists in infinite
time.
3. DLS has applications in graph theory particularly similar to DFS.

3/3/2024 Anagha Patil, VCET 32


Disadvantages
(i) The goal node may not exist in the depth limit set earlier, which
will push the user to iterate further adding execution time.
(ii) The goal node cannot be found out if it does not exist in the
desired limit.

3/3/2024 Anagha Patil, VCET 33


Performance Measures
• Optimality:
• The DLS is a non-optimal algorithm since the depth that is chosen can be
greater than d (l > d). Thus DLS is not optimal if l > d.
• Time complexity:
• It is similar to DFS, i.e. O (bl), where l is the specified depth limit.
• Space complexity:
• It is similar to DFS, it is O (bl), where l is the specified depth limit.
• DLS is incomplete as sometime it is not reaching to the goal as limit
is specified, cut-off failure can happen.

3/3/2024 Anagha Patil, VCET 34


Iterative Deepening Search Technique
(IDS/IDDFS)
• IDS is a state space/graph search strategy in which a depth-limited
version of depth-first search is run repeatedly with increasing depth
limits until the goal is found. i.e. the best depth limit is found out by
gradually increasing the limit.
• DDFS combines depth-first search's space-efficiency and breadth-
first search's completeness.
• it visits the nodes in the search tree in the same order as depth-first
search, but the cumulative order in which nodes are first visited is
effectively breadth- first. Hence, memory utilization is less.

3/3/2024 Anagha Patil, VCET 35


Algorithm
Function iterative-Deepening-search (problem) returns a solution or
failure
inputs : problem, a problem
for depth <- O to ∞ do
result <- Depth-Limited-Search (problem, depth)
if result <- cutoff then return result

3/3/2024 Anagha Patil, VCET 36


Advantages
• The main advantage of IDDFS is in game tree searching.
• Another advantage is the responsiveness of the algorithm.
• The time complexity of IDDFS in well-balanced trees works out to be
the same as Depth-first search: O (bd).

3/3/2024 Anagha Patil, VCET 37


Performance Measures
• This search terminates when a solution is found or if the depth- limit
search returns failure meaning that no solution exists.
• It is optimal when the path cost is a non-decreasing function of the
depth of the node.
• The time complexity of IDDFS is O ( bd ) and its space complexity is
O( bd ), where b is the branching factor and d is the depth of the
shallowest goal.

3/3/2024 Anagha Patil, VCET 38


Bidirectional Search
• The principle used in a bidirectional heuristic search algorithm is to find
the shortest path from the current node to the goal node.
• It runs two simultaneous searches, one from initial node (forward search)
and other from goal node (backward search).
• The main idea behind bidirectional searches is to reduce the time taken
for search drastically.
• This takes place when both searches happen simultaneously from the
‘initial node depth’ or ‘breadth-first’ and ‘backwards from goal nodes’.
They intersect somewhere in between of the graph.
• The path traverses from the initial node through the intersecting point to
goal vertex and that is the shortest path found because of this search.
3/3/2024 Anagha Patil, VCET 39
Example

Step 1 : Let A be initial node and O the goal node and H is the
intersection node.
Step 2 : We start searching simultaneously from start to goal node and
backwards from goal node to start node.
Step 3 : When the forward search and backward search intersect at
one node, then searching stops.

3/3/2024 Anagha Patil, VCET 40


Performance Measures
Completeness : Bidirectional search is complete if BFS is used in both
searches.
Optimality : It is optimal if BFS is used for search and paths have
uniform cost.
Time and space complexity: Time and space complexity is O (bd/2).

3/3/2024 Anagha Patil, VCET 41


When to use?
We use bidirectional approach when :
(1) Both initial and goal states are unique and completely defined.
(2) The branching factor is exactly the same in both directions.

3/3/2024 Anagha Patil, VCET 42


Advantages
• Searching is fast.
• Requires less Memory.

Disadvantages
• Implementation of the bidirectional search tree is difficult.
• Goal state should be known in advance.

3/3/2024 Anagha Patil, VCET 43


Examples:
Question. Which solution would UCS find to move from node S to
node G if run on the graph below?

Solution: Path: S -> A -> B -> G


Cost: 5

3/3/2024 Anagha Patil, VCET 44


Examples:
Apply DLS with limit = 1.

Solution: Path: b -> c -> d

3/3/2024 Anagha Patil, VCET 45


Informed/Heuristic Search
• This can decide whether one non-goal state is more promising than
another non-goal state.
• The advantages of the informed search comes from the fact that :
1. It adds domain-specific information to select the best path along
which to continue searching.
2. Define a heuristic function h(n) that estimates the “goodness” of a
node n. Specifically, h(n) = estimated cost (or distance) of minimal cost
path from n to a goal state.
3. The heuristic function is an estimate of how close we are to a goal,
based on domain-specific information that is computable from the
current state description.
3/3/2024 Anagha Patil, VCET 46
Heuristic Function
• It is a function that maps from problem state description to
measures of desirability, usually represented as number.
• Which aspect of the problem state are considered, how these
aspects are evaluated, and weight given to the individual aspects
are chosen.
• We define a heuristic function h(n) that estimates the “goodness”
of a node n.
• Specifically, h(n) = estimated cost (or distance) of minimal cost path
from n to a goal state.
• The heuristic function is an estimate of how close we are to a goal,
based on domain-specific information that is computable from the
current state description.

3/3/2024 Anagha Patil, VCET 47


Heuristic Function
Two categories of problems use heuristics:
1. Problems for which no exact algorithms are known and one needs
to find an approximate and satisfying solution.
E.g., computer vision, speech recognition etc.
2. Problems for which exact solutions are known, but computationally
infeasible.
E.g., Rubik’s cube, chess etc.

3/3/2024 Anagha Patil, VCET 48


Simple Heuristic Function
1. In the famous 8-tile puzzle, the hamming distance is a popular
heuristic function. It is an indicator of the number of tiles in the
position they are to be.
2. In a game like chess, the material advantage one has over the
opponent is an indicator. Normally, the following values are assigned to
the pieces. Queen-9 etc.
• The purpose of heuristic function is to guide the search process in
the most profitable direction by suggesting which path to follow first
when more than one is available.
• The more accurate the heuristic function estimate the true merit of
each node in the search tree, the more direct the solution process.

3/3/2024 Anagha Patil, VCET 49


Key dimensions for heuristic search
1. Is the Problem Decomposable ?
2. Can Solution Steps be Ignored or Undone ?
3. Is the Universal Predictable ?
4. Is Good Solution Absolute or Relative ? (Is the Solution a State or a
Path?)
5. The Knowledge Base Consistent ?
6. What is the Role of Knowledge ?
7. Does the Task require Interaction with the Person?

3/3/2024 Anagha Patil, VCET 50


Can Solution Steps be Ignored or Undone ?
(i) Ignorable problems
Eg : Theorem proving
In which solution steps can be ignored.
(ii) Recoverable problems
Eg: 8 puzzle
In which solution steps can be undone.
(iii) Irrecoverable problems
Eg : Chess
In which solution steps can’t be undone.

3/3/2024 Anagha Patil, VCET 51


Does the Task require Interaction with the Person?
(i) Solitary Problems
In which the computer will be given a problem description and will
produce an answer, with no intermediate communication and with the
demand for an explanation of the reasoning process. Simple theorem
proving falls under this category.
(ii) Conversational Problems
In which there will be intermediate communication between a person
and the computer, whether to provide additional assistance to the
computer or to provide additional informed information to the user, or
both problems such as medical diagnosis fall under this category,
where people will be unwilling to accept the verdict of the program, if
they cannot follow its reasoning.

3/3/2024 Anagha Patil, VCET 52


Informed Search Algorithms
1. Hill climbing
2. Stimulated Annealing
3. Constraint satisfaction
3. Best-first search
4. A* algorithm
5. AO* algorithm
6. Beam search

3/3/2024 Anagha Patil, VCET 53


Hill Climbing
• 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.
• This algorithm is also called discrete optimization algorithm.
• It uses a simple heuristic function viz., the amount of distance the node is
from the goal.
• The ordering of choices is a heuristic measure of the remaining distance
one has to traverse to reach the goal node.
• Practically there is no difference between Hill climbing and depth-first
search except that the children of the node that has been expanded are
sorted by the remaining distance.
• It always moves in a single direction and no backtracking is possible.
• In this algorithm, we don't need to maintain and handle the search tree
or graph as it only keeps a single current state.

3/3/2024 Anagha Patil, VCET 54


Features
•Generate and Test variant: Hill Climbing is the variant of Generate and
Test method. The Generate and Test method produce feedback which
helps to decide which direction to move in the search space.
•Greedy approach: Hill-climbing algorithm search moves in the
direction which optimizes the cost.
•No backtracking: It does not backtrack the search space, as it does not
remember the previous states.

3/3/2024 Anagha Patil, VCET 55


Algorithm
• Step 1 : Put the initial node on a list START.
• Step 2 : If (START is empty) or (START = GOAL), then terminate
search.
• Step 3 : Remove the first node from START. Call this as node a.
• Step 4 : If (a = GOAL), then terminate search with success.
• Step 5 : Else if node a has successors, generate all of them. Find out
how far they are from the goal node. Sort them by the remaining
distance from the goal and add them at the beginning of START.
• Step 6 : Goto Step 2.

3/3/2024 Anagha Patil, VCET 56


Explaination
1. Evaluate the initial state. If it is also a goal state, then return it and
quit. Otherwise, continue with the initial state as the current state.
2. Loop until a solution is found or until there are no new operators left
to be applied in the current state:
(i) Select an operator that has not yet been applied to the current state
and apply it to produce a new state.
(ii) Evaluate the new state.
(a) If it is a goal state, then return it and quit.
(b) If it is not a goal state but it is better than the current state, then
make it the current state.
(c) If it is not better than the current state, then continue in the loop.
3/3/2024 Anagha Patil, VCET 57
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.
Solution: Backtracking technique can be a solution of the local
maximum in state space landscape. Create a list of the promising path
so that the algorithm can backtrack the search space and explore other
paths as well.

3/3/2024 Anagha Patil, VCET 58


Problems in Hill Climbing Algorithm:
2. 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.
Solution: The solution for the plateau is to take big steps or very little
steps while searching, to solve the problem. Randomly select a state
which is far away from the current state so it is possible that the
algorithm could find non-plateau region.

3/3/2024 Anagha Patil, VCET 59


Problems in Hill Climbing Algorithm:
3. 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.
Solution: With the use of bidirectional search, or by moving in different
directions, we can improve this problem.

3/3/2024 Anagha Patil, VCET 60


Simulated Annealing (SA)
• Simulated annealing is a variation of hill climbing in which, at the
beginning of the process, some downhill moves may be made.
• The idea is to do enough exploration of the whole space early on so that
the final solution is relatively intensive to the starting state.
• This should lower the chances of getting caught at a local maximum, a
plateau or a ridge.
• Simulated annealing as a computational process is patterned after the
physical process of annealing, in which physical substances such as metals
are melted (i.e., raised to high energy levels) and then gradually cooled
until some solid state is reached.
• Annealing refers to an analogy with thermodynamics, specifically with
the way that metals cool and anneal. Simulated annealing uses the
objective function of an optimisation problem instead of the energy of a
material.

3/3/2024 Anagha Patil, VCET 61


Simulated Annealing in Machine Learning
• S.A. is a technique that is used to find the best solution for either a global
minimum or maximum without having a check for every single possible
solution, that exists.
• This is super helpful when addressing massive optimisation problems like
the one previously stated.
• S.A. is a stochastic global search optimization algorithm.
• Annealing is a heat treatment process that changes the ‘physical and
sometimes’ also the chemical properties of a material to increase
ductility and reduce the hardness to make it more workable.
• It configurated correctly and under certain condition, S.A. can guarantee
finding the global optimum, whereas such a guarantee is available to Hill
Climbing /Descent if the all local optima in the search place have equal
scores / costs.

3/3/2024 Anagha Patil, VCET 62


Parameters for S.A.
• Choice of parameters depends on the expected variation in the
performance measure over the search space.
• A good rule of thumb is that the initial temperature should be set to
accept roughly 98o of the moves and that the final temperature
should be low enough that the solution does not improve much, if
at all. To improve simulated annealing, we have to do the following:
(i) Improve the accuracy.
(ii) Alter the parameters of the algorithm.
(iii) You could run your own meta-optimisation on the parameters of
your problem.

3/3/2024 Anagha Patil, VCET 63


Simulated Annealing in Machine Learning
• Simulated annealing is gradient based.
• It is an extension of gradient descent, and in the degenerate case
(zero temperature) they are the same: It generates random
neighbouring states, and if the fitness of that state is better than the
current one then it jumps there.
• That is, it seeks a local minimum.

3/3/2024 Anagha Patil, VCET 64


Examples
• Travelling salesman problem.
• Task allocation
• Graph colouring and partitioning
• Scheduling problems
• Non-linear function optimization

3/3/2024 Anagha Patil, VCET 65


Best First Search
• It is an informed search algorithm i.e. it uses heuristic function.
• This search procedure is an evaluation function variant of best the first search.
• The heuristic function used here called an evaluation function is an indicator
how far the node is from the goal node.
• Goal nodes have an evaluation function value of zero.
• Best-first search “jumps all around” in the search graph to identify the node
with minimal evaluation function value.
• There is only a minor variation between hill-climbing and best-first search. In
the former, we sorted the children of the first node being generated. Here, we
have to sort the entire list to identify the next node to be expanded.
Note: But there is a family of best first search algorithms, which have different
evaluation functions.

3/3/2024 Anagha Patil, VCET 66


Example

3/3/2024 Anagha Patil, VCET 67


Step Node being Children Available nodes Node chosen
expanded

1. S (A : 3), (B : 6), (C : 5) (A : 3), (B : 6), (C : 5) (A : 3)

2. A (D : 9), (E : 8) (B : 6), (C : 5), (D : 9), (E : 8) (C : 5)

3. C (H : 7) (B : 6), (D : 9), (E : 8), (H : 7) (B : 6)

4. B (F : 12), (G : 14) (D : 9), (E : 8), (H : 7), (F : 12), (G : 14) (H : 7)

5. H (I : 5), (J : 6) (D : 9), (E : 8), (F : 12), (G : 14), (I : 5), (I : 5)


(J : 6)

6. I (K : 1), (L : 0) (M : 2) (D : 9), (E : 8), (F : 12), (G : 14), Search stops as goal is


reached
(J : 6), (K : 1), (L : 0), (M : 2)

3/3/2024 Anagha Patil, VCET 68


Algorithm:
Step 1 : Put the initial node on a list START.
Step 2 : If (START is empty) or (START = GOAL), then terminate search.
Step 3 : Remove the first node from START. Call this as node a.
Step 4 : If (a = GOAL), then terminate search with success.
Step 5 : Else if node a has successors, generate all of them. Find out
how far they are from the goal node. Sort them by the remaining
distance from the goal.
Step 6 : Name this list as START 1.
Step 7 : Replace START with START 1.
Step 8 : Goto Step 2.

3/3/2024 Anagha Patil, VCET 69


Best First Search
• The best first search makes use of the function g (n) along with h
(n).
• The evaluation function f (n) represents the total cost. Here f (n) = g
(n) + h (n), where g (n) is the cost so far to reach n, while h (n) is the
estimated cost from n to the goal state.
• For greedy best-search g (n) = 0, and f (n) = h (n).

3/3/2024 Anagha Patil, VCET 70


If the goal (from home) to Roopali restaurant, we need to know the distance to Roopali Hotel,
which are shown in the Fig.

3/3/2024 Anagha Patil, VCET 71


Greedy Best First Search
The straight line distance heuristic estimate for the nodes are also given below :
h(s) = 10.5, h (A) = 10, h(B) = 6, h(c) = 4,
h(D) = 8, h(E) = 6.5, h(F) = 3 and h(G) = 0
Step2 Step4

Step3
Step1
Total cost
8 + 6.5 + 3 + 0 = 17. 5
optimal path
S→D→E→F→G
Remark : Here we have to find
optimal (greedy) search. And the path
S → D → E → F → G is optimal.
3/3/2024 Anagha Patil, VCET 72
(1) If we have chosen the path
S → A → B → E → F → G, then
H(A) = 10, H (B) = 6, H(E) = 6, H (F) = 3; H (G) = 0
And the total cost = 10 + 6 + 6.5 + 3 = 25.5
(2)OR, if we have chosen the path
S → D → A → B → E → F → G; then
H (D) = 4, H (A) = 3, H (B) = 4, H (E) = 5, H (F) = 4 and H (G) = 0
Then the total cost = 4 + 3 + 4 + 5 + 4 = 21
(3) For any other path, the total cost would have been greater than 17. 5
 S → D → E → F → G is optimal path and optimal cost is 17.5

3/3/2024 Anagha Patil, VCET 73


Performance Measures
• Greedy Best-First Search is not optimal.
• It is incomplete, even if the given state consists of finite number of
nodes.

3/3/2024 Anagha Patil, VCET 74


A* SEARCH
• Evaluation function: It is a value that estimates how far a particular
node is from the goal.
• Apart from the evaluation function value, one can also bring in cost
functions.
• Cost function: indicates how much resource like time, energy,
money etc. have been spent in reaching a particular node from the
start.
• While evaluation function values deal with the future, cost function
values deal with the past.
• Since cost function values are really expended, they are more
concrete than evaluation function values.

3/3/2024 Anagha Patil, VCET 75


A* SEARCH
• If it is possible for one to obtain the evaluation function values and
the cost function values, then A* algorithm can be used.
• While best-first search uses the evaluation function value only for
expanding the best node, A* uses the fitness number for its
computation.
• A* algorithm finds the shortest path through the search space using
the heuristic function.
• The fitness number (f(n)) (is the total of the evaluation function
value/heuristic value (h(n)) and the cost-function value (g(n)).
• f(n) is the estimated cost of the cheapest solution.
• g(n) is the cost reach node n from start node.
• h(n) is the cost to reach from node n to goal node.
3/3/2024 Anagha Patil, VCET 76
For example, consider node K, the fitness number is 20, which is
obtained as follows :
(Evaluation function of K) + (Cost function involved from start
node S to node K)
= 1 + (Cost function from S to C + Cost function from C to H +
Cost function from H to I + Cost function from I to K)
= 1 + 6 + 5 + 7 + 1 = 20.

Consider Fig. again with the same evaluation function


values. Now associated with each node are three numbers,
the evaluation function value, the cost function value and
the fitness number.

3/3/2024 Anagha Patil, VCET 77


Example
Consider the graph given in the Fig. below. Assume that the initial state is S and the goal state is 7. Find a path from the
initial state to the goal state using A* search. Also report the solution cost. The straight line distance heuristic estimate
for the nodes are as follows :
h(1) = 14, h(2) = 10, h(3) = 8, h(4) = 12, h(5) = 10, h(6) = 10, h(s) = 15
Step4
Step6
Step3

Step1 Step7

Now, open : 4(12 + 4), 1(14 + 3) Step5


Closed : 5(15)
Step2

3/3/2024 Anagha Patil, VCET 78


Performance Measures
A* is optimal and complete.

3/3/2024 Anagha Patil, VCET 79


Solve this example
5
2 B
D Solution:
A 3
1
1 2
4
C 5
S G 2 B
10 D
A 1 3
1 2
4
C
Node h(n) S G
S 5 10
A 3
B 4
Optimal path: S – A – C – G
C 2 Cost: 6
D 6
G 0
3/3/2024 Anagha Patil, VCET 80
AO* SEARCH
• The AO* method divides any given
difficult problem into a smaller group of
problems that are then resolved using the
AND-OR graph concept.
In the above figure, the buying of a car may be
• AND OR graphs are specialized graphs that broken down into smaller problems or tasks
are used in problems that can be divided that can be accomplished to achieve the main
into smaller problems. goal in the above figure, which is an example of
a simple AND-OR graph. The other task is to
• The AND side of the graph represents a either steal a car that will help us accomplish
set of tasks that must be completed to the main goal or use your own money to
achieve the main goal, while the OR side purchase a car that will accomplish the main
goal. The AND symbol is used to indicate the
of the graph represents different methods AND part of the graphs, which refers to the
for accomplishing the same main goal. need that all subproblems containing the AND
to be resolved before the preceding node or
issue may be finished.
3/3/2024 Anagha Patil, VCET 81
AO* SEARCH
• The start state and the target state are already known in the
knowledge-based search strategy known as the AO* algorithm, and
the best path is identified by heuristics.
• The informed search technique considerably reduces the algorithm’s
time complexity.
• The AO* algorithm is far more effective in searching AND-OR trees
than the A* algorithm.

3/3/2024 Anagha Patil, VCET 82


Working
• The evaluation function in AO* looks like this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
• here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.

3/3/2024 Anagha Patil, VCET 83


Difference between the A* Algorithm and
AO* algorithm
• A* algorithm and AO* algorithm both works on the best first search.
• They are both informed search and works on given heuristics values.
• A* always gives the optimal solution but AO* doesn’t guarantee to
give the optimal solution.
• Once AO* got a solution doesn’t explore all possible paths but A*
explores all paths.
• When compared to the A* algorithm, the AO* algorithm uses less
memory.
• opposite to the A* algorithm, the AO* algorithm cannot go into an
endless loop.

3/3/2024 Anagha Patil, VCET 84


Here in the above example, the Node which is given is the
heuristic value i.e h(n). Edge length is considered as 1.

3/3/2024 Anagha Patil, VCET 85


3/3/2024 Anagha Patil, VCET 86
3/3/2024 Anagha Patil, VCET 87
Problem Reduction

3/3/2024 Anagha Patil, VCET 88


Hill Climbing

3/3/2024 Anagha Patil, VCET 89

You might also like