0% found this document useful (0 votes)
42 views21 pages

Unit 3 Artificial Intelligence

State space search is an AI technique that finds the solution path from an initial state to a goal state by exploring various states. Uninformed search algorithms like breadth-first search, depth-first search, and depth-limited search traverse the state space without any additional information. Informed search algorithms use heuristics to guide the search towards the goal state more efficiently. Hill climbing is an informed local search technique that iteratively improves the current state until reaching an optimal local solution.

Uploaded by

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

Unit 3 Artificial Intelligence

State space search is an AI technique that finds the solution path from an initial state to a goal state by exploring various states. Uninformed search algorithms like breadth-first search, depth-first search, and depth-limited search traverse the state space without any additional information. Informed search algorithms use heuristics to guide the search towards the goal state more efficiently. Hill climbing is an informed local search technique that iteratively improves the current state until reaching an optimal local solution.

Uploaded by

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

State Space Search in Artificial Intelligence

State space search is a problem-solving technique used in Artificial Intelligence (AI) to


find the solution path from the initial state to the goal state by exploring the various
states. The state space search approach searches through all possible states of a
problem to find a solution. It is an essential part of Artificial Intelligence and is used in
various applications, from game-playing algorithms to natural language processing.
Uninformed Search Algorithms
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.

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.

3. Depth-Limited Search Algorithm:


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

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:

Depth-limited search is Memory efficient.

Disadvantages:

o Depth-limited search also has a disadvantage of incompleteness.


o It may not be optimal if the problem has more than one solution.

4. Uniform-cost Search Algorithm:


o used for traversing a weighted tree or graph.

o The primary goal of the uniform-cost search is to find a path to the goal node which has the lowest

cumulative cost.

o Node expansion or selection is based on path cost

o Priority queue is used for Implimentation

o High priority is given to minimum 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.

5. Iterative deepening depth-first Search:


o is a combination of DFS and BFS algorithms

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

depth of goal node is unknown.

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

 how far we are from the goal,


 path cost,
 how to reach to goal node, etc.
Informed search algorithm uses the idea of heuristic, so it is also called Heuristic search.

What is the Heuristic Function?

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.

Introduction to Hill Climbing in


Artificial Intelligence
Hill Climbing is a form of heuristic search algorithm which is used in solving

optimization related problems in Artificial Intelligence domain. The algorithm

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

the peak value, that is why it is called Hill Climbing Algorithm.

Hill Climbing Algorithm is a memory-efficient way of solving large computational

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

most commonly used Hill Climbing Algorithm is “Travelling Salesman” Problem”

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

for finding local minima/maxima efficiently.

Key Features of Hill Climbing in Artificial Intelligence


Following are few of the key features of Hill Climbing Algorithm

 Greedy Approach: The algorithm moves in the direction of optimizing the cost i.e.

finding Local Maxima/Minima

 No Backtracking: It cannot remember the previous state of the system so

backtracking to the previous state is not possible


 Feedback Mechanism: The feedback from the previous computation helps in

deciding the next course of action i.e. whether to move up or down the slope

State Space Diagram – Hill Climbing in Artificial


Intelligence
 Local Maxima/Minima: Local Minima is a state which is better than its

neighbouring state, however, it is not the best possible state as there exists a state

where objective function value is higher

 Global Maxima/Minima: It is the best possible state in the state diagram. Here the

value of the objective function is highest

 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

function value is higher

Solution: Back Propagation can mitigate the problem of Local maximum as it

starts exploring alternate paths when it encounters Local Maximum

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

objective function so the algorithm finds it hard to select an appropriate

direction.

Solution: Plateau obstacle can be solved by taking making a big jump from the

current state which will land you in non-plateau region

Types of Hill Climbing Algorithm in Artificial


Intelligence
Here we discuss the types of a hill-climbing algorithm in artificial intelligence:

1. Simple Hill Climbing


It is the simplest form of the Hill Climbing Algorithm. It only takes into account

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

Simple Hill Climbing Algorithm

 Since it needs low computation power, it consumes lesser time

 The algorithm results in sub-optimal solutions and at times the solution is not

guaranteed

Algorithm

1. Examine the current state, Return success if it is a goal state

2. Continue the Loop until a new solution is found or no operators are left to

apply

3. Apply the operator to the node in the current state

4. Check for the new state

 If Current State = Goal State, Return success and exit

 Else if New state is better than current state then Goto New state

 Else return to step 2

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

power than Simple Hill Climbing Algorithm as it searches through multiple

neighbors at once.

Algorithm

1. Examine the current state, Return success if it is a goal state

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

the current state

 Apply the operator to create a new state

 Examine new state

 If Current State = Goal State, Return success and exit

 Else if New state is better than Temp then set this state as Temp

 If Temp is better than Current State set Current state to Target

3. Stochastic Hill Climbing


Stochastic Hill Climbing doesn’t look at all its neighboring nodes to check if it is

better than the current node instead, it randomly selects one neighboring node,

and based on the pre-defined criteria it decides whether to go to the neighboring

node or select an alternate node.

Advantage of Hill Climbing Algorithm in Artificial


Intelligence
Advantage of Hill Climbing Algorithm in Artificial Intelligence is given below:

 Hill Climbing is very useful in routing-related problems like Travelling Salesmen

Problem, Job Scheduling, Chip Designing, and Portfolio Management

 It is good in solving the optimization problem while using only limited

computation power

 It is more efficient than other search algorithms

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

Were, h(n)= estimated cost from node n to the goal.

The greedy best first algorithm is implemented by the priority queue.

Best first search algorithm:

o Step 1: Place the starting node into the OPEN list.


o Step 2: If the OPEN list is empty, Stop and return failure.
o Step 3: Remove the node n, from the OPEN list which has the lowest value of h(n), and
places it in the CLOSED list.
o Step 4: Expand the node n, and generate the successors of node n.
o 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.
o 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
list, then add it to the OPEN list.
o Step 7: Return to Step 2.

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:

o It can behave as an unguided depth-first search in the worst case scenario.


o It can get stuck in a loop as DFS.
o This algorithm is not optimal.

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.

Expand the nodes of S and put in the CLOSED list

Initialization: Open [A, B], Closed [S]

Iteration 1: Open [A], Closed [S, B]


Iteration 2: Open [E, F, A], Closed [S, B]
: Open [E, A], Closed [S, B, F]

Iteration 3: Open [I, G, E, A], Closed [S, B, F]


: Open [I, E, A], Closed [S, B, F, G]

Hence the final solution path will be: S----> B----->F----> G

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.

3.) A* Search Algorithm:

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.

Step 6: Return to Step 2.

Advantages:

o A* search algorithm is the best algorithm than other search algorithms.


o A* search algorithm is optimal and complete.
o This algorithm can solve very complex problems.

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)}

Iteration1: {(S--> A, 4), (S-->G, 10)}

Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}

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="">

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)

AO* algorithm – Artificial intelligence

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.

Difference between INFORMED and UNINFORMED SEARCH

You might also like