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

Navigating The Frontier:: Exploration of The A Search Algorithm

The document discusses the A* search algorithm, including its definition, pseudocode, graphical explanation of the process, discussion of heuristics like Manhattan distance and time/space complexity. It also briefly covers real-life applications and comparisons to other algorithms.

Uploaded by

Lê hoàng minh
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)
6 views

Navigating The Frontier:: Exploration of The A Search Algorithm

The document discusses the A* search algorithm, including its definition, pseudocode, graphical explanation of the process, discussion of heuristics like Manhattan distance and time/space complexity. It also briefly covers real-life applications and comparisons to other algorithms.

Uploaded by

Lê hoàng minh
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/ 32

Navigating the Frontier:

Exploration of the
A* Search
Algorithm
DATA STRUCTURE AND ALGORITHM - Group 4
TABLE OF CONTENT
01 Problem

02 A* search algorithm

03 Real-life application

04 Comparison with other algorithms


I. PROBLEM
I. PROBLEM
Imagine a map as a web of
connections, where cities are
represented by nodes and roads are
lines. You are in the start node, and you
want to go to the target node. So which
way is the fastest way?
II. A* ALGORITHM
II. A* ALGORITHM
1. Definitions:
First invented by Peter Hart,
Nils Nilsson, and Bertram Raphael in
1968, A* (A-star) is a graph traversal and
pathfinding algorithm. It finds the
shortest path (with respect to the given
weights) from source to goal.
A* was invented by researchers
working on Shakey the Robot's path
planning.
II. A* ALGORITHM
At each step it picks the node having the lowest f(n), and processes that node/cell. We define
g(n) and h(n) as simply as possible below:
II. A* ALGORITHM
2. Pseudocode:
# initialize a min Heap contains the start node
minHeap = MinHeap([start])While minHeap is not empty:
# grab the minimum f-value node from minHeap and denote as current
current = minHeap.pop() # check if current is the target node
if current == target:
break

# populate all current node's neighbors


for neighbor in current.neighbors:
compute neighbor's g, h, f value

if neighbor in minHeap:
if neighbor.g < neighbor.g in minHeap:
update minHeap
else:
insert neighbor into minHeap
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
Step 1:
• a: Set the distance to the start node itself to 0 and the distance to all other nodes to
infinity.
• b: Calculate the f value for the start node and set the previous node to none/nil/null.
• c: Initialize an open list and close list which are empty initially.
Step 2: Place the start node into the open list
Step 3:
• a: Find the node with the minimum f-value in the open list and removed from the
list. Denote this node as the current node.
• b: Check if the current node is the target node or not
• c: Populate all the current node’s neighboring nodes and do following checks for
each neighboring nodes
• d: Place the current node to the close list because we have expanded this node.
Step 4: Repeat Step 3 until reaches the target node
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:

Repeat Step 3 until reaches


Step 4:
the target node
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
3. Graphical explanation:
II. A* ALGORITHM
4. Heuristics:
a. Manhattan Distance
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)
II. A* ALGORITHM
4. Heuristics:
b. Diagonal Distance
dx = abs(current_cell.x – goal.x)
dy = abs(current_cell.y – goal.y)

h = D * (dx + dy) + (D2 - 2 * D) * min(dx, dy)

where D is length of each node(usually = 1) and D2 is


diagonal distance between each node (usually = sqrt(2) ).

·When to use this heuristic? – When we are


allowed to move in eight directions only (similar to
a move of a King in Chess)
II. A* ALGORITHM
4. Heuristics:
c. Euclidean Distance
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.
II. A* ALGORITHM
5. Time Complexity
Considering a graph, it may take us to travel all the edge to reach the
destination cell from the source cell. The worst case time complexity is O(E),
where E is the number of edges in the graph.

6. Auxiliary Space
In the worst case, we can have all the edges inside the open list, so the
required auxiliary space in the worst case is O(V), where V is the total number of
vertices/nodes.
III. REAL-LIFE
APPLICATION
III. REAL-LIFE APPLICATION
Start

End
IV. COMPARE WITH
ANOTHER ALGORITHM
IV. COMPARE WITH
ANOTHER ALGORITHM

You might also like