Unit 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 45

Problem Solving Methods

• In Artificial Intelligence, Search techniques are universal problem-solving methods.


Search Algorithm Terminologies:
• Search: Searching is a step by step procedure to solve a search-problem in a given
search space. A search problem can have three main factors:
– Search Space: Search space represents a set of possible solutions, which a
system may have.
– Start State: It is a state from where agent begins the search.
– Goal test: It is a function which observe the current state and returns whether
the goal state is achieved or not.
• Search tree: A tree representation of search problem is called Search tree. The root
of the search tree is the root node which is corresponding to the initial state.
• Actions: It gives the description of all the available actions to the agent.
• Transition model: A description of what each action do, can be represented as a
transition model.
• Path Cost: It is a function which assigns a numeric cost to each path.
• Solution: It is an action sequence which leads from the start node to the goal node.
• Optimal Solution: If a solution has the lowest cost among all solutions.
Types of Search Algorithms
Uninformed/Blind Search
• The uninformed search does not contain any domain knowledge such as closeness,
the location of the goal. It operates in a brute-force way as it only includes
information about how to traverse the tree and how to identify leaf and goal nodes.
Uninformed Search Algorithms
1. 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.
• Breadth-first search implemented using FIFO queue data structure.
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.
Uninformed/Blind Search
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.
•  S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K  
Uninformed/Blind Search
2. Depth-first Search
• 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.
• 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.
Uninformed/Blind Search
• Root node--->Left node ----> right node.
• It will start searching from root node S, and traverse A, then B, then D and E, after
traversing E, it will backtrack the tree as E has no other successor and still goal
node is not found. After backtracking it will traverse node C and then G, and here it
will terminate as it found goal node.
Uninformed/Blind Search
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:
• Standard failure value: It indicates that problem does not have any solution.
• Cutoff failure value: It defines no solution for the problem within a given depth
limit.
• Advantages:
• Depth-limited search is Memory efficient.
• Disadvantages:
• Depth-limited search also has a disadvantage of incompleteness.
• It may not be optimal if the problem has more than one solution.
Uninformed/Blind Search
4. Uniform-cost Search Algorithm:
• 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.
• Advantages:
• Uniform cost search is optimal because at every state the path with the least cost is
chosen.
• Disadvantages:
• 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.
Uninformed/Blind Search
5. 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.
Advantages:
• It combines the benefits of BFS and DFS search algorithm in terms of fast search and
memory efficiency.
Disadvantages:
• The main drawback of IDDFS is that it repeats all the work of the previous phase.
• 1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
Uninformed/Blind Search
6. Bidirectional Search Algorithm:
• 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.
Advantages:
• Bidirectional search is fast.
• Bidirectional search requires less memory
Disadvantages:
• Implementation of the bidirectional search tree is difficult.
• In bidirectional search, one should know the goal state in advance.
Informed Search Algorithms
• 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.
• Admissibility of the heuristic function is given as:
• h(n) <= h*(n)  
• Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost
should be less than or equal to the estimated cost.
Informed Search Algorithms
Best-first Search Algorithm (Greedy Search):-
Step 1: Place the starting node into the OPEN list.
Step 2: If the OPEN list is empty, Stop and return failure.
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.
Step 4: Expand the node n, and generate the successors of node n.
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.
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.
Step 7: Return to Step 2.
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) ,
Continue…………….
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]
• Iteration2: Open [E, F, A], Closed [S, B]
                  : Open [E, A], Closed [S, B, F]
• Iteration3: 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
Informed Search Algorithms
A* Search Algorithm:
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:
A* search algorithm is optimal and complete.
This algorithm can solve very complex problems.
Disadvantages:
It does not always produce the shortest path as it mostly based on heuristics and
approximation.
Informed Search Algorithms
Example

Solutions
• 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.
AO * Algorithm
Step-1: Create an initial graph with a single node (start node).
Step-2: Transverse the graph following the current path, accumulating
node that has not yet been expanded or solved.
Step-3: Select any of these nodes and explore it. If it has no successors
then call this value- FUTILITY else calculate f'(n) for each of the
successors.
Step-4: If f'(n)=0, then mark the node as SOLVED.
Step-5: Change the value of f'(n) for the newly created node to reflect its
successors by back propagation.
Step-6: Whenever possible use the most promising routes, If a node is
marked as SOLVED then mark the parent node as SOLVED.
Step-7: If the starting node is SOLVED or value is greater
than FUTILITY then stop else repeat from Step-2.
Informed Search Algorithms
Hill Climbing Algorithm in Artificial Intelligence:-
• Hill climbing algorithm is a local search algorithm which continuously moves in the
direction of increasing elevation/value to find the peak of the mountain or best
solution to the problem. It terminates when it reaches a peak value where no
neighbour has a higher value
Different regions in the state space landscape:
• Local Maximum: Local maximum is a state which is better than its neighbor states,
but there is also another state which is higher than it.
• Global Maximum: Global maximum is the best possible state of state space
landscape. It has the highest value of objective function.
• Current state: It is a state in a landscape diagram where an agent is currently
present.
• Flat local maximum: It is a flat space in the landscape where all the neighbor states
of current states have the same value.
• Shoulder: It is a plateau region which has an uphill edge.
Informed Search Algorithms
Types of Hill Climbing Algorithm:
• Simple hill Climbing:
• Steepest-Ascent hill-climbing:
• Stochastic hill Climbing:
1. Simple Hill Climbing:
• Simple hill climbing is the simplest way to implement a hill climbing algorithm. It
only evaluates the neighbor node state at a time and selects the first one which
optimizes current cost and set it as a current state. It only checks it's one
successor state, and if it finds better than the current state, then move else be in the
same state. This algorithm has the following features:
Step 1: Evaluate the initial state, if it is goal state then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Step 3: Select and apply an operator to the current state.
Step 4: Check new state:
If it is goal state, then return success and quit.
Else if it is better than the current state then assign new state as a current state.
Else if not better than the current state, then return to step2.Step 5: Exit.
Informed Search Algorithms
Steepest-Ascent hill climbing:
• The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This
algorithm examines all the neighboring nodes of the current state and selects one
neighbor node which is closest to the goal state. This algorithm consumes more
time as it searches for multiple neighbors
Step 1: Evaluate the initial state, if it is goal state then return success and stop, else
make current state as initial state.
Step 2: Loop until a solution is found or the current state does not change.
a.Let SUCC be a state such that any successor of the current state will be better
than it.
b.For each operator that applies to the current state:
a.Apply the new operator and generate a new state.
b.Evaluate the new state.
c.If it is goal state, then return it and quit, else compare it to the SUCC.
d.If it is better than SUCC, then set new state as SUCC.
e.If the SUCC is better than the current state, then set current state to SUCC.
Step 5: Exit.
Informed Search Algorithms
3. Stochastic hill climbing:
• Stochastic hill climbing does not examine for all its neighbor before moving.
Rather, this search algorithm selects one neighbor node at random and decides
whether to choose it as a current state or examine another state.
Problems in Hill Climbing Algorithm:
1. Local Maximum: A local maximum is a peak state in the landscape which is better
than each of its neighboring states, but there is another state also present which is
higher than the local maximum.
• Solution: Backtracking technique can be a solution of the local maximum in state
space landscape. Create a list of the promising path so that the algorithm can
backtrack the search space and explore other paths as well.
Informed Search Algorithms
2. Plateau: A plateau is the flat area of the search space in which all the neighbor states
of the current state contains the same value, because of this algorithm does not find
any best direction to move. A hill-climbing search might be lost in the plateau area.
• Solution: The solution for the plateau is to take big steps or very little steps while
searching, to solve the problem. Randomly select a state which is far away from the
current state so it is possible that the algorithm could find non-plateau region.

3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher
than its surrounding areas, but itself has a slope, and cannot be reached in a single
move.
• Solution: With the use of bidirectional search, or by moving in different directions,
we can improve this problem.
Adversarial Search
• Searches in which two or more players with conflicting goals are trying to explore
the same search space for the solution, are called adversarial searches, often known
as Games.
Game tree:
• A game tree is a tree where nodes of the tree are the game states and Edges of the
tree are the moves by players. Game tree involves initial state, actions function, and
result Function.
Example: Tic-Tac-Toe game tree:
• The following figure is showing part of the game-tree for tic-tac-toe game.
Following are some key points of the game:
• There are two players MAX and MIN.
• Players have an alternate turn and start with MAX.
• MAX maximizes the result of the game tree
• MIN minimizes the result
Mini-Max Algorithm in Artificial Intelligence
• Min-Max algorithm is mostly used for game playing in AI. Such as Chess,
Checkers, tic-tac-toe, go, and various tow-players game. This Algorithm computes
the minimax decision for the current state.
• In this algorithm two players play the game, one is called MAX and other is called
MIN.
• Both the players fight it as the opponent player gets the minimum benefit while they
get the maximum benefit.
• Both Players of the game are opponent of each other, where MAX will select the
maximized value and MIN will select the minimized value.
• The minimax algorithm performs a depth-first search algorithm for the exploration
of the complete game tree.
• The minimax algorithm proceeds all the way down to the terminal node of the tree,
then backtrack the tree as the recursion.
Working of Min-Max Algorithm
Step 1:
Continue……………….

• Step2:
Continue…………..
• Step 3:

• Step 4:
Alpha-Beta Pruning
• The main drawback of the minimax algorithm is that it gets really slow for complex
games such as Chess, go, etc. This type of games has a huge branching factor, and
the player has lots of choices to decide. This limitation of the minimax algorithm
can be improved from alpha-beta pruning
• there is a technique by which without checking each node of the game tree we can
compute the correct minimax decision, and this technique is called pruning. This
involves two threshold parameter Alpha and beta for future expansion, so it is
called alpha-beta pruning.
• The two-parameter can be defined as:
– Alpha: The best (highest-value) choice we have found so far at any point along
the path of Maximizer. The initial value of alpha is -∞.
– Beta: The best (lowest-value) choice we have found so far at any point along
the path of Minimizer. The initial value of beta is +∞.
• The Alpha-beta pruning to a standard minimax algorithm returns the same move as
the standard algorithm does, but it removes all the nodes which are not really
affecting the final decision but making algorithm slow. Hence by pruning these
nodes, it makes the algorithm fast.
Alpha-Beta Pruning
Key points about alpha-beta pruning :(α>=β)
• The Max player will only update the value of alpha.
• The Min player will only update the value of beta.
• While backtracking the tree, the node values will be passed to upper nodes instead
of values of alpha and beta.
• We will only pass the alpha, beta values to the child nodes.
Working of Alpha-Beta Pruning:
Step 1:
Alpha-Beta Pruning
• Step 2&3:
Alpha-Beta Pruning
• Step 4:

Step 5&6:
Alpha-Beta Pruning
• Step 7:

• Step 8:
Crypt Arithmetic Problem
• Cryptarithmetic Problem is a type of constraint satisfaction problem where the game
is about digits and its unique replacement either with alphabets or other symbols.
In cryptarithmetic problem, the digits  (0-9) get substituted by some possible
alphabets or symbols. The task in cryptarithmetic problem is to substitute each digit
with an alphabet to get the result arithmetically correct.
Crypt Arithmetic Problem
• The rules or constraints on a cryptarithmetic problem are as follows:
• There should be a unique digit to be replaced with a unique alphabet.
• The result should satisfy the predefined arithmetic rules, i.e., 2+2 =4, nothing else.
• Digits should be from 0-9 only.
• There should be only one carry forward, while performing the addition operation on
a problem.
• The problem can be solved from both sides, i.e., left hand side (L.H.S), or right
hand side (R.H.S)
• Let’s understand the cryptarithmetic problem as well its constraints better with the
help of an example:
• Given a cryptarithmetic problem, i.e., S E N D + M O R E = M O N E Y

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy