0% found this document useful (0 votes)
3 views34 pages

Module-II

The document covers various search algorithms in artificial intelligence, including uninformed strategies like breadth-first and depth-first search, as well as informed strategies such as A* search and best-first search. It discusses the infrastructure for search algorithms, measuring performance, and techniques like problem reduction and constraint satisfaction. Each algorithm's advantages and disadvantages are outlined, emphasizing the importance of heuristics in informed search methods for efficiency and optimality.

Uploaded by

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

Module-II

The document covers various search algorithms in artificial intelligence, including uninformed strategies like breadth-first and depth-first search, as well as informed strategies such as A* search and best-first search. It discusses the infrastructure for search algorithms, measuring performance, and techniques like problem reduction and constraint satisfaction. Each algorithm's advantages and disadvantages are outlined, emphasizing the importance of heuristics in informed search methods for efficiency and optimality.

Uploaded by

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

Unit-II

Chapter-I: Searching & Reduction:


» Infrastructure for search algorithm
» Measuring problem-solving performance
» Uni-informed search strategies:
• Breath-first search.
• Depth-first search.
Chapter-II: Informed (Heuristics) Search Strategies:
» Generate- and- Test.
» Best-first search.
» A* search
» Problem reduction.
» Constraint Satisfaction.
» Means-end Analysis.
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, traditionally denoted by g(n), of the path from the initial
state to the node, as indicated by the parent pointers.
• Given the components for a parent node, it is easy to see how to compute
the necessary components for a child node. The function CHILD-NODE
takes a parent node and an action and returns the resulting child node:
Measuring problem- solving performance
• Before we get into the design of specific search algorithms, we need to
consider the criteria that might be used to chose among them. We can
evaluate an algorithm’s performance into 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?


denoted by O(V+E)=O(b^d)
where, b- branch factor
d-depth ( level 0 to n)

– Space complexity: how much memory is needed to perform the search?


• In AI, the graph is often represented implicitly by the initial state, action
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)

– 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
the memory
Uninformed Search Algorithms

• Uninformed search is a class of general-purpose search algorithms which


operates in brute force-way.

• Uninformed search algorithms do not have additional information about


state or search space other than how to traverse the tree, so it is also
called blind search.

• Following are the various types of uninformed search algorithms:


– Breadth-first Search
– Depth-first Search
Note:
– No knowledge about specific domain.
Ex: From A to B, how much time and cost needed to reach.

A B G
Breadth-first Search

• Breadth-first search is the most common search strategy for traversing a


tree or graph. This algorithm searches breadth wise 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.
• Breadth-first search implemented using FIFO queue data structure.
• Work with shallowest node (nearest node in branch wise).
Advantages:
• BFS will provide a solution if any solution exists.
• If there are more than one solutions for a given problem, then BFS will
provide the minimal solution which requires the least number of steps.
Disadvantages:
• 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.

• Example
Let’s discuss the algorithm for the BFS:

• Initialization: Enqueue the starting node into a queue and


mark it as visited.
• Exploration: While the queue is not empty:
– Dequeue a node from the queue and visit it (e.g., print its value).
– For each unvisited neighbor of the dequeued node:
• Enqueue the neighbor into the queue.
• Mark the neighbor as visited.
• Termination: Repeat step 2 until the queue is empty.
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 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.
• Advantage:
• 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).
• Disadvantage:
• 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 sometime it may go to
the infinite loop.

• Example.
Algorithm:

Step 1: SET STATUS = 1 (ready state) for each node in G

Step 2: Push the starting node A on the stack and set its STATUS = 2 (waiting state)

Step 3: Repeat Steps 4 and 5 until STACK is empty

Step 4: Pop the top node N. Process it and set its STATUS = 3 (processed state)

Step 5: Push on the stack all the neighbors of N that are in the ready state (whose STATUS
= 1) and set their STATUS = 2 (waiting state)

[END OF LOOP]
Informed Search Algorithms

• Informed search is a type of search algorithm in artificial intelligence that


uses additional information or heuristics to make more accurate decisions
about which paths to explore first.

• These heuristics provide estimates of how close a given state is to the


goal, guiding the search toward more promising solutions.

• Informed search is particularly useful in solving complex problems


efficiently, as it can significantly reduce the search space and improve the
speed of finding solutions.
• Informed search algorithms can quickly reject irrelevant or less
promising alternatives, allowing the search to concentrate on the most
reliable options, by employing domain-specific knowledge to drive the
search.
• Heuristics are used by these kinds of AI search algorithms to increase the
search’s effectiveness and speed.

• Advantages
– Faster convergence – By expanding promising nodes first based on heuristics,
informed search prunes large unproductive areas of the state space. This focused
search leads to exponentially faster goal discovery.
– Optimal solutions – Algorithms like A* can guarantee optimality given admissible
heuristics. This combined power of speed and accuracy is important for mission-
critical applications.
– Scalability – The ability to leverage heuristics lets informed search tackle much
bigger problems with large search spaces and higher complexity.
– Efficiency – Reduced nodes expanded means informed search uses computational
resources very economically. This enables applications on resource-constrained
devices.
• Disadvantages:

– Design complexity – Crafting high-quality heuristics requires extensive domain


expertise and insight. This makes scaling informed search to new problems difficult.
– Overhead cost – Computing complex heuristic values at each node adds overhead
to the search process, slowing it down. Simpler heuristics are more efficient.
– No guarantee of optimality – Unlike algorithms like A*, greedy searches will settle
for suboptimal solutions because they get trapped following misleading heuristics.
– Lack of exploration – Over-reliance on exploitation of heuristics can prevent
discovery of novel solutions. Balancing exploration is key.
• Types:
– Generate and Test
– Best-First-Search
– A * Search
Generate and Test Algorithm

• Generate and Test Search is a heuristic search technique based on Depth


First Search with Backtracking which guarantees to find a solution if
done systematically and there exists a solution.

• In this technique, all the solutions are generated and tested for the best
solution. It ensures that the best solution is checked against all possible
generated solutions.
• The generate-and-test strategy is the simplest of all the approaches. It consists of
the following steps:
Algorithm: Generate-and-Test
1. Generate a possible solution. For some problems. this means generating a
particular point in the problem space. For others, it means generating a path
from a start state.
2. 2. Test to see if this is actually a solution by comparing the chosen point or the
endpoint of the chosen path to the set of acceptable goal states.
3. If a solution has been found, quit. Otherwise, return to step 1.
• Properties of good generate:
– Complete: it will give define solution in all the possible state.

– Non-redundant: Repeat of generate solution can increase the number of state & also
time complexity.

– Informed: it must have the knowledge about the domain.

• Example – Traveling Salesman Problem (TSP)


A salesman has a list of cities, each of which he must visit exactly once. There are
direct roads between each pair of cities on the list. Find the route the salesman should
follow for the shortest possible round trip that both starts and finishes at any one of the
cities.

– Traveler needs to visit n cities.(visit exactly once).


– Know the distance between each pair of cities.
– Want to know the shortest route that visits all the cities once.
Best-First Search.

• Best First Search is a heuristic search algorithm that explores a graph by


expanding the most promising node first, according to a specified
evaluation function.

• It continuously selects nodes based on their estimated cost to reach the


goal, typically using a priority queue.

• BFS is suitable for finding paths in graphs and optimization problems


where informed decision-making is crucial.
• Best First Search algorithm in step-by-step form:

Priority Queue ‘PQ’ containing initial states


Loop
if PQ=Empty Return Fail
else
NODE Remove.first(PQ)
if NODE=Goal
return path from initial to NODE
else
generate all successor of NODE
and insert newly generated NODE
into PQ according to the cost value
END Loop
A* Search Algorithm

• To determine the shortest route between a beginning and a final point, a


search method is used. It is a useful approach that is frequently applied to
map traversal to determine the shortest path.

• In this algorithm, you traverse the tree in depth and keep moving and
adding up the total cost of reaching the cost from the current state to the
goal state and add it to the cost of reaching the current state.

• The use of weighted graphs in the use of A* is another factor contributing to


its effectiveness. Numbers are used in a weighted graph to indicate the costs
associated with each path or course of action.

• This implies that the algorithms can determine the shortest way in terms of
both time and distance, as well as the path with the lowest cost.
• It uses a formula: F(n) = g(n) + h(n)

Algorithm of A*:
The first step is to create an open list and a closed list.
At this point, the following actions must be taken:
Step 1. Enter the starting node in the OPEN list.
Step 2. If the OPEN list is empty return FAIL.
Step 3. Select the node from the OPEN list that has the smallest value (g
+ h).
if node = Goal, return success.
Step 4. Expand node "n" and generate all successors
Compute (g + h) for each successor node.
Step 5. If node "n" is OPEN/CLOSED, attach it to a back pointer.
Step 6. Go to step 3.
Advantages Of A* Algorithm
• A* algorithm solving complex problems.
• This algorithm is optimal and complete.
• It is the best search algorithm.

Disadvantages Of A* Algorithm
• It does not always produce the shortest path.
• In the A* algorithm complexity issues occur.
• It also requires memory.
Problem Reduction

• In artificial intelligence, problem reduction is the process of decomposing


large, difficult problems into smaller, easier-to-manage sub problems to
arrive at a solution.

• By breaking complex issues up into smaller, more manageable


challenges, this method enables AI systems to take on bigger, more
challenging tasks.
Problem Reduction Techniques in AI
• A successful technique for simplifying difficult problems and making
them simpler to address is problem reduction. It can also be applied to
lessen the algorithms' complexity in terms of time and space.

• An AND/OR graph can be used to depict the various ways a problem to


reduced.
• Problem Reduction algorithm:

1. Initialize the graph to the starting node.


2. Loop until the starting node is labeled SOLVED or until its cost goes
above FUTILITY.
1. Traverse the graph, staring at the initial node & following the current best path &
accumulate the set of nodes that are on that path and have not yet been expanded.
2. Pick one of these unexpanded nodes and expand it. If there are no successors,
assign FUTILITY as the value of this node. Otherwise, add its successors to the
graph and for each of them compute f(n), if f(n) of any node is 0, marks that node
as SOLVED.
3. Change the f(n) estimate of the newly expanded node to reflect the new
information provided by its successors. Propagate this change backwards through
the graph. If any node contains a successor arc whose descendant are all solved,
label the node itself as SOLVED.

Example.
Constraint Satisfaction

• Finding a solution that meets a set of constraints is the goal of constraint


satisfaction problems (CSPs), a type of AI issue. Finding values for a
group of variables that fulfill a set of restrictions or rules is the aim of
constraint satisfaction problems. For tasks including resource allocation,
planning, scheduling, and decision-making, CSPs are frequently
employed in AI.
• There are mainly three basic components in the constraint satisfaction
problem:
– 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.

– 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.

– 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.
• Constraint Satisfaction Problems (CSP) representation:
– The finite set of variables V1, V2, V3 ……………..Vn.
– Non-empty domain for every single variable D1, D2,
D3 …………..Dn.
– The finite set of constraints C1, C2 …….…, Cm.
• where each constraint Ci restricts the possible values for variables,
e.g., V1 ≠ V2
Constraint Satisfaction Problems (CSP) algorithms:

• The backtracking algorithm is a depth-first search algorithm that


methodically investigates the search space of potential solutions up until
a solution is discovered that satisfies all the restrictions. The method
begins by choosing a variable and giving it a value before repeatedly
attempting to give values to the other variables. The method returns to the
prior variable and tries a different value if at any time a variable cannot
be given a value that fulfills the requirements.
• The forward-checking algorithm is a variation of the backtracking
algorithm that condenses the search space using a type of local
consistency. For each unassigned variable, the method keeps a list of
remaining values and applies local constraints to eliminate inconsistent
values from these sets. The algorithm examines a variable’s neighbors
after it is given a value to see whether any of its remaining values become
inconsistent and removes them from the sets if they do. The algorithm
goes backward if, after forward checking, a variable has no more values.
• Algorithms for propagating constraints are a class that uses local
consistency and inference to condense the search space. These algorithms
operate by propagating restrictions between variables and removing
inconsistent values from the variable domains using the information
obtained.
Means-end Analysis

• We have studied the strategies which can reason either in forward or


backward, but a mixture of the two directions is appropriate for solving a
complex and large problem.

• Such a mixed strategy, make it possible that first to solve the major part of a
problem and then go back and solve the small problems arise during
combining the big parts of the problem. Such a technique is called Means-
Ends Analysis.

• Means-Ends Analysis is problem-solving techniques used in Artificial


intelligence for limiting search in AI programs.

• It is a mixture of Backward and forward search technique.

• The MEA analysis process centered on the evaluation of the difference


• How means-ends analysis Works:
– The means-ends analysis process can be applied recursively for a problem. It is a
strategy to control search in problem-solving. Following are the main Steps which
describes the working of MEA technique for solving a problem.
– First, evaluate the difference between Initial State and final State.
– Select the various operators which can be applied for each difference.
– Apply the operator at each difference, which reduces the difference between the
current state and goal state.
Operator Sub-goaling
• In the MEA process, we detect the differences between the current state
and goal state. Once these differences occur, then we can apply an
operator to reduce the differences.
• But sometimes it is possible that an operator cannot be applied to the
current state. So we create the subproblem of the current state, in which
operator can be applied, such type of backward chaining in which
operators are selected, and then sub goals are set up to establish the
preconditions of the operator is called Operator Sub goaling.
Algorithm for Means-Ends Analysis:
• Let's we take Current state as CURRENT and Goal State as GOAL, then
following are the steps for the MEA algorithm.

• Step 1: Compare CURRENT to GOAL, if there are no differences between both then return
Success and Exit.
• Step 2: Else, select the most significant difference and reduce it by doing the following steps
until the success or failure occurs.
– Select a new operator O which is applicable for the current difference, and if there is no
such operator, then signal failure.
– Attempt to apply operator O to CURRENT. Make a description of two states.
i) O-Start, a state in which O?s preconditions are satisfied.
ii) O-Result, the state that would result if O were applied In O-start.
– If
(First-Part <------ MEAN (CURRENT, O-START)
And
(LAST-Part <----- MEAN (O-Result, GOAL), are successful, then signal Success
and return the result of combining FIRST-PART, O, and LAST-PART.
• Assignment questions:

1. State and explain algorithm for Best First Search Algorithm with an
example. (10 Marks) 21-22
2. “Means-Ends Analysis approach is a technique used to solve problems in
Artificial intelligence”, Provide the conclusion with an example.
3. Explain the following search strategies i) best first search ii) A* search
4. Give an example of a problem for which breadth first search would work
better than depth first search
5. What is AND graph and OR graph? Explain A* algorithm with example.
6. Write the algorithm for mean max analysis.
7. Explain CSP with an algorithm and example.
8. Explain A* algorithm with example and algorithm.

You might also like