0% found this document useful (0 votes)
4 views

Module 2 Lecture 5

The A* Search Algorithm is a popular pathfinding technique that approximates the shortest path in scenarios with obstacles, utilizing a heuristic to evaluate nodes based on movement costs. It combines actual costs (g) and estimated costs (h) to determine the most promising path, ensuring optimal solutions when a suitable heuristic is applied. However, its effectiveness is dependent on heuristic accuracy, and it may face challenges with memory usage and time complexity in large search spaces.

Uploaded by

Balamurali Gunji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Module 2 Lecture 5

The A* Search Algorithm is a popular pathfinding technique that approximates the shortest path in scenarios with obstacles, utilizing a heuristic to evaluate nodes based on movement costs. It combines actual costs (g) and estimated costs (h) to determine the most promising path, ensuring optimal solutions when a suitable heuristic is applied. However, its effectiveness is dependent on heuristic accuracy, and it may face challenges with memory usage and time complexity in large search spaces.

Uploaded by

Balamurali Gunji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

MODULE-2

LECTURE-5
A* Search Algorithm
To approximate the shortest path in real-life situations, like- in maps, games
Motivationwhere there can be many hindrances.

We can consider a 2D Grid having several obstacles and we start from a source
cell (colored red below) to reach towards a goal cell (colored green below)
What is A* Search Algorithm?

A* Search algorithm is one of the best and popular technique used in path-finding and
graph traversals.

Why A* Search Algorithm?

Informally speaking, A* Search algorithms, unlike other traversal techniques, it has


“brains”. What it means is that it is really a smart algorithm which separates it from the
other conventional algorithms. This fact is cleared in detail in below sections.

And it is also worth mentioning that many games and web-based maps use this algorithm
to find the shortest path very efficiently (approximation).
Explanation

Consider a square grid having many obstacles and we are given a starting cell and a target
cell. We want to reach the target cell (if possible) from the starting cell as quickly as
possible. Here A* Search Algorithm comes to the rescue.

What A* Search Algorithm does is that at each step it picks the node according to a
value-‘f’ which is a parameter equal to the sum of two other parameters – ‘g’ and ‘h’. At
each step it picks the node/cell having the lowest ‘f’, and process that node/cell.

We define ‘g’ and ‘h’ as simply as possible below

g = the movement cost to move from the starting point to a given square on the grid,
following the path generated to get there.

h = the estimated movement cost to move from that given square on the grid to the final
destination.

This is often referred to as the heuristic, which is nothing but a kind of smart guess. We
really don’t know the actual distance until we find the path, because all sorts of things can
be in the way (walls, water, etc.). There can be many ways to calculate this ‘h’ which are
discussed in the later sections.
The main idea of A* is to evaluate each node based on two parameters:

1.g(n): the actual cost to get from the initial node to node n. It represents the sum of the
costs of node n outgoing edges.

2.h(n): Heuristic cost (also known as "estimation cost") from node n to destination node n.
This problem-specific heuristic function must be acceptable, meaning it never
overestimates the actual cost of achieving the goal. The evaluation function of node n is
defined as f(n) = g(n)+h(n).
A* Algorithm extends the path that minimizes the following
function-
f(n) = g(n) + h(n)

Here,
•‘n’ is the last node on the path
•g(n) is the cost of the path from start node to node ‘n’
•h(n) is a heuristic function that estimates cost of the cheapest path from node
‘n’ to the goal node
Solution-
Consider the following graph
Step-01:

•We start with node A.


•Node B and Node F can be reached from node A.

A* Algorithm calculates f(B) and f(F).

•f(B) = 6 + 8 = 14
•f(F) = 3 + 6 = 9

Since f(F) < f(B), so it decides to go to node F.


Step-03:
Path- A → F
Node I can be reached from node G.
Step-02:

Node G and Node H can be reached from node F. A* Algorithm calculates f(I).
f(I) = (3+1+3) + 1 = 8
A* Algorithm calculates f(G) and f(H). It decides to go to node I.
•f(G) = (3+1) + 5 = 9
•f(H) = (3+7) + 3 = 13 Path- A → F → G → I
Step-04:
Since f(G) < f(H), so it decides to go to node G.
Node E, Node H and Node J can be reached from node I.
Path- A → F → G
A* Algorithm calculates f(E), f(H) and f(J).
•f(E) = (3+1+3+5) + 3 = 15
•f(H) = (3+1+3+2) + 3 = 12
•f(J) = (3+1+3+3) + 0 = 10

Since f(J) is least, so it decides to go to node J.

Path- A → F → G → I → J
This is the required shortest path from node A to node J.
It is important to note that-

•A* Algorithm is one of the best path finding


algorithms.

•But it does not produce the shortest path always.

•This is because it heavily depends on heuristics.


FINAL PATH IS REPRESENTED IN RED
COLOR
Example
Consider the following example of trying to find the shortest
path from S to G in the following graph:

Each edge has an associated weight, and each


node has a heuristic cost (in parentheses).
An open list is maintained in which the node S is
the only node in the list. The search tree can now
be constructed.

A is the current most promising path, so it is


explored next:
Exploring
D:

Exploring F:
SHORTEST PATH FOUND
Advantages of A* Search Algorithm in
Artificial Intelligence
The A* search algorithm offers several advantages in artificial intelligence and
problem-solving scenarios:
1.Optimal solution: A* ensures finding the optimal (shortest) path from the start node to
the destination node in the weighted graph given an acceptable heuristic function. This
optimality is a decisive advantage in many applications where finding the shortest path is
essential.
2.Completeness: If a solution exists, A* will find it, provided the graph does not have an
infinite cost This completeness property ensures that A* can take advantage of a solution if it
exists.
3.Efficiency: A* is efficient ifan efficient and acceptable heuristic function is used. Heuristics
guide the search to a goal by focusing on promising paths and avoiding unnecessary
exploration, making A* more efficient than non-aware search algorithms such as breadth-
first search or depth-first search.
4.Versatility: A* is widely applicable to variousproblem areas, including wayfinding, route
planning, robotics, game development, and more. A* can be used to find optimal solutions
efficiently as long as a meaningful heuristic can be defined.
5.Optimized search: A* maintains a priority order to select the nodes with the minor f(n)
value (g(n) and h(n)) for expansion. This allows it to explore promising paths first, which
reduces the search space and leads to faster convergence.
6.Memory efficiency: Unlike some other search algorithms, such as breadth-first search, A*
stores only a limited number of nodes in the priority queue, which makes it memory
1.Tunable Heuristics: A*'s performancecan be fine-tuned by selecting different
heuristic functions. More educated heuristics can lead to faster convergence and less
expanded nodes.

2.Extensively researched: A* is a well-established algorithm with decades of


research and practical applications. Many optimizations and variations have been
developed, making it a reliable and well-understood troubleshooting tool.

3.Web search: A* can be used for web-based path search, where the algorithm
constantly updates the path according to changes in the environment or the
appearance of new It enables real-time decision-making in dynamic scenarios.
Disadvantages of A* Search Algorithm in
Artificial Intelligence
Although the A* (letter A) search algorithm is a widely used and powerful technique for
solving AI pathfinding and graph traversal problems, it has disadvantages and
limitations. Here are some of the main disadvantages of the search algorithm:

1.Heuristic accuracy: The performance of the A* algorithm depends heavily on the


accuracy of the heuristic function used to estimate the cost from the current node to the
If the heuristic is unacceptable (never overestimates the actual cost) or inconsistent
(satisfies the triangle inequality), A* may not find an optimal path or may explore more
nodes than necessary, affecting its efficiency and accuracy.
2.Memory usage: A* requires that all visited nodes be kept in memory to keep track of
explored paths. Memory usage can sometimes become a significant issue, especially
when dealing with an ample search space or limited memory resources.
3.Time complexity: AlthoughA* is generally efficient, its time complexity can be a
concern for vast search spaces or graphs. In the worst case, A* can take exponentially
longer to find the optimal path if the heuristic is inappropriate for the problem.
4.Bottleneck at the destination: In specific scenarios, the A* algorithm needs to
explore nodes far from the destination before finally reaching the destination region. This
the problem occurs when the heuristic needs to direct the search to the goal early
effectively.
Applications of the A* Search Algorithm in
Artificial Intelligence
The search algorithm A* (letter A) is a widely used and robust pathfinding algorithm in
artificial intelligence and computer science. Its efficiency and optimality make it suitable for
various applications. Here are some typical applications of the A* search algorithm in
artificial intelligence:
1.Pathfinding in Games: A* is oftenused in video games for character movement,
enemy AI navigation, and finding the shortest path from one location to another on the
game map. Its ability to find the optimal path based on cost and heuristics makes it
ideal for real-time applications such as games.
2.Robotics and Autonomous Vehicles: A* is used in robotics and autonomous vehicle
navigation to plan anoptimal route for robots to reach a destination, avoiding obstacles
and considering terrain costs. This is crucial for efficient and safe movement in natural
environments.
3.Maze solving: A* can efficiently find the shortest path through a maze, making it
valuable in many maze-solving applications, such as solving puzzles or navigating
complex structures.
4.Route planningand navigation: In GPS systems and mapping applications, A* can
be used to find the optimal route between two points on a map, considering factors such
as distance, traffic conditions, and road network topology.
5.Puzzle-solving: A* can solve various diagram puzzles, such as sliding puzzles,
Sudoku, and the 8-puzzle problem. Resource Allocation: In scenarios where resources
must be optimally allocated, A* can help find the most efficient allocation path,
PARCTICE EXAMPLES
THANK YOU

You might also like