Ch-3 - AI Problem Solving by Searching
Ch-3 - AI Problem Solving by Searching
AI ch3-4 compiled by MT 1
What is search and terminologies?
AI ch3-4 compiled by MT 2
Searching Terminologies
• 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
AI ch3-4 compiled by MT 3
Search / Problem Solving
AI ch3-4 compiled by MT 4
Cont…
AI ch3-4 compiled by MT 6
Cont…
Problem Types
• Based on the environment types the problem type can
be different type.
. AI ch3-4 compiled by MT 10
Transition Model
• A description of what each action does; the formal
name for this is the transition model, specified by a
function RESULT(s, a) that returns the state that
results from doing action a in state s
• State Space
• Together, the initial state, actions, and transition model implicitly
define the state space of the problem—the set of all states
reachable from the initial state by any sequence of actions.
– Graph
• The state space forms a directed network or graph in which the
nodes are states and the links between nodes are actions.
– Path
• A path in the state space is a sequence of states connected by a
sequence of actions.
AI ch3-4 compiled by MT 11
Goal Test
• The goal test, which determines whether a given
state is a goal state.
– Sometimes there is an explicit set of possible goal states,
and the test simply checks whether the given state is one
of them.
Path Cost
• A path cost function that assigns a numeric cost to
each path.
• The problem-solving agent chooses a cost function
that reflects its own performance measure.
• The cost of a path can be described as the sum of the
costs of the individual actions along the path.
AI ch3-4 compiled by MT 12
Example Problems
• A toy problem
– is intended to illustrate or exercise various problem-solving
methods.
– It can be given a concise, exact description and hence is
usable by different researchers to compare the performance
of algorithms.
– vacuum world, 8-puzzle, 8-queens problem etc.
• A real-world problem
– is one whose solutions people actually care about. Such
problems tend not to have a single agreed-upon description,
but we can give the general flavor of their formulations.
– route-finding problem, Touring problems, traveling
salesperson problem, VLSI layout, Robot navigation,
Automatic assembly sequencing, protein design etc.
AI ch3-4 compiled by MT 13
Cont...
There are different types of search strategy.
One thing common to all this strategies, they can assess
against a certain criteria:
Completeness : find a solution if there is one
Optimality: find the least-cost solution
Time complexity: big-O complexity of the algorithm
regarding the number of nodes generated.
Space complexity: big-O complexity of the algorithm
regarding memory used.
AI ch3-4 compiled by MT 14
Measuring Problem-solving Performance
• We can evaluate an algorithm’s performance in four
ways:
– Completeness: Is the algorithm guaranteed to find a
solution when there is one?
– Optimality: Does the strategy find the optimal solution?
– Time complexity: How long does it take to find a
solution?
– Space complexity: How much memory is needed to
perform the search?
• Complexity is expressed in terms of three quantities:
– b, the branching factor or maximum number of
successors of any node;
– d, the depth of the shallowest goal node (i.e., the number
of steps along the path from the root); and
AI ch3-4 compiled by MT 15
Types of Search Strategies(Algorithms)
There are two types of search strategies:
1. Uninformed Search (Blind Search).
• Algorithms and strategies have no additional information about states beyond that
provided in the problem definition.
• All they can do is generate successors and distinguish a goal state from a non-goal
state.
• All search strategies are distinguished by the order in which nodes are
expanded. The uninformed search does not contain any domain
knowledge such as closeness, the location of the goal. It is also called level
order traversal.
• 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.
• Eg. Breadth-first search, Uniform-cost search, Depth-first search,
Depth-limited search, Iterative deepening depth-first search, Bidirectional
search AI ch3-4 compiled by MT 16
…
2. Informed Search (Heuristic Search)
– Strategies that know whether one non-goal state is
“more promising” than another are called informed
search or heuristic search strategies.
– can do quite well given some guidance on where to
look for solutions.
– E.g. Greedy best-first search, A* search, Memory-
bounded heuristic search.
AI ch3-4 compiled by MT 17
1. Breadth-First Search(BFS)
• BFS algorithm starts searching from the root node of
the tree and expands all successor node at the current
level before moving on to nodes of next depth level.
• It searches breadth wise in a tree or graph, so it is
called breadth-first search.
• Breadth-first search implemented using FIFO queue
data structure.
• In general, all the nodes are expanded at a given
depth in the search tree before any nodes at the next
level are expanded.
• Breadth-first search is an instance of the general graph-
search algorithm in which the shallowest unexpanded
node is chosen for expansion.
AI ch3-4 compiled by MT 18
Breadth-First Search:
• Breadth-first search expands the shallowest nodes in the search tree first. It
is complete, optimal for unit-cost operators, and has time and space
complexity of O(bd).
• It has two factors of time-complexity and space- complexity have to be
considered here also. Breadth-first search, being a brute search generates all
the nodes for identifying the goal. The amount of time taken for generating
these node is prepositional to the depth “d “ and branching factor “b “ .
Unlike depth-first search wherein the search procedure has to remember only
the paths it has generated, breath-first search procedure has to remember
every node it has generated.
Here searching progresses level by level, unlike depth-first search, this goes
deep into the tree.
AI ch3-4 compiled by MT 19
BFS
• bfs
AI ch3-4 compiled by MT 20
• How does breadth-first search rate according
to the four criteria from the previous section?
– it is complete
– is optimal
– space complexity is O(bd)
– time complexity is O(bd)
AI ch3-4 compiled by MT 21
2, Depth-first Search(DFS)
• Depth-first search is a 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.
Depth-first search always expands the deepest node in the current
frontier of the search tree where the nodes have no successors.
• Whereas breadth-first-search uses a FIFO queue, depth-first search
uses a LIFO queue.
• A variant of depth-first search called backtracking search uses still
less memory.
• The depth-first search algorithm is an instance of the graph-search
algorithm.
• Is explore as far down a branch as possible before backtracking and
explore other branches. AI ch3-4 compiled by MT 22
Depth-First Search:
AI ch3-4 compiled by MT 23
DFS
AI ch3-4 compiled by MT 24
Cont…
• Completeness: depth-first search is not complete.
• Optimal: depth-first search is not optimal.
• Space complexity: For a state space with
branching factor b and maximum depth m, depth-
first search requires storage of only O(bm) nodes.
(advantage over breadth-first search).
• Time complexity: A depth-first tree search may
generate all of the O(bm) nodes in the search tree,
where m is the maximum depth of any node and
b is branching factor.
AI ch3-4 compiled by MT 25
3, Depth limited search
AI ch3-4 compiled by MT 26
Cont…
Depth-limited search can be terminated with two Conditions of
failure:
a. Standard failure value: It indicates that problem does not have
any solution.
b. 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
AI ch3-4 compiled by MT 27
Find the path to get the goal ‘J‘ if in depth limit is 2
AI ch3-4 compiled by MT 28
4, Uniform cost search
AI ch3-4 compiled by MT 29
Find the goal node ‗’G‘ for the following search tree
AI ch3-4 compiled by MT 30
5, Iterative Deeping DFS
AI ch3-4 compiled by MT 31
• Solution
.
1'st Iteration---- > A
2'nd Iteration--- > A, B, C
3'rd Iteration ----- >A, B, D, E, C, F, G
In the third iteration, the algorithm will find the goal node.
AI ch3-4 compiled by MT 32
6. Bidirectional search
AI ch3-4 compiled by MT 33
Find the path to get the goal node ‗16‘
AI ch3-4 compiled by MT 34
Comparing Uninformed Search Strategies
AI ch3-4 compiled by MT 35
Fig. 3.6. Comparison of uninformed search strategies
B, Informed Search Strategies
AI ch3-4 compiled by MT 36
1, Gready Best-first search
AI ch3-4 compiled by MT 37
2, A* Search
• The most widely known form of best-first search is called
A* search (pronounced “A-star search”).
• It evaluates nodes by combining g(n), the cost to reach
the node, and h(n), the cost to get from the node to the
goal: f(n)=g(n)+h(n) .
• Since g(n) gives the path cost from the start node to node
n, and h(n) is the estimated cost of the cheapest path
from n to the goal, we have f(n)= estimated cost of the
cheapest solution through n.
• Thus, if we are trying to find the cheapest solution, a
reasonable thing to try first is the node with the lowest
value of g(n)+h(n).
• It turns out that this strategy is more than just
reasonable: provided that the heuristic function h(n)
AI ch3-4 compiled by MT 38
satisfies certain conditions.
.
AI ch3-4 compiled by MT 39
A* search
• It minimizes the current cost plus the estimated
cost to the goal. If the latter is never
overestimated (admissible heuristic) and we
handle repeated states, A* is complete,
• optimal, and optimally efficient among all optimal
search algorithms for a given admissible heuristic.
Its space complexity is still exponential in problem
size.
AI ch3-4 compiled by MT 40
Application of Problem solving and search Algorithms
• Problem solving and search Algorithms have a
wide range of Application in AI includes:
Game playing; chess, Go
Path-finding: in navigation systems
Puzzle solving
Robotics
Scheduling and planning
AI ch3-4 compiled by MT 41
.
END OF CHAPTER 3
AI ch3-4 compiled by MT 42