0% found this document useful (0 votes)
6 views97 pages

Unit 2 CH 2

This document discusses problem-solving in machine intelligence, focusing on problem-solving agents and their processes, which include goal formulation, problem formulation, search, and execution. It outlines well-defined problems and solutions, providing examples such as toy problems (vacuum world, 8-puzzle, 8-queens) and real-world problems (route-finding, touring problems, VLSI layout). The document also covers search algorithms, their infrastructure, and strategies for finding solutions in various contexts.

Uploaded by

N Thakore
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)
6 views97 pages

Unit 2 CH 2

This document discusses problem-solving in machine intelligence, focusing on problem-solving agents and their processes, which include goal formulation, problem formulation, search, and execution. It outlines well-defined problems and solutions, providing examples such as toy problems (vacuum world, 8-puzzle, 8-queens) and real-world problems (route-finding, touring problems, VLSI layout). The document also covers search algorithms, their infrastructure, and strategies for finding solutions in various contexts.

Uploaded by

N Thakore
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/ 97

Machine Intelligence (MI)

Unit – 2 (Part – 1)
Problem Solving
Topics to be covered
 Looping
 Problem Solving Agents
 Well-defined problems and solutions
 Example Problems
 Toy problems
 Real-world problems
 Searching for Solution
 Infrastructure for search algorithms
 Measuring problem-solving performance
 Search Strategies / Search Algorithms
 Uninformed Search Strategies
 Informed (Heuristic) Search Strategies
 Local Search Algorithms and Optimization Problems
 Hill-climbing search
Problem Solving Agents
 Problem solving agents are goal-based agents. It decides what to do by finding a
sequence of actions that leads to a desirable state or solution.
 An agent may need to plan when the best course of action is not immediately
visible. They may need to think through a series of moves that will lead them to
their goal state. Such an agent is known as a problem-solving agent, and the
computation it does is known as a search.
 The problem-solving agent follows this four-phase problem solving process:
1. Goal Formulation: This is the first and most basic phase in problem solving. It
arranges specific steps to establish a target/goal that demands some activity to
reach it. AI agents are now used to formulate goals.
2. Problem Formulation: It is one of the fundamental steps in problem-solving that
determines what action should be taken to reach the goal.
Problem Solving Agents
3. Search: After the Goal and Problem Formulation, the agent simulates sequences
of actions and has to look for a sequence of actions that reaches the goal. This
process is called search, and the sequence is called a solution.
 The agent might have to simulate multiple sequences that do not reach the
goal, but eventually, it will find a solution, or it will find that no solution is
possible.
 A search algorithm takes a problem as input and outputs a sequence of
actions.
4. Execution: After the search phase, the agent can now execute the actions that
are recommended by the search algorithm, one at a time. This final stage is
known as the execution phase.
Well-defined problems and solutions
 A problem can be defined formally by five components:
1. Initial State: It is the agent’s starting state or initial step towards its goal.
 For example, if a taxi agent needs to travel to a location (B), but the taxi is
already at location (A), the problem’s initial state would be the location (A).
2. Actions: It is a description of the possible actions that the agent can take.
 Given a state s, Actions(s) returns the set of actions that can be executed in
s. Each of these actions is said to be appropriate in s.
3. Transition Model: It describes what each action does.
 It is specified by a function Result(s,a) that returns the state that results
from doing action a in state s.
 The initial state, actions, and transition model together define the state
space of a problem.
Well-defined problems and solutions
 The state space forms a graph in which the nodes are states, and the links
between the nodes are actions. A path in the state space is a sequence of
states connected by a sequence of actions.
4. Goal Test: It determines whether a given state is a goal state.
 Sometimes there is an explicit list of potential goal states, and the test
simply checks whether the given state is one of them.
5. Path Cost: It assigns a numerical cost to each path that leads to the goal.
 The problem-solving agents choose a cost function that matches its
performance measure.
 Remember that the optimal solution has the lowest path cost of all the
solutions.
Example Problems
 The problem-solving approach has been used in a wide range of work contexts.
 There are two kinds of problem approaches:
1. Standardized/Toy problems: Its purpose is to demonstrate or practice various
problem solving techniques.
 It can be described concisely and precisely, making it appropriate as a
benchmark for academics to compare the performance of algorithms.
2. Real-world problems: It is real-world problems that need solutions.
 It does not rely on descriptions, unlike a toy problem, yet we can have a basic
description of the issue.
Toy problems: Vacuum world problem

Figure: The state space for the vacuum world. Links denote actions: L = Left, R = Right, S = Suck.
Toy problems: Vacuum world problem
 Let us take a vacuum cleaner agent and it can move left or right and its jump is to
suck up the dirt from the floor.
 This can be formulated as a problem as follows:
 States: The state is determined by both the agent location and the dirt locations.
The agent is in one of two locations, each of which might or might not contain dirt.
Thus, there are 2 × 22 = 8 possible world states. A larger environment with n
locations has n × 2n states.
 Initial state: Any state can be designated as the initial state.
 Actions: In this simple environment, each state has just three actions: Left, Right,
and Suck. Larger environments might also include Up and Down.
Toy problems: Vacuum world problem
 Transition model: The actions have their expected effects, except that moving
Left in the leftmost square, moving Right in the rightmost square, and Sucking in a
clean square have no effect. The complete state space is shown in figure.
 Goal test: This checks whether all the squares are clean.
 Path cost: Each step costs 1, so the path cost is the number of steps in the path.
Toy problems: 8-puzzle problem
 The 8-puzzle, an instance of which is
shown in Figure, consists of a 3×3
board with eight numbered tiles and a
blank space.
 A tile adjacent to the blank space can
slide into the space. The object is to
reach a specified goal state, such as
the one shown on the right of the
Figure: : A typical instance of the 8-puzzle.
figure.
Toy problems: 8-puzzle problem
 The standard formulation is as follows:
 States: A state description specifies the location of each of the eight tiles and the
blank in one of the nine squares.
 Initial state: Any state can be designated as the initial state. Note that any given
goal can be reached from exactly half of the possible initial states.
 Actions: The simplest formulation defines the actions as movements of the blank
space Left, Right, Up, or Down. Different subsets of these are possible depending
on where the blank is.
 Transition model: Given a state and action, this returns the resulting state; for
example, if we apply Left to the start state in figure, the resulting state has the 5
and the blank switched.
Toy problems: 8-puzzle problem
 Goal test: This checks whether the state matches the goal configuration shown in
figure. (Other goal configurations are possible).
 Path cost: Each step costs 1, so the path cost is the number of steps in the path.
 The 8-puzzle belongs to the family of sliding-block puzzles, which are often used
as test problems for new search algorithms in AI.
 The 8-puzzle has 9!/2=181,440 reachable states and is easily solved. The 15-
puzzle (on a 4×4 board) has around 1.3 trillion states, and random instances can
be solved optimally in a few milliseconds by the best search algorithms.
 The 24-puzzle (on a 5 × 5 board) has around 1025 states, and random instances
take several hours to solve optimally.
Toy problems: 8-queens problem
 The goal of the 8-queens problem is to
place eight queens on a chessboard
such that no queen attacks any other.
(A queen attacks any piece in the
same row, column or diagonal).
 Figure shows an attempted solution
that fails: the queen in the rightmost
column is attacked by the queen at the
top left.

Figure: Almost a solution to the 8-queens problem


Toy problems: 8-queens problem
 There are two main kinds of formulation: Incremental formulation and complete-
state formulation.
1. Incremental formulation: It involves operators that augment the state description,
starting with an empty state; for the 8-queens problem, this means that each action
adds a queen to the state. Following steps are involved in this formulation:
 States: Any arrangement of 0 to 8 queens on the board is a state.
 Initial state: No queens on the board.
 Actions: Add a queen to any empty square.
 Transition model: Returns the board with a queen added to the specified square.
 Goal test: 8 queens are on the board, none attacked.
 Path cost: There is no need for path cost because only final states are counted.
In this formulation, there is approximately 1.8 x 1014 possible sequence to investigate.
Toy problems: 8-queens problem
2. Complete-state formulation: It starts with all 8 queens on the board and moves
them around saving from the attacks. Following steps are involved in this
formulation:
States: Arrangement of all the 8 queens one per column with no queen
attacking the other queen.
Actions: Move the queen at the location where it is safe from the attacks.
This formulation is better than the incremental formulation as it reduces the
state space from 1.8 x1014 to 2057, and it is easy to find the solutions.
Real-world problems: Route-finding problem
 Route-finding algorithms are used in a variety of application such as routing in computer
networks, military operations planning and airline travel planning systems. These
problems are typically complex to specify.
 Consider a simplified example of an airline travel problem specified as follows:
 States: Each state obviously includes a location (e.g., an airport) and the current time.
 Initial state: This is specified by the user’s query.
 Actions: Take any flight from the current location, in any seat class, leaving after the
current time, leaving enough time for within-airport transfer if needed.
 Transition model: The state resulting from taking a flight will have the flight’s
destination as the current location and the flight’s arrival time as the current time.
 Goal test: Are we at the final destination specified by the user?
 Path cost: This depends on monetary cost, waiting time, flight time, customs and
immigration procedures, seat quality, time of day, type of airplane, and so on.
Real-world problems: Touring problems
 Touring problems are closely related to route-finding problems.
 The traveling salesperson problem (TSP) is a touring problem in which each city
must be visited exactly once.
 The aim is to find the shortest tour.
 In addition to planning trips for traveling salespersons, these algorithms have
been used for tasks such as planning movements of automatic circuit-board drills
and of stocking machines on shop floors.
Real-world problems: VLSI layout problem
 A VLSI layout problem requires positioning millions of components and
connections on a chip to minimize area, minimize circuit delays, minimize stray
capacitances, and maximize manufacturing yield.
 The layout problem comes after the logical design phase and is usually split into
two parts: cell layout and channel routing.
 In cell layout, the primitive components of the circuit are grouped into cells, each
of which performs some recognized function. Each cell has a fixed footprint (size
and shape) and requires a certain number of connections to each of the other
cells. The aim is to place the cells on the chip so that they do not overlap and so
that there is room for the connecting wires to be placed between the cells.
 Channel routing finds a specific route for each wire through the gaps between the
cells. These search problems are extremely complex, but definitely worth solving.
Real-world problems: Robot navigation problem
 Robot navigation is a generalization of the route-finding problem.
 Rather than following a discrete set of routes, a robot can move in a continuous
space with an infinite set of possible actions and states.
 For a circular robot moving on a flat surface, the space is essentially two-
dimensional.
 When the robot has arms and legs or wheels that must also be controlled, the
search space becomes many-dimensional.
 Advanced techniques are required just to make the search space finite.
Real-world problems: Automatic assembly sequencing
 In assembly problems, the aim is to find an order in which to assemble the parts of
some object.
 If the wrong order is chosen, there will be no way to add some part later in the
sequence without undoing some of the work already done.
 Checking a step in the sequence for feasibility is a difficult geometrical search
problem closely related to robot navigation.
 Thus, the generation of legal actions is the expensive part of assembly
sequencing.
 Any practical algorithm must avoid exploring all but a tiny fraction of the state
space.
Searching for Solutions
 A solution is an action
sequence, so search algorithms
work by considering various
possible action sequences.
 The possible action sequences
starting at the initial state form
a search tree with the initial
state at the root; the branches
are actions, and the nodes
correspond to states in the
state space of the problem.

Figure: Partial search trees for finding a route from Arad to Bucharest.
Searching for Solutions
 Here, nodes that have been expanded are shaded; nodes that have been
generated but not yet expanded are outlined in bold; nodes that have not yet been
generated are shown in faint dashed lines.
 Figure shows the first few steps in growing the search tree for finding a route
from Arad to Bucharest. The root node of the tree corresponds to the initial state,
In(Arad).
 The first step is to test whether this is a goal state. Then we need to consider
taking various actions. We do this by expanding the current state; that is, applying
each legal action to the current state, thereby generating a new set of states.
 In this case, we add three branches from the parent node In(Arad) leading to three
new child nodes: In(Sibiu), In(Timisoara), and In(Zerind). Now we must choose
which of these three possibilities to consider further.
Searching for Solutions
 This is the essence of search - following up one option now and putting the others
aside for later, in case the first choice does not lead to a solution.
 Suppose we choose Sibiu first. We check to see whether it is a goal state (it is
not) and then expand it to get In(Arad), In(Fagaras), In(Oradea), and
In(RimnicuVilcea).
 We can then choose any of these four or go back and choose Timisoara or Zerind.
 Each of these six nodes is a leaf node, that is, a node with no children in the tree.
 The set of all leaf nodes available for expansion at any given point is called the
frontier (Open list).
 In Figure, the frontier of each tree consists of those nodes with bold outlines.
 The process of expanding nodes on the frontier continues until either a solution is
found or there are no more states to expand.
Searching for Solutions
 The general algorithm is shown
informally in figure.
 Search algorithms all share this
basic structure; they vary
primarily according to how they
choose which state to expand
next - the so-called search
strategy.

Figure: An informal description of the general tree-search and graph-


search algorithms. The parts of GRAPH-SEARCH marked in bold italic are
the additions needed to handle repeated states.
Infrastructure for search algorithms
 Search algorithms require a data structure to keep track of the search tree that is
being constructed.
 For each node n of the tree, we have a structure that contains four components:
n.STATE: the state in the state space to which the node corresponds;
n.PARENT: the node in the search tree that generated this node;
n.ACTION: the action that was applied to the parent to generate the node;
n.PATH-COST: the cost of the path from the initial state to the node, as
indicated by the parent pointers.
Measuring problem-solving performance
 Algorithm’s performance can be evaluated in four ways:
Completeness: Is the algorithm guaranteed to find a solution when there is
one?
Optimality: Does the strategy find the optimal solution?
Time complexity: How long does it take to find a solution?
Space complexity: How much memory is needed to perform the search?
 Time and space complexity are always considered with respect to some measure
of the problem difficulty.
 In theoretical computer science, the typical measure is the size of the state space
graph, |V| + |E|, where V is the set of vertices (nodes) of the graph and E is the set
of edges (links).
Measuring problem-solving performance
 In AI, the graph is often represented implicitly by the initial state, actions, and
transition model and is frequently infinite.
 For these reasons, complexity is expressed in terms of three quantities:
b, the branching factor or maximum number of successors of any node;
d, the depth of the shallowest goal node (i.e., the number of steps along the
path from the root); and
m, the maximum length of any path in the state space.
 Time is often measured in terms of the number of nodes generated during the
search, and space in terms of the maximum number of nodes stored in memory.
Search Strategies / Search Algorithms
 Based on the search problems
we can classify the search
strategies (algorithms) into:
1. Uninformed search
(blind search)
2. Informed search
(heuristic search)
Search Strategies / Search Algorithms
 Uninformed search (blind search) - This type of search strategy does not have any
additional information about the states except the information provided in the problem
definition.
 They can only generate the successors and distinguish a goal state from a non-goal
state. These type of search does not maintain any internal state, that’s why it is also
known as blind search.
 There are following types of uninformed searches:
 Breadth-first search
 Depth-first search
 Depth-limited search
 Uniform-cost search
 Iterative deepening search
 Bidirectional search
Search Strategies / Search Algorithms
 Informed (heuristic) search - This type of search strategy contains some
additional information about the states beyond the problem definition.
 This search uses problem-specific knowledge to find more efficient solutions.
 This search maintains some sort of internal states via heuristic functions (which
provides hints), so it is also called heuristic search.
 There are following types of informed searches:
Greedy best-first search
A* search
Breadth-first search
 Breadth-first search 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.
 The breadth-first search algorithm is an example of a general-graph search
algorithm.
 It implemented using FIFO queue data structure.
Breadth-first search
 Example – In the tree structure, we
have shown the traversing of the tree
using BFS algorithm from the root node
S to goal node K.
 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:
SABCDGHE
FIK
Breadth-first search
 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
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.
Breadth-first search
 Completeness: BFS is complete, which means if the shallowest goal node is at
some finite depth, then BFS will find a solution.
 Time Complexity: If the shallowest solution is at depth d and the goal test is done
when each node is generated then BFS generates b + b2 + b3 + ... +bd = O(bd)
nodes, i.e., has a time complexity of O(bd). If the goal test is done when each node
is expanded the time complexity of BFS is O(bd+1). Here, b is the branching factor.
 Space Complexity: Space complexity of BFS algorithm is given by the memory
size of frontier which is O(bd).
 Optimality: BFS is optimal if path cost is a non-decreasing function of the depth
of the node.
Depth-first search
 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 LIFO queue (i.e., stack) data structure for its implementation.
 The process of the DFS algorithm is similar to the BFS algorithm.
 Note: Backtracking is an algorithm technique for finding all possible solutions
using recursion.
Depth-first search
 Example – In this search tree, we have
shown the flow of depth-first search,
and it will follow the order as:
Root node  Left node  right node.
 It will start searching from root node S,
and traverse A, then B, then D and E,
after traversing E, it will backtrack the
tree as E has no other successor and
still goal node is not found.
 After backtracking it will traverse node
C and then G, and here it will terminate
as it found goal node.
Depth-first search
 Advantages –
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).
 Disadvantages –
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 sometimes it may go to the
infinite loop.
Depth-first search
 Completeness: DFS is incomplete on infinite trees or graphs. DFS is complete
within finite state space as it will expand every node within a limited search tree.
 Time Complexity: DFS has time complexity O(bm), where m is the maximum depth
of any node (may be infinite) and this can be much larger than d (Shallowest
solution depth), b is the branching factor.
 Space Complexity: DFS algorithm needs to store only single path from the root
node, hence space complexity of DFS is equivalent to 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.
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 if:
The solution is found.
There is no solution withing given depth limit.
Depth-limited search
 Example –
Depth limit (ℓ) = 2
Depth-limited search
 Advantages –
Solve the problem of infinite path with no solution of DFS.
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 incomplete if ℓ < d.
 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
 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 form 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.
 Uniform cost search is equivalent to BFS algorithm if the path cost of all edges is
the same.
Uniform-cost search
 Example –
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.
Uniform-cost search
 Completeness: Completeness is guaranteed provided the cost of every step
exceeds some small positive constant ε.
 Time Complexity: Uniform-cost search is guided by path costs rather than depths,
so its complexity is not easily characterized in terms of b and d. Instead, let C∗ be
the cost of the optimal solution, and assume that every action costs at least ε.
Then the algorithm’s worst-case time complexity is O(b1 + [C*/ε]), which can be
much greater than bd.
 Space Complexity: The same logic is for space complexity so, the worst-case
space complexity of Uniform-cost search is O(b1 + [C*/ε]).
 Optimal: It produces optimal solution as nodes are expanded in order of their path
cost.
Iterative deepening depth-first search
 The iterative deepening depth-first 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.
Iterative deepening depth-first search
 Example – This tree structure is showing
the iterative deepening depth-first search.
 IDDFS algorithm performs various
iterations until it does not find the goal
node.
 The iteration performed by the algorithm is
given as:
1'st Iteration  A
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
 In the third iteration, the algorithm will find
the goal node.
Iterative deepening depth-first search
 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
 Completeness: If the branching factor is finite, this algorithm is complete.
 Time Complexity: If the branching factor is b and the depth is d, the worst-case
time complexity is O(bd).
 Space Complexity: The space complexity of IDDFS will be O(bd).
 Optimal: If path cost is a non-decreasing function of node depth, the IDDFS
algorithm is optimal.
Bidirectional search
 Bidirectional search algorithm 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.
Bidirectional search
 Example – In this search tree,
bidirectional search algorithm is
applied.
 This algorithm 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.
 The algorithm terminates at node 9
where two searches meet.
Bidirectional search
 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
 Completeness: Bidirectional search is complete if we use BFS in both searches.
 Time Complexity: Time complexity of bidirectional search using BFS is O(bd/2).
 Space Complexity: Space complexity of bidirectional search is O(bd/2).
 Optimal: Bidirectional search is optimal.
Comparing uninformed search strategies
 Table below compares search strategies in terms of the four evaluation criteria.

 Here,  Superscript caveats are as follows:


 b is the branching factor;  a complete if b is finite;
 d is the depth of the shallowest solution;  b complete if step costs ≥ ε for
 m is the maximum depth of the search positive ε;
tree;  c optimal if step costs are all identical;
 ℓ is the depth limit.  d if both directions use breadth-first
search.
Informed (Heuristic) Search Strategies
 So far, we have learned about the uninformed search algorithms which looked
through search space for all possible solutions of the problem without having any
additional knowledge about search space.
 But informed search algorithm contains an array of knowledge such as how far we
are from the goal, path cost, how to reach to goal node, etc.
 This knowledge help agents to explore less to the search space and find more
efficiently the goal node.
 The informed search algorithm is more useful for large search space.
 Informed search algorithm uses the idea of heuristic, so it is also called heuristic
search.
Heuristics function
 Heuristic is a function which is used in informed search, and it finds the most
promising path.
 It takes the current state of the agent as its input and produces the estimation of
how close agent is from the goal.
 The heuristic method, however, might not always give the best solution, but it
guaranteed to find a good solution in reasonable time.
 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.
 Admissibility of the heuristic function is given as: h(n) <= h*(n)
 Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost
should be less than or equal to the estimated cost.
Pure Heuristic Search
 Pure heuristic search is the simplest form of heuristic search algorithms.
 It expands nodes based on their heuristic value h(n).
 It maintains two lists, OPEN and CLOSED list.
 In the CLOSED list, it places those nodes which have already expanded and in the
OPEN list, it places nodes which have yet not been expanded.
 On each iteration, each node n with the lowest heuristic value is expanded and
generates all its successors and n is placed to the closed list. The algorithm
continues until a goal state is found.
 Following are the two main informed (heuristic) search algorithms:
Greedy best-first search algorithm
A* search algorithm
Greedy best-first search algorithm
 Greedy best-first search algorithm always selects the path which appears best at
that moment.
 It is the combination of depth-first search and breadth-first search algorithms.
 It uses the heuristic function and search.
 Best-first search allows us to take the advantages of both algorithms.
 With the help of best-first search, at each step, we can choose the most promising
node.
 In the best first search algorithm, we expand the node which is closest to the goal
node and the closest cost is estimated by heuristic function.
 The greedy best first algorithm is implemented by the priority queue.
Greedy best-first search algorithm
 Algorithm:
1. Place the starting node into the OPEN list.
2. If the OPEN list is empty, Stop and return failure.
3. Remove the node n, from the OPEN list which has the lowest value of h(n), and
places it in the CLOSED list.
4. Expand the node n, and generate the successors of node n.
5. Check each successor of node n and find whether any node is a goal node or not. If
any successor node is goal node, then return success and terminate the search,
else proceed to Step 6.
6. For each successor node, algorithm checks for evaluation function f(n), and then
check if the node has been in either OPEN or CLOSED list. If the node has not been
in both lists, then add it to the OPEN list.
7. Return to Step 2.
Greedy best-first search algorithm
 Example – Consider this search
problem, and we will traverse it using
greedy best-first search.
 At each iteration, each node is
expanded using evaluation function
f(n) = h(n), which is given in the below
table.
 In this search example, we are using
two lists which are OPEN and CLOSED
Lists.
Greedy best-first search algorithm
 Following are the iteration for traversing the
above example.
 Open = [S:13]; Closed = [ ]
 Open = [B:4, A:12]; Closed = [S:13]
 Open = [F:2, E:8, A:12]; Closed = [S:13, B:4]
 Open = [G:0, E:8, I:9, A:12]; Closed = [S:13, B:4, F:2]
 Open = [E:8, I:9, A:12]; Closed = [S:13, B:4, F:2, G:0]
 Hence the final solution path will be:
S  B F G
Greedy best-first search algorithm
 Advantages –
Best first search can switch between BFS and DFS by gaining the advantages
of both the algorithms.
This algorithm is more efficient than BFS and DFS algorithms.
 Disadvantages –
It can behave as an unguided depth-first search in the worst-case scenario.
It can get stuck in a loop as DFS.
This algorithm is not optimal.
Greedy best-first search algorithm
 Complete: Greedy best-first search is incomplete, even if the given state space is
finite.
 Time Complexity: The worst-case time complexity of Greedy best-first search is
O(bm).
 Space Complexity: The worst-case space complexity of Greedy best first search
is O(bm), where m is the maximum depth of the search space.
 Optimal: Greedy best first search algorithm is not optimal.
A* search algorithm
 A* search is the most commonly known form of best-first search.
 It uses heuristic function h(n), and cost to reach the node n from the start state
g(n).
 It has combined features of UCS and greedy best-first search, by which it solves
the problem efficiently.
 A* search algorithm finds the shortest path through the search space using the
heuristic function.
 This search algorithm expands less search tree and provides optimal result faster.
 A* algorithm is similar to UCS except that it uses g(n)+h(n) instead of g(n).
A* search algorithm
 In A* search algorithm, we use search heuristic as well as the cost to reach the
node.
 Hence, we can combine both costs as following, and this sum is called as a
fitness number.

 Note: At each point in the search space, only that node is expanded which have
the lowest value of f(n), and the algorithm terminates when the goal node is
found.
A* search algorithm
 Algorithm:
1. Place the beginning node in the OPEN list as the first step.
2. Check if the OPEN list is empty or not, if the list is empty then return failure and
stops.
3. Choose the node with the shortest value of the evaluation function (g+h) from the
OPEN list; if node n is the goal node, return success and stop; otherwise, return
failure and continue.
4. Expand node n and create all its descendants, then place n in the CLOSED list.
Check whether n' is already in the OPEN or CLOSED list for each successor n'; if
not, compute the evaluation function for n' and insert it in the OPEN list.
5. If node n' is already in OPEN and CLOSED, then it should be attached to the back
pointer which reflects the lowest g(n') value.
6. Return to Step 2.
A* search algorithm
 Example – In this example, we will
traverse the given graph using the
A* algorithm.
 The heuristic value of all states is
given in the table so we will
calculate the f(n) of each state
using the formula
f(n)= g(n) + h(n)
where g(n) is the cost to reach any
node from start state.
A* search algorithm
 Initialization: {(S, 5)}
 Iteration1: {(S  A, 4), (S  G, 10)}
 Iteration2: {(S  A  C, 4), (S  A  B, 7), (S  G, 10)}
 Iteration3: {(S  A  C  G, 6), (S  A  C  D, 11), (S  A  B, 7), (S  G, 10)}
 Iteration 4: will give the final result, as S  A  C  G it provides the optimal path
with cost 6.
 Points to remember –
 A* algorithm returns the path which occurred first, and it does not search for all
remaining paths.
 The efficiency of A* algorithm depends on the quality of heuristic.
 A* algorithm expands all nodes which satisfy the condition f(n).
A* search algorithm
 Advantages –
When compared to other search algorithms, the A* search method is the best.
The A* search algorithm is ideal and comprehensive.
This algorithm can solve very complex problems.
 Disadvantages –
It does not always produce the shortest path as it mostly based on heuristics
and approximation.
The A* search algorithm has some concerns with complexity.
The fundamental disadvantage of A* is that it requires a lot of memory
because it maintains all created nodes in memory, which makes it unsuitable
for a variety of large-scale issues.
A* search algorithm
 Complete: A* algorithm is complete as long as:
 Branching factor is finite.
 Cost at every action is fixed.
 Optimal: A* search algorithm is optimal if it follows below two conditions:
 Admissible: the first condition requires for optimality is that h(n) should be an admissible
heuristic for A* tree search. An admissible heuristic is optimistic in nature.
 Consistency: Second required condition is consistency for only A* graph-search.
 If the heuristic function is admissible, then A* tree search will always find the least cost
path.
 Time Complexity: The time complexity of A* search algorithm depends on heuristic function,
and the number of nodes expanded is exponential to the depth of solution d. So, the time
complexity is O(bd), where b is the branching factor.
 Space Complexity: The space complexity of A* search algorithm is O(bd).
Exercise: A* search algorithm - Example
Find the route between A and Z using A* algorithm. Values written at each vertex
shows the straight line distance heuristic function.
Exercise: A* search algorithm - Example
Apply the steps of the A* Search algorithm to find the shortest path from A to Z
using the following graph:
Exercise: A* search algorithm - Example
Apply the steps of the A* Search algorithm to find the shortest path from A to Z
using the following graph:
Local Search Algorithms and Optimization Problem
 The informed and uninformed search expands the nodes systematically in two
ways:
keeping different paths in the memory and
selecting the best suitable path,
which leads to a solution state required to reach the goal node.
 But beyond these “classical search algorithms”, we have some “local search
algorithms” where the path cost does not matter, and only focus on solution-
state needed to reach the goal node.
 A local search algorithm completes its task by traversing on a single current node
rather than multiple paths and following the neighbours of that node generally.
Local Search Algorithms and Optimization Problem
 Although local search algorithms are not systematic, still they have the
following two advantages:
Local search algorithms use a very little or constant amount of memory as
they operate only on a single path.
Most often, they find a reasonable solution in large or infinite state spaces
where the classical or systematic algorithms do not work.
 The local search algorithm works for pure optimized problems.
 A pure optimization problem is one where all the nodes can give a solution.
 But the target is to find the best state out of all according to the objective
function.
 Unfortunately, the pure optimization problem fails to find high-quality solutions to
reach the goal state from the current state.
Hill-climbing search
 Hill climbing search is a local search problem.
 The purpose of the hill climbing search is to climb a hill and reach the topmost
peak/point of that hill.
 It is based on the heuristic search technique where the person who is climbing up
on the hill estimates the direction which will lead him to the highest peak.
 Features of Hill-climbing –
 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.
State-space landscape of Hill-climbing algorithm
 To understand the concept of hill climbing algorithm, consider the below
landscape representing the goal state/peak and the current state of the climber.
State-space landscape of Hill-climbing algorithm
 The topographical regions shown in the figure can be defined as:
Global Maximum: It is the highest point on the hill, which is the goal state.
Local Maximum: It is the peak higher than all other peaks but lower than the
global maximum.
Flat local maximum: It is the flat area over the hill where it has no uphill or
downhill. It is a saturated point of the hill.
Shoulder: It is also a flat area where the summit (mountain top) is possible.
Current state: It is the current position of the person.
Types of Hill-climbing search algorithms
 There are following types of hill-climbing search:
Simple hill-climbing
Steepest-ascent hill-climbing
Stochastic hill-climbing
Random-restart hill-climbing
Types of Hill-climbing search algorithms
 Simple hill-climbing
 Simple hill-climbing is the simplest technique to climb a hill. The task is to reach
the highest peak of the mountain.
 Here, the movement of the climber depends on his move/steps. If he finds his
next step better than the previous one, he continues to move else remain in the
same state.
 This search focus only on his previous and next step.
 This algorithm has the following features:
Less time consuming.
Less optimal solution and the solution is not guaranteed.
Types of Hill-climbing search algorithms
 Simple hill-climbing algorithm:
Step 1: Evaluate the initial state, if it is goal state then return success and stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Step 3: Select and apply an operator to the current state.
Step 4: Check new state:
a. If it is goal state, then return success and quit.
b. Else if it is better than the current state then assigns new state as a
current state.
c. Else if not better than the current state, then return to step2.
Step 5: Exit.
Types of Hill-climbing search algorithms
 Steepest-ascent hill-climbing
 Steepest-ascent hill-climbing is different from simple hill climbing search.
 Unlike simple hill climbing search, it considers all the successive nodes,
compares them, and choose the node which is closest to the solution.
 Steepest hill-climbing search is similar to best-first search because it focuses on
each node instead of one.
 Note: Both simple as well as steepest-ascent hill climbing search fails when there
is no closer node.
Types of Hill-climbing search algorithms
 Steepest-ascent hill climbing algorithm:
Step 1: Evaluate the initial state, if it is goal state then return success and stop, else make
current state as initial state.
Step 2: Loop until a solution is found or the current state does not change.
a. Let SUCC be a state such that any successor of the current state will be better than
it.
b. For each operator that applies to the current state:
a) Apply the new operator and generate a new state.
b) Evaluate the new state.
c) If it is goal state, then return it and quit, else compare it to the SUCC.
d) If it is better than SUCC, then set new state as SUCC.
e) If the SUCC is better than the current state, then set current state to SUCC.
Step 3: Exit.
Types of Hill-climbing search algorithms
 Stochastic hill-climbing
 Stochastic hill-climbing does not focus on all the nodes.
 It selects one node at random and decides whether it should be expanded or
search for a better one.
 Random-restart hill climbing
 Random-restart algorithm is based on try and try strategy.
 It iteratively searches the node and selects the best one at each step until the goal
is not found.
 The success depends most commonly on the shape of the hill.
 If there are few plateaus, local maxima, and ridges, it becomes easy to reach the
destination.
Limitations of Hill-climbing algorithm
 Hill climbing algorithm is a fast and furious approach. It finds the solution state
rapidly because it is quite easy to improve a bad state. But there are following
limitations of this search:
 Local Maximum: A local maximum is a peak state in the landscape which is better
than each of its neighbouring 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.
Limitations of Hill-climbing algorithm
 Plateau: A plateau is the flat area of the search space in which all the neighbour
states of the current state contain 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.
Limitations of 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.

 Solution: With the use of bidirectional


search, or by moving in different
directions, we can improve this problem.
Simulated annealing
 Simulated annealing is similar to the hill climbing algorithm.
 It works on the current situation.
 It picks a random move instead of picking the best move.
 If the move leads to the improvement of the current situation, it is always
accepted as a step towards the solution state, else it accepts the move having a
probability less than 1.
 This search technique was first used in 1980 to solve VLSI layout problems.
 It is also applied for factory scheduling and other large optimization tasks.
Local beam search
 Local beam search is quite different from random-restart search. It keeps track of
k states instead of just one. It selects k randomly generated states and expand
them at each step. If any state is a goal state, the search stops with success. Else
it selects the best k successors from the complete list and repeats the same
process.
 In random-restart search where each search process runs independently, but in
local beam search, the necessary information is shared between the parallel
search processes.
 Disadvantages of local beam search –
This search can suffer from a lack of diversity among the k states.
It is an expensive version of hill climbing search.

You might also like