You are on page 1of 8

Assignment 2

 Artificial Intelligence
MCT211

SCHOOL OF ENGINEERING AND TECHNOLOGY


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Submitted By
Student Name Nikita Anand
System_Id 2020468119
Programme/Section MCA

Department Computer Science and Engineering


Semester 2nd Semester
Submitted To
Faculty Name Prof. Jasneet Kaur

1. What are the factors that affect the quality of a heuristic?


Ans-
 A heuristic is a strategy for solving a problem quicker than traditional
approaches or for finding an approximate answer when traditional
approaches fail. This is a type of shortcut because we frequently
compromise one of optimality, completeness, accuracy, or precision for
speed.
 They compute the cost of the best path between two states. A heuristic
function for sliding-tiles games is calculated by calculating the amount of
movements made by each tile from its target state and summing these
numbers for all tiles.
 The costs of the edges change in a heuristic search, and the nodes to
investigate are chosen depending on heuristic functions.
 Heuristics aid in making fast judgments.
 Heuristic approaches simplify and speed up decision making by using
shortcuts and good-enough computations.
 By employing a heuristic function, we may decrease the amount of memory
required and arrive at a solution in less time.
 There are two types of calculations involved in heuristic search. The object-
level processing of actually expanding nodes and constructing the route
itself comes first. Then there's the metalevel calculation of determining
which node to expand next.
 A heuristic (or heuristic function) examines search strategies. It analyses
the given information and decides which branch to take at each branching
phase.

2. What is a local search algorithm? What are the problems faced by


a local search algorithm?
Ans- In Artificial Intelligence, local search is an optimization algorithm that finds
the best answer more rapidly. When we just worry about the solution and not the
journey to it, we employ local search methods. Local search is utilised in the
majority of AI models to find the best answer based on the model's cost function. In
linear regression, neural networks, and clustering models, local search is applied.
Hill climbing, simulated annealing, tabu search are some of the local search
algorithms.
the problems faced by a local search algorithm are:
(i) they cannot prove optimality,
(ii) they cannot provably reduce the search space,
(iii) they do not have well defined stopping criteria (this is particularly true for
metaheuristics),
(iv) they often have problems with highly constrained problems where feasible
areas of the solution space are disconnected.

3. Explain simulated annealing search in detail.


Ans- Annealing is a metallurgical process in which metals are gently cooled to a
low-energy state where they are extremely strong. Simulated annealing is a similar
optimization strategy. Thermodynamics is commonly used to describe it. When the
temperature is high, there is a lot of random movement; when the temperature is
low, there isn't much. Simulated annealing is a process in which the temperature is
gradually dropped, starting with a random search at high temperatures and
progressing to pure greedy descent as the temperature approaches zero. Local
minima should cause randomness to spring out and identify places with a low
heuristic value; greedy descent will lead to local minima. When temperatures are
high, deteriorating steps are more frequent than when temperatures are low.
Simulated annealing keeps the values assigned to variables current. It chooses a
variable at random, then a value at random, at each step. The algorithm accepts the
assignment and a new current assignment is created if adding that value to the
variable is an improvement or does not increase the number of conflicts.
Otherwise, depending on the temperature and how much worse the assignment is
than the existing one, it accepts it with some likelihood. The present assignment
will remain unchanged if the modification is not approved.
To control how many worsening steps are accepted, there is a positive real-valued
temperature T. Suppose A is the current assignment of a value to each variable.
Suppose that h(A) is the evaluation of assignment A to be minimized. For solving
constraints, h is typically the number of conflicts. Simulated annealing selects a
neighbour at random, which gives a new assignment A'. If h(A') ≤ h(A), it accepts
the assignment and A' becomes the new assignment. Otherwise, the assignment is
only accepted randomly with probability.

e(h(A)-h(A'))/T
Thus, if h(A') is close to h(A), the assignment is more likely to be accepted. If the
temperature is high, the exponent will be close to zero, and so the probability will
be close to 1. As the temperature approaches zero, the exponent approaches -∞,
and the probability approaches zero.
An annealing schedule, which describes how the temperature is dropped as the
search advances, is required for simulated annealing. One of the most often utilised
schedules is geometric cooling. Starting with a temperature of 10 and multiplying
by 0.97 after each step, for a temperature of 0.48 after 100 steps, is an example of a
geometric cooling schedule. It's an art to find a proper annealing schedule.

4. What is Admissibility in Heuristic search? Explain with the help of


an example.
Ans- A heuristic function is considered to be admissible, especially in algorithms
linked to pathfinding, if it never overestimates the cost of reaching the objective,
i.e. the cost it predicts to reach the objective is not higher than the lowest feasible
cost from the present point on the path.
 The heuristic function h(n) is called admissible if h(n) is never larger than
h*(n), namely h(n) is always less or equal to true cheapest cost from n to the
goal.
 A* is admissible if it uses an admissible heuristic, and h(goal) = 0.
 If the heuristic function, h always underestimates the true cost (h(n) is
smaller than h*(n)), then A* is guaranteed to find an optimal solution.
For example, in A* search the evaluation function (where is the current node) is:
f(n)=g(n)+h(n)
where
 f(n) = the evaluation function.
 g(n) = the cost from the start node to the current node
 h(n) = estimated cost from current node to goal.
h(n) is calculated using the heuristic function. With a non-admissible heuristic,
the A* algorithm could overlook the optimal solution to a search problem due to
an overestimation in f(n).

Formulation:
n is a node
h is a heuristic
h(n) is cost indicated by h to reach a goal from n
h*(n) is the optimal cost to reach a goal from n
h(n) is admissible if, Vn
h(n)< h*(n)
 An admissible heuristic can be derived from a relaxed version of the problem, or
by information from pattern databases that store exact solutions to
subproblems of the problem, or by using inductive learning methods.
 Never overestimates the cost to reach the goal. f(n) never overestimates the cost
of a solution along the current path through n. An obvious example of an
admissible heuristic is the straight-line distance.

 Consistency heuristic
 Consistent heuristic: for every node n and every successor n' of n generated
by any action a: h(n) ≤ c(n,a,n') + h(n')
 Required only for applications of A* to graph search
 Every consistent heuristic is also admissible.

 In this figure:

let's assume that h(C)=1 If f(A)=g(A)+h(A)=0+4=4, and f(C)=g(C)+h(C)=1+1=2


Then f(C) is NOT greater than or equal to f(A) Therefore this example is
consistent and admissible.
5. State all search techniques discussed in class. Compare their
performance analysis, and write their applications.
Ans- Based on the search problems we can classify the search algorithms into
uninformed (Blind search) search and informed search (Heuristic search)
algorithms.

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: 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. Breadth-first search implemented using
FIFO queue data structure.

Time Complexity: Time Complexity of BFS algorithm can be obtained by the


number of nodes traversed in BFS until the shallowest Node. Where the d=
depth of shallowest solution and b is a node at every state.
T (b) = 1+b2+b3+.......+ bd= O (bd)
Space Complexity: Space complexity of BFS algorithm is given by the Memory
size of frontier which is O(bd).
Completeness: BFS is complete, which means if the shallowest goal node is at
some finite depth, then BFS will find a solution.
Optimality: BFS is optimal if path cost is a non-decreasing function of the
depth of the node.

 Depth-first Search: Depth-first search isa 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.

Completeness: DFS search algorithm is complete within finite state space as it


will expand every node within a limited search tree.
Time Complexity: Time complexity of DFS will be equivalent to the node
traversed by the algorithm. It is given by:
T(n)= 1+ n2+ n3 +.........+ nm=O(nm)
Where, m= maximum depth of any node and this can be much larger than d
(Shallowest solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root
node, hence space complexity of DFS is equivalent to the size of the fringe set,
which is 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 with two Conditions of failure:


1. Standard failure value: It indicates that problem does not have any
solution.
2. Cut-off failure value: It defines no solution for the problem within a given
depth limit.

Completeness: DLS search algorithm is complete if the solution is above the


depth-limit.
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.

 Iterative deepening depth-first search: The iterative deepening 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.

Completeness: This algorithm is complete is if the branching factor is finite.


Time Complexity: Let's suppose b is the branching factor and depth is d then
the worst-case time complexity is O(bd).
Space Complexity: The space complexity of IDDFS will be O(bd).
Optimal: IDDFS algorithm is optimal if path cost is a non- decreasing function of
the depth of the node.

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

Time Complexity: Let C* is Cost of the optimal solution, and ε is each step to
get closer to the goal node. Then the number of steps is = C*/ε+1. Here we have
taken +1, as we start from state 0 and end to C*/ε.
Hence, the worst-case time complexity of Uniform-cost search isO(b1 + [C*/ε])/.
Space Complexity: The same logic is for space complexity so, the worst-case
space complexity of Uniform-cost search is O(b1 + [C*/ε]).
Optimal: Uniform-cost search is always optimal as it only selects a path with the
lowest path cost.

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

Completeness: Bidirectional Search is complete if we use BFS in both searches.


Time Complexity: Time complexity of bidirectional search using BFS is O(bd).
Space Complexity: Space complexity of bidirectional search is O(bd).
Optimal: Bidirectional search is Optimal.

Informed Search Algorithms


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.
In the informed search there are two main algorithms:

 Best First Search Algorithm (Greedy search): 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, i.e.
f(n)= g(n).   
Were, h(n)= estimated cost from node n to the goal.
The greedy best first algorithm is implemented by the priority queue.

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.
Complete: Greedy best-first search is also incomplete, even if the given state
space is finite.
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 solve 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).
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.
Complete: A* algorithm is complete as long as:
o Branching factor is finite.
o Cost at every action is fixed.
Optimal: A* search algorithm is optimal if it follows below two conditions:
o 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.
o 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(b^d), where b is the branching
factor.
Space Complexity: The space complexity of A* search algorithm is O(b^d)

You might also like