0% found this document useful (0 votes)
5 views64 pages

Artificial Intelligence: by Ms. Nida E Rub

The document discusses various search algorithms in artificial intelligence, focusing on uninformed search strategies like Depth Limited Search (DLS), Iterative Deepening Depth-First Search (IDDFS), and Bidirectional Search. It also covers informed search strategies, particularly the A* search algorithm, which combines path cost and heuristic estimates to find the shortest path efficiently. The document provides examples and applications of these algorithms, emphasizing their advantages and limitations.

Uploaded by

binteaqeel2004
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)
5 views64 pages

Artificial Intelligence: by Ms. Nida E Rub

The document discusses various search algorithms in artificial intelligence, focusing on uninformed search strategies like Depth Limited Search (DLS), Iterative Deepening Depth-First Search (IDDFS), and Bidirectional Search. It also covers informed search strategies, particularly the A* search algorithm, which combines path cost and heuristic estimates to find the shortest path efficiently. The document provides examples and applications of these algorithms, emphasizing their advantages and limitations.

Uploaded by

binteaqeel2004
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/ 64

ARTIFICIAL INTELLIGENCE

BY MS. NIDA E RUB


TYPES
OF
SEARCH
ALGORITHMS
UNINFORMED SEARCH STRATEGIES
TYPES
OF
SEARCH
ALGORITHMS
4. DEPTH LIMITED SEARCH
 This is similar to DFS but differs only in a few ways.
 The failure of DFS is alleviated by supplying a depth-first search with a predetermined
depth limit.
 That is, nodes at depth are treated as if they have no successors. This approach is
called a depth-limited search.
 The depth limit solves the infinite-path problem. Depth-limited search can be halted
in two cases:
 Standard Failure Value (SFV): The SFV tells that there is no solution to the
problem.
 Cutoff Failure Value (CFV): The Cutoff Failure Value tells that there is no solution
within the given depth limit.
EXAMPLE

• Node A is at Limit = 0, followed by nodes B, C, D, and E at Limit = 1


and nodes F, G, and H at Limit = 2.
• Our start state is considered to be node A, and our goal state is node
H.
• To reach node H, we apply DLS. So in the first case, let’s set our limit
to 0 and search for the goal.
Since Limit 0
• The algorithm will assume that there are no children after limit 0 even if nodes exist
further. Now, if we implement it, we will traverse only node A as there is only one node
in limit 0, which is basically our goal state.
• If we use SFV, it says there is no solution to the problem at limit 0, whereas LCV says
there is no solution for the problem until the set depth limit.
• Since we could not find the goal, let’s increase our limit to 1 and apply DFS till limit 1,
even though there are further nodes after limit 1. But those nodes aren’t expanded as
we have set our limit as 1.
• Hence nodes A, followed by B, C, D, and E, are expanded in the mentioned order.
• As in our first case, if we use SFV, it says there is no solution to the problem at limit 1,
whereas LCV says there is no solution for the problem until the set depth limit 1.
• Hence we again increase our limit from 1 to 2 in the notion to find the goal.
Till limit 2

• DFS will be implemented from our start node A and its children B, C, D, and E.
• Then from E, it moves to F, similarly backtracks the path, and explores the unexplored
branch where node G is present.
• It then retraces the path and explores the child of C, i.e., node H, and then we finally
reach our goal by applying DLS Algorithm.
• Suppose we have further successors of node F but only the nodes till limit 2 will be
explored as we have limited the depth and have reached the goal state.
Autonomous Vehicles (Path Planning):

Constrained Pathfinding:
In autonomous vehicle systems like drones or self-driving
cars, DLS is useful when limiting how far the vehicle plans a
path ahead.
For example, DLS can ensure that the search for a navigation
path doesn’t extend beyond a certain number of turns or
distance, helping the vehicle respond efficiently to dynamic
environments.
4. DEPTH LIMITED SEARCH

Consider the given


graph with Depth
Limit(l)=2, Target
Node=H and the
given source
node=A
D being the topmost element is
popped from the stack and the
neighbouring nodes G and H at
depth=3(>l) will not be pushed onto
the stack.
Traversal: ACFBED

Since the stack is now empty, all


nodes within the depth limit
have been visited, but the target
node H has not been reached.
5. ITERATIVE DEEPENING DFS

 Iterative deepening search (or iterative deepening


depth-first search) is a general strategy, often used in
combination with depth-first tree search, that finds the
best depth limit.
 It does this by gradually increasing the limit—first 0,
then 1, then 2, and so on—until a goal is found.
5. ITERATIVE DEEPENING DFS
 It is a search algorithm that uses the combined power of
the BFS and DFS algorithms.
 It is iterative in nature. Searches for the best depth in
each iteration.
 It performs the Algorithm until it reaches the goal node.
 The algorithm is set to search until a certain depth and
the depth keeps increasing at every iteration until it
reaches the goal state.
Solving Puzzles
IDDFS is used in AI to solve puzzles that
involve a large state space, like the sliding-
tile puzzle.
It systematically searches deeper levels of
the puzzle's state space while avoiding
excessive memory usage.
EXAMPLE
Consider the goal node to be G and the start state to be A.

• In the first iteration, it traverses only node A at level 0.


• Since the goal is not reached, we expand our nodes, go to the next
level, i.e., 1 and move to the next iteration.
• Then in the next iteration, we traverse the node A, B, and C.
• Even in this iteration, our goal state is not reached,
so we expand the node to the next level, i.e., 2, and
the nodes are traversed from the start node or the
previous iteration and expand the nodes A, B, C, and
D, E, F, G.
• Even though the goal node is traversed, we go
through for the next iteration, and the remaining
nodes A, B, D, H, I, E, C, F, K, and G(BFS & DFS) too
are explored, and we find the goal state in this
iteration.
• This is the implementation of the IDDFS Algorithm.
EXAMPLE
6. BIDIRECTIONAL

 Before moving into bidirectional search, let’s first understand a few terms.
 Forward Search: Looking in front of the end from the start.
 Backward Search: Looking from end to the start backward.
 We must traverse the tree from the start node and the goal node, and wherever they
meet, the path from the start node to the goal through the intersection is the
optimal solution.
 The Bidirectional Algorithm is applicable when generating predecessors is easy in
both forward and backward directions, and there exist only 1 or fewer goal states.
EXAMPLE
EXAMPLE
Do BFS from both directions.

• Start moving forward


from start node
(Green) and backwards
from end node
(Orange).

• Similar to BFS, at
every point explore
the next level of
nodes till you find an
intersecting node.
CONCLUSION
Uninformed search methods have access only to the problem definition. The basic algorithms are as
follows:
 – Breadth-first search expands the shallowest nodes first; it is complete, optimal for unit step costs,
but has exponential space complexity.
 – Uniform-cost search expands the node with lowest path cost, g(n), and is optimal for general step
costs.
 – Depth-first search expands the deepest unexpanded node first. It is neither complete nor optimal,
but has linear space complexity.
 --Depth-limited search adds a depth bound.
 – Iterative deepening search calls depth-first search with increasing depth limits until a goal is
found. It is complete, optimal for unit step costs, has time complexity comparable to breadth-first
search, and has linear space complexity.
 – Bidirectional search can enormously reduce time complexity, but it is not always applicable and
may require too much space.
INFORMED SEARCH STRATEGIES
CHAPTER 3
INFORMED SEARCH AND EXPLORATION

Informed search strategies that uses


problem-specific knowledge to find
solutions more efficiently
INFORMED SEARCH STRATEGIES
 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.
 This knowledge help agents to explore less to the search space
and find more efficiently the goal node.
 The informed search algorithm is more useful for large search
space.
 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.
 Heuristic function 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.
1. BEST FIRST SEARCH

• Idea: use an evaluation function f(n) for each node


f(n) provides an estimate for the total cost.
Expand the node n with smallest f(n).
• Implementation:
 Arrange the nodes in ascending order based on their cost
• Special cases:
Greedy best-first search
A* search
GREEDY BEST FIRST SEARCH
GREEDY BEST FIRST SEARCH
• Greedy best-first search algorithm always selects the path which appears best at
that moment. It is the combination of DFS and BFS algorithms.

• In BFS and DFS, when we are at a node, we can consider any of the adjacent as next
node.

• So both BFS and DFS blindly explore paths without considering any cost function.

• The idea of Best First Search is to use an evaluation function to decide which
adjacent is most promising and then explore.
GREEDY BEST FIRST 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.

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

• We use a priority queue to store costs of nodes. So the implementation is a


variation of BFS, we just need to change Queue to PriorityQueue.
EXAMPLE
• We start from source "S" and search for goal "I" using given costs.
• PriorityQueue initially contains S S

• Remove S from PriorityQueue and process unvisited neighbors of S to PriorityQueue


• PriorityQueue now contains {A, C, B} (C is put before B because C has lesser cost)

A C B
• Remove A from PriorityQueue and process unvisited neighbors of A to PriorityQueue.

• PriorityQueue now contains {C, B, E, D}

C B E D
• Remove C from PriorityQueue and process unvisited neighbors of C to PriorityQueue.

• PriorityQueue now contains {B, H, E, D}

B H E D
• Remove B from PriorityQueue and process unvisited neighbors of B to PriorityQueue.

• PriorityQueue now contains {H, E, D, F, G}

H E D F G
• Remove H from PriorityQueue. Since our goal "I" is a neighbor of H, we return.
RECALL ROMANIA MAP EXAMPLE

What’s a proper heuristic that measures cheapest path from current node to goal node?
2. A* SEARCH
 It is a searching algorithm that is used to find the shortest path
between an initial and a final point.
 A* was initially designed as a graph traversal problem, to help
build a robot that can find its own course.
 It searches for shorter paths first, thus making it an optimal and
complete algorithm.
 An optimal algorithm will find the least cost outcome for a
problem, while a complete algorithm finds all the possible
outcomes of a problem.
2. A* SEARCH

Another aspect that makes A* so powerful is the use of weighted


graphs in its implementation. A weighted graph uses numbers to
represent the cost of taking each path or course of action. This
means that the algorithms can take the path with the least cost,
and find the best route in terms of distance and time.
2. A* SEARCH
 The A* algorithm is implemented in a similar way to Dijkstra’s algorithm.
Given a weighted graph with non-negative edge weights, to find the
lowest-cost path from a start node S to a goal node G, two lists are
used:
 An open list, implemented as a priority queue, which stores the next nodes
to be explored. Because this is a priority queue, the most promising
candidate node (the one with the lowest value from the evaluation function)
is always at the top. Initially, the only node in this list is the start node S.
 A closed list which stores the nodes that have already been evaluated.
When a node is in the closed list, it means that the lowest-cost path to that
node has been found.
Exploring S:

A is the current most promising path, so it is explored next:


Exploring D:
Exploring F:
Notice that the goal node G has been found.
However, it hasn’t been explored, so the
algorithm continues because there may be a
shorter path to G.
The node B has two entries in the open list: one
at a cost of 16 (child of S) and one at a cost of 18
(child of A). The one with the lowest cost is
explored next:
Exploring C:

The next node in the open list is again B.


However, because B has already been explored,
meaning a shortest path to B has been found, it
is not explored again and the algorithm
continues to the next candidate.
The next node to be explored is the goal
node G, meaning the shortest path to G has
been found! The path is constructed by tracing
the graph backward from G to S:
2. A* SEARCH
❑ Most widely-known form of best-first 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) (estimated cost of cheapest solution through n).
❑ A reasonable strategy: try node with the lowest g(n) +

h(n) value!
❑ Provided heuristic meets some basic conditions, A* is

both complete and optimal.


Romania Map Problem Setup
• The goal is to find the shortest path from the city of Arad to
Bucharest. The cities are connected by roads with specific distances
between them (these distances represent the cost). The problem
provides us with:
• A map of Romania with various cities (nodes) connected by roads
(edges).
• The actual distances between cities, representing the cost.
• A heuristic estimate, which could be the straight-line (Euclidean)
distance between cities and the goal city, Bucharest.
1. Cost (g(n)) in the Romania Map
• The cost represents the actual distances between cities on the map. For instance:The cost
from Arad to Sibiu is 140 km.
• The cost from Sibiu to Rimnicu Vilcea is 80 km.
• These values come from the problem definition and represent the real distances you would
travel on the roads between cities.
2. Heuristic (h(n)) in the Romania Map
• The heuristic is an estimated distance from a city to the goal (Bucharest). This is typically a
straight-line distance that might not consider the actual roads but gives an approximation
of how far a city is from Bucharest as the crow flies.
• For example, the heuristic values (straight-line distances to Bucharest) for some cities:
• Arad: 366 km (this is not the actual road distance but an estimate).
• Sibiu: 253 km.
• Rimnicu Vilcea: 193 km.
• Fagaras: 178 km.
A* combines both the cost (g(n)) and the heuristic (h(n)) to
decide which path to explore. It tries to minimize the total cost:
f(n)=g(n)+h(n)
•g(n) is the total actual distance traveled so far (the accumulated
cost from Arad to the current city).
•h(n) is the estimated distance from the current city to
Bucharest.
ROMANIA MAP WITH COSTS
A* SEARCH EXAMPLE

f(n)=g(n)+h(n)
EXERCISE

❑ Use A* graph-search to generate a


path from Lugoj to Bucharest using
the straight- line distance heuristic.

You might also like