AI Lecture-4 Solving Problems by Searching
AI Lecture-4 Solving Problems by Searching
LECTURE-4:
SOLVING PROBLEMS BY SEARCHING
By MUHAMMAD AFZAL
Solving Problems by
2
Searching
Sometimes, it's not easy for an agent to know
what to do next.
When this happens, a agent might need to
think ahead.
It can plan a series of steps to reach a goal. We
call this program a problem-solving agent, and
the process of planning is called searching.
Search algorithms are distinguished as:
informed algorithms: agent can estimate how far it
is from the goal
uninformed algorithms: where no such estimate is
available.
Problem-Solving Agents
3
Problem-solving agent
A kind of goal-based agent
It solves problem by
finding sequences of actions that lead to target
If the environment is unknown and the agent has no
additional information, then it can execute one of
the action randomly
Problem-Solving Agents
4
GOAL FORMULATION
This is first stage of problem solving agent based on
the current situation.
Goals help us focus on what we want to achieve.
They limit what we try to do, so we can focus on
important things.
Problem-Solving Agents
5
Search Algorithms
route from Arad to
Bucharest
9
10
Search Algorithms
11
to generate it
PATH-COST: the cost from initial state to the node
n itself
DEPTH: number of steps along the path from the
initial state
Measuring problem-solving
performance
13
The evaluation of a search strategy
Completeness:
is
the strategy guaranteed to find a solution when
there is one?
Optimality:
does
the strategy find the highest-quality solution
when there are several different solutions?
Time complexity:
how long does it take to find a solution?
Space complexity:
howmuch memory is needed to perform the
search?
Types of search algorithms
14
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
Un-informed Search Strategies
19
Example:
S---> A--->B---->C--->D---->G--->H--->E---->F---->I----
>K
Un-informed Search Strategies
20
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
Un-informed Search Strategies
23
Depth-first search: Depth-first search always
expands the deepest node in the frontier first
It starts from the root node and follows each path to
its greatest depth node before moving to the next
path
Only when the search hits a dead end
goes back and expands nodes at shallower levels
Dead end leaf nodes but not the goal
DFS uses a stack data structure for its
implementation
Depth-first search
Depth-first search
Depth-first search
26
Advantage:
DFS requires very less memory as it only needs
Advantages:
This algorithm is more efficient than BFS and
DFS algorithms.
Disadvantages:
It can get stuck in a loop as DFS.
This algorithm is not optimal.
Informed Search Strategies
32
A* search:
A* search algorithm is a simple and efficient
that can be used to find the optimal path
between two nodes in a graph
It searches for the shortest path between
the initial and the final state
Informed Search Strategies
33
Informed Search Strategies
34
Advantages:
A* search algorithm is the best algorithm than
other search algorithms.
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.
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.