Module 2 - MCA Sem II - AIML - Search Strategies
Module 2 - MCA Sem II - AIML - Search Strategies
Search
Strategies
S O LV I N G P R O B L E M S BY S E A R C H I N G , S E A R C H - I S S U E S I N T H E D E S I G N O F
SEARCH PROGRAMS, UN-INFORMED SEARCH- BFS, DFS
I N F O R M E D S E A R C H ( H E U R I S T I C S E A R C H T E C H N I Q U E S ) - G E N E R AT E - A N D - T E S T,
H I L L C L I M B I N G , B E S T- F I R S T S E A R C H , A * A L G O R I T H M , A L P H A - B E TA S E A R C H
ALGORITHM,
P R O B L E M R E D U C T I O N , A O * A L G O R I T H M , C O N S T R A I N T S AT I S FA C T I O N , M E A N S -
E N D S A N A LY S I S
Solving problems by searching
3. Transition Model :
RESULT(In(Arad),Go(Zerind)) = In(Zerind)
5. Path Cost :
sequence of path with sum of all the paths from
source to destination
Time complexity:
◦ Assume a state space where every state has b successors.
◦ root has b successors, each node at the next level has again b successors (total b2), …
◦ Assume solution is at depth d
◦ Worst case; expand all but the last node at depth d
◦ Total numb. of nodes generated:
Space complexity:
◦ if each node is retained in memory
Optimality:
◦ Does it always find the least-cost solution?
◦ In general YES
◦ unless actions have different cost.
Depth-first search (DFS)
DFS always expands the deepest node in the current frontier of the search tree. The search
proceeds immediately to the deepest level of the search tree, where the nodes have no
successors.
As those nodes are expended, they are dropped from the frontier, so then the search “backs up”
to the next deepest node that still has unexplored successors.
DFS is an instance of the general graph-search algorithm which uses a LIFO queue. This means
that the most recently generated node is chosen for expansion.
Expand deepest unexpanded node
Implementation:
◦ frontier = LIFO queue, i.e., put successors at front
DF-search, an example
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue (=stack)
Expand deepest unexpanded node
Implementation: fringe is a LIFO queue (=stack)
DF-search- evaluation
Completeness;
◦ NO unless search space is finite.
Time complexity;
◦ Terrible if m is much larger than d (depth of optimal solution)
◦ But if many solutions, then faster than BF-search
Space complexity;
◦ Backtracking search uses even less memory
◦ One successor instead of all b.
Optimallity; No
◦ Same issues as completeness
◦ Assume node J and C contain goal states
Informed Search Algorithms or Heuristic Search
“Heuristics means norms, procedures or principles that helps in deciding which
amongst the several available alternative choice of action promises to be the most
effective mean to achieve some predetermined goal”.
Informed Search Algorithm uses Heuristic function to find the most appropriate route.
While doing so, it considers the present state of the agent as the starting point and
produces an approximation of gap between agent and the goal.
The Solution hence suggested by this method may or may not always be the best, but
it definitely tries to suggest good or we may say decent solution in comparatively much
reasonable time.
Heuristic function examines the gap between the state and the goal and the outcome is
denoted by h(n).
It computes the cost of an optimal path between the given pair of states.
These are:
Best First Search Algorithm (Greedy search)
A* Search Algorithm
Hill Climbing
BEST-FIRST SEARCH ALGORITHM
This is also known as GREEDY SEARCH.
This search algorithm picks such path that appears best at that moment.
This algorithm is a blend of both - depth-first search and breadth-first search algorithms and in
its operations, it hence take the benefits of both the algorithms.
This algorithm is preferred as it helps choose the most promising node at each step.
Here, the node which is closest to the goal node is expanded and the closest cost is estimated by
heuristic function,
i.e. f(n)= h(n).
Where, h(n) = estimated cost from node n to the goal.
The greedy best first algorithm is applied by the priority queue.
Step 1: The process begins once the start node is placed into the OPEN list.
Step 2: In case the OPEN list is empty, Stop and return failure.
Step 3: Remove the node n (that has the lowest value h(n)) from the OPEN list, and place it in the CLOSED
list.
Step 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.
Step 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.
Time Complexity: In the worst situation, the time complexity of this Greedy best first search is O(bm).
Space Complexity: In the worst situation, the space complexity of Greedy best first search is O(bm). Where, m is
the maximum depth of the search space.
Complete: Generally, the Greedy best-first search is incomplete even when the given state space is finite.
Optimal: Greedy best first search algorithm is also not optimal.
A* SEARCH ALGORITHM
This Search Algorithm is the most commonly identified form of best-first search.
This method applies heuristic function h(n), and cost to reach the node n from the start state g(n).
This search algorithm searches the shortest available path through the search space by utilizing the heuristic
function, expands only few search tree and hence provides optimal result much faster.
Here since both search heuristic as well as the cost to reach the node is utilized, we can take a combination both
the costs (as stated below), and the sum hence arrived is called fitness number f(n).
f(n) = g(n) + h(n) Where, f(n)
is the estimated cost of the most optimal solution,
g(n) represents the cost calculated to reach node n from start state, and
h(n) represents the cost calculated to reach from node n to goal node.
Here it has to be noted that at each step in the search space, only the node having lowest value f(n) is expanded,
and once the goal node is reached, the algorithm gets terminated.
Algorithm used in A* search
Step1: The process starts once the starting node is placed in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if node n
is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each successor n',
check whether n' is already in the OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
Step 5: Else 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.
This algorithm is the best search algorithm than other search algorithms.
A* search algorithm is optimal and complete.
This algorithm is capable to solve very complex problems also.
This search algorithm does not always gives the shortest possible path as it is mostly based on heuristics
and approximation.
This search algorithm has some complexity issues.
The main drawback of applying this algorithm is the memory required for the task as it keeps all
generated nodes in the memory that occupies lots of space.
This way it is not preferred to resolve large-scale problems.
Example
In this example, the given graph has been traversed utilizing the A* search algorithm.
The heuristic value hence calculated for all the states is stated in the table (given below) using which f(n)
of each state can be calculated by applying the formula
f(n)= g(n) + h(n), where g(n) is the cost to reach any node from start state.
Simple, intuitive and straight forward: This search algorithm is preferred for its being simple and straight-
forward that is easy to understand and implement and its accuracy in solving problem and giving optimal result.
Memory efficiency: This algorithm is memory-efficient as it has to maintain only current state’s date.
Rapid and Swift Convergence: to solution makes this search algorithm useful especially when time is crucial.
Easily Modifiable: This algorithm may easily be changed and extended to contain additional heuristics or
constraints.
Susceptibility to Local Optima: Sometimes these search algorithms get stuck at locally optimal solutions which is
always not good and preferred.
Limited exploration: This feature restricts search algorithm to improvise according to neighboring or available
options and provides best solution from that range only which limits its search capability to local optima only and
limits its exploration which is not always desirable and helpful.
Dependence on Initial State: In this method, the initial step begins with a randomly selected solution. It has often
been found that quality and effectiveness of the solution depends a lot on the first value chosen.
Alpha-beta search
algorithm/Pruning
Alpha Beta Pruning is a search optimization technique
The word ‘pruning’ means cutting down branches and leaves. In Artificial Intelligence, Alpha-beta pruning is the pruning of useless
branches in decision trees.
In such games, one player aims to maximize their score while the other seeks to minimize it.
By eliminating unnecessary computations it simplifies the decision-making process, enabling faster and more efficient evaluations.
As a result, Alpha Beta Pruning is practical for real-time applications, such as game-playing AI, where speed and efficiency are critical.
Therefore, in this example, the optimal value of the maximizer would be 10.
AO* Algorithm
● Its an informed search and works as best first search.
● Each Node in the graph will also have a heuristic value associated with it.
Edge value h(n): Heuristic/ Estimated value of the nodes● It finds applications in
diverse problems, including the problem of parsing using stochastic grammars in
NLP.
CSPs are used extensively in artificial intelligence for decision-making problems where resources must be managed or arranged within
strict guidelines.
Scheduling: Assigning resources like employees or equipment while respecting time and availability constraints.
D is a set of domains {D1,D2, .....Dn}, where each Diis the set of possible values for Vi.
C is a set of constraints {C1, C2…..., Cn}, where each Ci is a constraint that restricts the values that can be assigned to a subset of the
variables.
Example of CSP : Map or graph
Coloring
1 2 3 4
Initial Domains R,G,B R,G,B R,G,B R,G,B
1.Variables: The things that need to be determined are variables. Variables in a CSP are the objects that must have
values assigned to them in order to satisfy a particular set of constraints. Boolean, integer, and categorical variables are
just a few examples of the various types of variables, for instance, could stand in for the many puzzle cells that need to be
filled with numbers in a sudoku puzzle.
2.Domains: The range of potential values that a variable can have is represented by domains. Depending on the issue, a
domain may be finite or limitless. For instance, in Sudoku, the set of numbers from 1 to 9 can serve as the domain of a
variable representing a problem cell.
3.Constraints: The guidelines that control how variables relate to one another are known as constraints. Constraints in a
CSP define the ranges of possible values for variables. Unary constraints, binary constraints, and higher-order constraints
are only a few examples of the various sorts of constraints. For instance, in a sudoku problem, the restrictions might be
that each row, column, and 3×3 box can only have one instance of each number from 1 to 9.