A Algorithm: Presented By-Ishan Gupta Pratyush Awasthi Mohd. Shariq Siraj Aryan Rastogi
A Algorithm: Presented By-Ishan Gupta Pratyush Awasthi Mohd. Shariq Siraj Aryan Rastogi
Presented by-
Ishan Gupta
Pratyush Awasthi
Mohd. Shariq Siraj
Aryan Rastogi
WHAT IS A * ALGORITHM AND WHY A* ALGORITHM
• A* Search algorithm is one of the best and popular technique used in path-finding and graph traversals.
• 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).
EXPLANATIO
N
• // A* Search Algorithm
• 1. Initialize the open list
• 2. Initialize the closed list
• put the starting node on the open
• list (you can leave its f at zero)
• It is nothing but the sum of absolute values of differences in the goal’s x and y coordinates and the current cell’s x and y
coordinates respectively, i.e.,
•
• h = abs (current_cell.x – goal.x) + abs (current_cell.y – goal.y)
• When to use this heuristic? – When we are allowed to move only in four directions only (right, left, top, bottom)
• The Manhattan Distance Heuristics is shown by the below figure (assume red spot as source cell and green spot as target
cell).
• 2) Diagonal Distance-
• It is nothing but the maximum of absolute values of differences in the goal’s x and y coordinates and the current cell’s x
and y coordinates respectively, i.e.,
• h = max { abs(current_cell.x – goal.x), abs(current_cell.y – goal.y) }
• When to use this heuristic? – When we are allowed to move in eight directions only (similar to a move of a King in
Chess)
• The Diagonal Distance Heuristics is shown by the below figure (assume red spot as source cell and green spot as target
cell).
• 3) Euclidean Distance-
• As it is clear from its name, it is nothing but the distance between the current cell and the goal cell using the distance
formula
• h = sqrt ( (current_cell.x – goal.x)2 + (current_cell.y – goal.y)2 )
• When to use this heuristic? – When we are allowed to move in any directions.
• The Euclidean Distance Heuristics is shown by the below figure (assume red spot as source cell and green spot as target
cell).
• Although being the best pathfinding algorithm around, A* Search Algorithm doesn’t produce the shortest path always,
as it relies heavily on heuristics / approximations to calculate – h
APPLICATIONS
• This is the most interesting part of A* Search Algorithm. They are used in games! But how?
• Ever played Tower Defense Games ?
• Tower defense is a type of strategy video game where the goal is to defend a player’s territories or possessions by
obstructing enemy attackers, usually achieved by placing defensive structures on or along their path of attack.
• A* Search Algorithm is often used to find the shortest path from one point to another point. You can use this for each enemy
to find a path to the goal.
• One example of this is the very popular game- Warcraft III
TIME
COMPLEXITY
• Considering a graph, it may take us to travel all the edge to reach the destination cell from the source cell [For
example, consider a graph where source and destination nodes are connected by a series of edges, like – 0(source) –
>1 –> 2 –> 3 (target)
• So the worse case time complexity is O(E), where E is the number of edges in the graph
AUXILIARY SPACE
• In the worse case we can have all the edges inside the open list, so required auxiliary space in worst case is O(V),
where V is the total number of vertices.