0% found this document useful (0 votes)
14 views61 pages

Unit-2 - Updated

The document outlines various problem-solving methods in artificial intelligence, emphasizing the importance of defining problems, forming state spaces, gathering knowledge, planning, and executing solutions. It discusses different search algorithms, including uninformed and informed searches, breadth-first search, depth-first search, and bidirectional search, highlighting their advantages and disadvantages. Additionally, it introduces concepts like completeness, optimality, and time and space complexity in relation to search algorithms.
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)
14 views61 pages

Unit-2 - Updated

The document outlines various problem-solving methods in artificial intelligence, emphasizing the importance of defining problems, forming state spaces, gathering knowledge, planning, and executing solutions. It discusses different search algorithms, including uninformed and informed searches, breadth-first search, depth-first search, and bidirectional search, highlighting their advantages and disadvantages. Additionally, it introduces concepts like completeness, optimality, and time and space complexity in relation to search algorithms.
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/ 61

PROBLEM SOLVING METHODS

 A problem is defined by its element and


relationship .
 To built a system to solve a particular
problem we need to do five things
1) Define a problem
Whenever a problem arises, the agent must
first define a problem to an extent so that a
particular state space can be represented
through it. Analyzing and defining the
problem is a very important step because if
the problem is understood something which
is different than the actual problem, then the
whole problem-solving process by the agent
is of no use.
2) Form the state space
Convert the problem statement into state
space. A state space is the collection of all the
possible valid states that an agent can reside
in. But here, all the possible states are chosen
which can exist according to the current
problem. The rest are ignored while dealing
with this particular problem.
3) Gather knowledge
Collect and isolate the knowledge which is
required by the agent to solve the current
problem. This knowledge gathering is done
from both the pre-embedded knowledge in
the system and the knowledge it has
gathered through the past experiences in
solving the same type of problem earlier.
4) Planning-(Decide data structure and control
strategy)
A problem may not always be an isolated
problem. It may contain various related
problems as well or some related areas where
the decision made with respect to the current
problem can affect those areas. So, a well-
suited data structure and a relevant control
strategy must be decided before attempting
to solve the problem.
5) Applying and executing
After all the gathering of knowledge and
planning the strategies, the knowledge
should be applied and the plans should be
executed in a systematic way so s to reach
the goal state in the most efficient and
fruitful manner.
• To find solution to any problem the foremost
condition is that it has to be precisely defined
or represented.
• By defining it precisely means to present an
abstract problem in real workable states that
are really understood.
• These states are then operated by some set
of operators and finally the solution is
obtained.
• The decision of which operator is to be
applied is taken by the control strategy used.
There are two ways in which the Al problem
can be represented.
• State Space Representation
• Problem Reduction
 State Space Representation consist of
defining an INITIAL State (from where to
start), the GOAL State (The destination) and
then we follow certain set of sequence of
steps (called States).

 Let's define each of them separately.


 State: Al problem can be represented as a
well formed set of possible states. State can
be Initial State ie starting point, Goal State ie.
destination point and various other possible
states between them which are formed by
applying certain set of rules.
• SPACE: In an AI problem the exhaustive set of all
possible states is called space.
• Search: In simple words search is a technique which
takes the initial state to goal state by applying certain
set of valid rules while moving through space of all
possible states.
• So we can say that to do a search process we need
the following.
• Initial State
• Set of valid Rules
• Goal State
So, a set of all possible states for a given problem is
known as state space representation of the problem.
 S:{S,A, Action(S), Result (S,A), Cost(S,A)}
• For example: In chess game:
• The initial position of all the pieces on a
chess board defines the initial state.
• The rules of playing chess defines the set of
legal rules and Goal state is defined by any
possible board position corresponding to
checkmate or a draw state.
• The point to be noted here is that there can
be more than one Goal state possible.
• State Space Representation of Tic Tac Toe
• Starting from the initial state as we move on
applying rules of putting X (cross) or 0 (Zero)
we keep on generating the states, hence the
set of states all such generated states is
called space, unless we reach one of the goal
states that can be a win situation or a draw
situation.
• The new state is generated from the earlier
one is by applying the a control strategy.
 In the water jug problem in Artificial
Intelligence, we are provided with two jugs: one
having the capacity to hold 3 gallons of water
and the other has the capacity to hold 4 gallons
of water.
 There is no other measuring equipment
available and the jugs also do not have any
kind of marking on them.
 GOAL: So, the agent’s task here is to fill the 4-
gallon jug with 2 gallons of water by using only
these two jugs and no other material.
 Initially, both our jugs are empty.
First solution: Second solution:
1) (0,0) 1) (0,0)
2) (0,3) 2) (4,0)
3) (3,0) 3) (1,3)
4) (3,3) 4) (1,0)
5) (4,2) 5) (0,1)
6) (0,2) 6) (4,1)
7) (2,0) 7) (2,3)
 Artificial Intelligence is basically the
replication of human intelligence through
computer systems or machines.
 It is done through the process of acquisition
of knowledge or information and the addition
of rules that are used by information, i.e.
learning, and then using these rules to derive
conclusions (i.e. reasoning) and then self-
correction.
 Completeness: A search algorithm is
complete when it returns a solution for any
input if at least one solution exists for that
particular input.
 Optimality: If the solution deduced by the
algorithm is the best solution, i.e. it has the
lowest path cost, then that solution is
considered as the optimal solution.
 Time and Space Complexity: Time complexity
is the time taken by an algorithm to complete
its task, and space complexity is the
maximum storage space needed during the
search operation.
 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 applies a way in which search
tree is searched without any information about the
search space like initial state operators and test for
the goal, so it is also called blind search.
 It examines each node of the tree until it achieves
the goal node.
 Informed search algorithms use domain knowledge.
 In an informed search, problem information is available
which can guide the search.
 Informed search strategies can find a solution more
efficiently than an uninformed search strategy.
 Informed search is also called a Heuristic search.
 A heuristic is a way which might not always be
guaranteed for best solutions but guaranteed to find a
good solution in reasonable time.
 Informed search can solve much complex problem
which could not be solved in another way.
 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.
 The breadth-first search algorithm is an example
of a general-graph search algorithm.
 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.
 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.
 A standard BFS implementation puts each vertex of
the graph into one of two categories:
 Visited
 Not Visited
 The purpose of the algorithm is to mark each
vertex as visited while avoiding cycles.

1) Start by putting any one of the graph's vertices at
the back of a queue.
2) Take the front item of the queue and add it to the
visited list.
3) Create a list of that vertex's adjacent nodes. Add
the ones which aren't in the visited list to the back
of the queue.
4) Keep repeating steps 2 and 3 until the queue is
empty.
5) The graph might have two different disconnected
parts so to make sure that we cover every vertex,
we can also run the BFS algorithm on every node
 In the tree structure, shown
the traversing of the tree
using BFS algorithm from
the root node S to goal
node K.
 BFS search algorithm
traverse in layers, so it will
follow the path which is
shown by the dotted arrow,
and the traversed path will
be:
 S---> A--->B---->C---
>D---->G--->H--->E---
->F---->I---->K
 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 (BRANCH FACTOR).
 T (b) = 1+b2+b3+.......+ bd= O (bd)
 Space Complexity: Space complexity of BFS
algorithm is given by the Memory size.
 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.
 Uniform-cost search is an uninformed
search algorithm that uses the lowest
cumulative cost to find a path from the
source to the destination.
 Nodes are expanded, starting from the root,
according to the minimum cumulative cost.
 The uniform-cost search is then
implemented using a Priority Queue.
 Used for weighted tree/Graph traversal.
 Advan: Optimal Solution
 Disadv: Infinite Loop
 Insert the root node into the priority queue
 Repeat while the queue is not empty:
Remove the element with the highest priority
If the removed node is the destination, print
total cost and stop the algorithm
Else, enqueue all the children of the current
node to the priority queue, with their
cumulative cost from the root as priority
 Depth first Search or Depth first traversal is a recursive
algorithm for searching all the vertices of a graph or
tree data structure.
 Traversal means visiting all the nodes of a graph.

 It uses STACK(LIFO)

Algorithm
 Start by putting any one of the graph's vertices on top
of a stack.
 Take the top item of the stack and add it to the visited
list.
 Create a list of that vertex's adjacent nodes. Add the
ones which aren't in the visited list to the top of the
stack.
 Keep repeating steps 2 and 3 until the stack is empty.
 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 (can be terminated without
solution).
 It may not be optimal if the problem has
more than one solution.
 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.
 Advantages:
 It combines the benefits of DFS and DLS
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.
 Bidirectional search is a graph search where
unlike Breadth First search and Depth First
Search, the search begins simultaneously
from Source vertex and Goal vertex and
ends when the two searches meet
somewhere in between in the graph.
 This is thus especially used for getting
results in a fraction of the time taken by
both DFS and FS searches.
 The search from the initial node is forward search
while that from the goal node is backwards.
 It is also based on heuristic search meaning
finding the shortest path to goal optimally.
 Heuristic refers to the concept of finding the
shortest path from the current node in the
graph to the goal node.
 The search always takes the shortest path to
the goal node. This principle is used in a
bidirectional heuristic search.
 The only difference being the two
simultaneous searches from the initial point
and from goal vertex. The main idea behind
bidirectional searches is to reduce the time
taken for search drastically.
 This happens when both searches happen
simultaneously from the initial node depth
or breadth-first and backwards from goal
nodes intersecting somewhere in between
of the graph.
 Now the path traverses through the initial
node through the intersecting point to goal
vertex is the shortest path found because of
this search.
 This is the shortest path and found in a
fraction of time taken by other search
algorithms.
 Step 1: Say, A is the
initial node and O is the
goal node, and H is the
intersection node.
 Step 2: We will start
searching
simultaneously from
start to goal node and
backward from goal to
start node.
 Step 3: Whenever the
forward search and
backward search
intersect at one node,
 Thus, it is possible when both the Start node
and goal node are known and unique,
separate from each other.
 Also, other points to be noted are that
bidirectional searches are complete if a
breadth-first search is used for both
traversals, i.e. for both paths from start node
till intersection and from goal node till
intersection.
 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 neighbor has a higher value.
 Hill climbing algorithm is a technique which
is used for optimizing the mathematical
problems. One of the widely discussed
examples of Hill climbing algorithm is
Traveling-salesman Problem in which we
need to minimize the distance traveled by the
salesman.
 It is also called greedy local search as it only
looks to its good immediate neighbor state
and not beyond that
 A node of hill climbing algorithm has two
components which are state and value.
 Hill Climbing is mostly used when a good
heuristic is available.
 In this algorithm, we don't need to maintain
and handle the search tree or graph as it only
keeps a single current state.
 Generate and Test variant: Hill Climbing is the
variant of Generate and Test method. The
Generate and Test method produce feedback
which helps to decide which direction to
move in the search space.
 Greedy approach: Hill-climbing algorithm
search moves in the direction which
optimizes the cost.
 No backtracking: It does not backtrack the
search space, as it does not remember the
previous states.

You might also like