Unit 3 Artificial Intelligence
Unit 3 Artificial Intelligence
1. Breadth-first Search:
o This algorithm searches breadthwise in a tree or graph, so it is called breadth-first search.
o 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.
o Breadth-first search implemented using FIFO queue data structure.
Advantages:
o BFS will provide a solution if any solution exists.
o 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:
o It requires lots of memory since each level of the tree must be saved into memory to expand
the next level.
o BFS needs lots of time if the solution is far away from the root node.
2. Depth-first Search
o Depth-first search is a recursive algorithm for traversing a tree or graph data structure.
o 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.
o DFS uses a stack data structure for its implementation.
Note: Backtracking is an algorithm technique for finding all possible solutions using recursion.
Advantage:
o 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.
o It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right
path).
Disadvantage:
o There is the possibility that many states keep re-occurring, and there is no guarantee of
finding the solution.
o DFS algorithm goes for deep down searching and sometime it may go to the infinite loop.
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.
o Standard failure value: It indicates that problem does not have any solution.
o Cutoff failure value: It defines no solution for the problem within a given depth limit.
Advantages:
Disadvantages:
o The primary goal of the uniform-cost search is to find a path to the goal node which has the lowest
cumulative cost.
Advantages:
o Uniform cost search is optimal because at every state the path with the least cost is chosen.
Disadvantages:
o 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.
o 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.
o The iterative search algorithm is useful uninformed search when search space is large, and
Advantages:
o Itcombines the benefits of BFS and DFS search algorithm in terms of fast search and memory
efficiency.
Disadvantages:
o The main drawback of IDDFS is that it repeats all the work of the previous phase.
Informed Search Algorithms
Informed search algorithm contains an array of knowledge such as
A heuristic is a function that determines how near a state is to the desired state.
Heuristics functions vary depending on the problem and must be tailored to match that particular challenge
Heuristic Function is a function that estimates the cost of getting from one place to another (from
the current state to the goal state.) Also called as simply a heuristic.
Used in a decision process to try to make the best choice of a list of possibilities (to choose the
move more likely to lead to the goal state.) Best move is the one with the least cost.
starts with a non-optimal state and iteratively improves its state until some
predefined condition is met. The condition to be met is based on the heuristic
function. The aim of the algorithm is to reach an optimal state which is better
than its current state. The starting point which is the non-optimal state is referred
to as the base of the hill and it tries to constantly iterate (climb) untill it reaches
problems. It takes into account the current state and immediate neighbouring
state. The Hill Climbing Problem is particularly useful when we want to maximize
or minimize any particular function based on the input which it is taking. The
where we have to minimize the distance travelled by the salesman. Hill Climbing
Algorithm may not find the global optimal (best possible) solution but it is good
Greedy Approach: The algorithm moves in the direction of optimizing the cost i.e.
deciding the next course of action i.e. whether to move up or down the slope
neighbouring state, however, it is not the best possible state as there exists a state
Global Maxima/Minima: It is the best possible state in the state diagram. Here the
Current State: Current State is the state where the agent is present currently
Flat Local Maximum: This region is depicted by a straight line where all
neighbouring states have the same value so every node is local maximum over the
region
Problems in Hill Climbing Algorithm
Here ve discuss the problems in the hill-climbing algorithm:
1. Local Maximum
The algorithm terminates when the current node is local maximum as it is better
than its neighbours. However, there exists a global maximum where objective
2. Ridge
Ridge occurs when there are multiple peaks and all have the same value or in
other words, there are multiple local maxima which are same as global maxima
Solution: Ridge obstacle can be solved by moving in several directions at the
same time
3. Plateau
Plateau is the region where all the neighbouring nodes have the same value of
direction.
Solution: Plateau obstacle can be solved by taking making a big jump from the
the neighboring node for its operation. If the neighboring node is better than the
current node then it sets the neighbor node as the current node. The algorithm
checks only one neighbor at a time. Following are a few of the key feature of the
The algorithm results in sub-optimal solutions and at times the solution is not
guaranteed
Algorithm
2. Continue the Loop until a new solution is found or no operators are left to
apply
Else if New state is better than current state then Goto New state
5. Exit
2. Steepest-Ascent Hill Climbing
Steepest-Ascent hill climbing is an advanced form of simple Hill Climbing
Algorithm. It runs through all the nearest neighbor nodes and selects the node
which is nearest to the goal state. The algorithm requires more computation
neighbors at once.
Algorithm
2. Continue the Loop until a new solution is found or no operators are left to
apply
Let ‘Temp’ be a state such that any successor of the current state will have a
higher value for the objective function. For all operators that can be applied to
Else if New state is better than Temp then set this state as Temp
better than the current node instead, it randomly selects one neighboring node,
computation power
Simulated Annealing
https://www.youtube.com/watch?v=ct9rpyxbgaE
2.) 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.
1. f(n)= g(n).
Advantages:
o Best first search can switch between BFS and DFS by gaining the advantages of both the
algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
Example:
Consider the below 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. Following are the
iteration for traversing the above example.
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.
Algorithm of A* search:
Step1: Place the starting node 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.
Advantages:
Disadvantages:
o It does not always produce the shortest path as it mostly based on heuristics and
approximation.
o A* search algorithm has some complexity issues.
o The main drawback of A* is memory requirement as it keeps all generated nodes in the
memory, so it is not practical for various large-scale problems.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic value of all
states is given in the below 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.
Here we will use OPEN and CLOSED list.
Solution:
Initialization: {(S, 5)}
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:
o A* algorithm returns the path which occurred first, and it does not search for all remaining
paths.
o The efficiency of A* algorithm depends on the quality of heuristic.
o A* algorithm expands all nodes which satisfy the condition f(n)<="" li="">
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.
andy_08
Read
Discuss
Courses
Practice
Best-first search is what the AO* algorithm does. The AO* method divides any given
difficult problem into a smaller group of problems that are then resolved using the AND-
OR graph concept. AND OR graphs are specialized graphs that are used in problems that can
be divided into smaller problems. The AND side of the graph represents a set of tasks that
must be completed to achieve the main goal, while the OR side of the graph represents
different methods for accomplishing the same main goal.
AND-OR Graph
In the above figure, the buying of a car may be broken down into smaller problems or tasks
that can be accomplished to achieve the main goal in the above figure, which is an example
of a simple AND-OR graph. The other task is to either steal a car that will help us accomplish
the main goal or use your own money to purchase a car that will accomplish the main goal.
The AND symbol is used to indicate the AND part of the graphs, which refers to the need that
all subproblems containing the AND to be resolved before the preceding node or issue may be
finished.
The start state and the target state are already known in the knowledge-
based search strategy known as the AO* algorithm, and the best path is identified by
heuristics. The informed search technique considerably reduces the algorithm’s time
complexity. The AO* algorithm is far more effective in searching AND-OR trees than the A*
algorithm.
Working of AO* algorithm:
The evaluation function in AO* looks like this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.
Difference between the A* Algorithm and AO* algorithm
A* algorithm and AO* algorithm both works on the best first search.
They are both informed search and works on given heuristics values.
A* always gives the optimal solution but AO* doesn’t guarantee to give the optimal
solution.
Once AO* got a solution doesn’t explore all possible paths but A* explores all paths.
When compared to the A* algorithm, the AO* algorithm uses less memory.
opposite to the A* algorithm, the AO* algorithm cannot go into an endless loop.