Module-II
Module-II
• 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:
– d, the depth of the shallowest goal node ( i.e the number of steps along the path
from the root)
A B G
Breadth-first Search
• Example
Let’s discuss the algorithm for the BFS:
• Example.
Algorithm:
Step 2: Push the starting node A on the stack and set its STATUS = 2 (waiting state)
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
• 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:
• 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.
• 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.
• 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
Example.
Constraint Satisfaction
– 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:
• 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.
• 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.