0% found this document useful (0 votes)
16 views7 pages

What Is A Search

The A* Search Algorithm is an efficient method for finding the shortest path in a graph by combining Dijkstra's Algorithm and Greedy Best-First Search, utilizing heuristics to estimate costs. It guarantees optimality when the heuristic is admissible, explores fewer paths than other methods, and is adaptable to various problems by changing the heuristic. A* is widely used in applications such as robotics navigation, GPS routing, and game pathfinding.

Uploaded by

utkarshm025
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)
16 views7 pages

What Is A Search

The A* Search Algorithm is an efficient method for finding the shortest path in a graph by combining Dijkstra's Algorithm and Greedy Best-First Search, utilizing heuristics to estimate costs. It guarantees optimality when the heuristic is admissible, explores fewer paths than other methods, and is adaptable to various problems by changing the heuristic. A* is widely used in applications such as robotics navigation, GPS routing, and game pathfinding.

Uploaded by

utkarshm025
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/ 7

What is A* Search Algorithm?

The A* (A-star) algorithm is a popular and powerful search algorithm used for
finding the shortest path from a starting node to a target node in a graph. It
combines features of Dijkstra's Algorithm and Greedy Best-First Search. The
key idea is to use a heuristic to estimate the cost from the current node to the
goal, thereby improving the efficiency of the search.

Why A* over other Algorithm


Optimality: A* is good at finding the shortest path from the start to the goal.
This is because it uses a special guess (called a heuristic) that never
overestimates the cost to get to the goal. As long as this guess is accurate, A*
will always find the shortest path if there is one.
example: If you have a good guess about how far B is from any point (like
knowing B is 10 miles away and never overestimating), A* will use this guess
to find the shortest route to B.

Efficiency: A* is faster than some other methods like Dijkstra's Algorithm. This
is because A* uses the heuristic to guess which paths might be better and
focuses on them. This means it often explores fewer paths than methods that
don’t use heuristics.
Example: If you were to check every possible route from A to B, it would take
a long time. A* uses your guess to only check the most promising routes first,
making it faster than checking everything blindly.

Flexibility: A* can be used in different situations by changing the heuristic


guess. This makes it useful for a variety of problems, not just one specific type.
Example: If you’re planning a route for a car, you might use one type of guess
(like shortest distance). If you’re planning a route for a delivery truck, you
might use a different guess (like avoiding roads with heavy traffic). A* can
handle both by adjusting the guess.

Heuristic Guidance: A* uses the heuristic to help decide which paths to


explore. It looks at paths that seem closer to the goal first, which helps it find
the solution more quickly compared to methods that don’t use any guessing.
Example: Imagine you can see a landmark near B from any point on the map.
A* uses this landmark to help choose the paths that get closer to it faster,
helping you reach B quicker than if you were just randomly exploring paths.

The heuristic value (often denoted as h(n)) in search algorithms, particularly in


A* search, is an estimate of the cost to reach the goal from a given node n.
Definitions:

 g(n): The cost from the start node to node n.


 h(n): The heuristic estimate of the cost from node n to the goal node.
 f(n) = g(n) + h(n): The total estimated cost of the cheapest path from the
start node to the goal node through n.

Steps:

1. Initialization:
o Create an open list (priority queue) of nodes to be evaluated. Start
with the initial node and add it to the open list.
o Create a closed list (set) of nodes that have been evaluated.
o Set the cost g(start) of the start node to 0.
o Calculate the initial f(start) using the heuristic function: f(start) =
g(start) + h(start).
2. Algorithm Execution:
o While the open list is not empty:
1. Select the node current with the lowest f value from the open
list and remove it.
2. If current is the goal node:
 Reconstruct the path from the start node to the goal
node by tracing back through the parent pointers of
the nodes.
 Return the path and stop.
3. Else, move current to the closed list.
4. For each neighbor of the current node:
 If the neighbor is in the closed list, skip it.
 Calculate the tentative g cost for the neighbor as:
tentative_g = g(current) + cost(current, neighbor).
 If the neighbor is not in the open list or the tentative_g
is lower than the previously recorded g cost:
 Update the neighbor’s g cost to tentative_g.
 Calculate the new f cost as: f(neighbor) =
g(neighbor) + h(neighbor).
 Set the parent of the neighbor to current (to
reconstruct the path later).
 If the neighbor is not in the open list, add it to
the open list.
3. Termination:
o If the open list becomes empty without finding the goal node, it
means there is no path from the start to the goal.

Example1:

A(4)
2 3

(2)B C(1)

3 1

(0)D
Heuristic Values:

 h(A) = 4 (estimated distance from A to D)


 h(B) = 2 (estimated distance from B to D)
 h(C) = 1 (estimated distance from C to D)
 h(D) = 0 (D is the goal, so no distance left)

Edge Costs (g):

 Cost from A to B: 2
 Cost from A to C: 3
 Cost from B to D: 3
 Cost from C to D: 1

A* Search Process:

1. Start at A:
o g(A) = 0 (cost to get to A from itself is 0).
o f(A) = g(A) + h(A) = 0 + 4 = 4.
2. Expand neighbors of A (B and C):
o For B:
 g(B) = 2 (cost from A to B).
 f(B) = g(B) + h(B) = 2 + 2 = 4.
o For C:
 g(C) = 3 (cost from A to C).
 f(C) = g(C) + h(C) = 3 + 1 = 4.
3. Choose a node with the lowest f(n). Since both B and C have the same f
= 4, let's pick B.
4. Expand neighbors of B (D):
o For D:
 g(D) = g(B) + cost(B to D) = 2 + 3 = 5.
 f(D) = g(D) + h(D) = 5 + 0 = 5.
5. Next, explore C:
o For D:
 g(D) = g(C) + cost(C to D) = 3 + 1 = 4.
 f(D) = g(D) + h(D) = 4 + 0 = 4.
6. Choose the path to D through C because f(D) = 4 is the lowest cost.

Thus, the path found by A* is A → C → D with a total cost of 4.

Example:

A(4)
1 2

(3)B C(2)

2 1 1

(2)D 2 E(0)

1. Nodes and Weights:


o A to B: 1
o A to C: 2
o B to D: 2
o C to D: 1
o C to E: 1
o D to E: 2
2. Heuristic Estimates (straight-line distances or estimated costs from each
node to E):
o h(A) = 4
o h(B) = 3
o h(C) = 2
o h(D) = 2
o h(E) = 0
3. Initial Costs:
o g(start) = 0 for node A.
o f(start) = g(A) + h(A) = 0 + 4 = 4.

Step-by-Step Execution

1. Initialization:
o Open List (Priority Queue): [A] with f(A) = 4
o Closed List: []
2. Step 1: Process Node A
o Remove A from the open list: current = A.
o Node A is not the goal, so we explore its neighbors (B and C).
o Neighbor B:
 Tentative g(B) = g(A) + cost(A, B) = 0 + 1 = 1
 f(B) = g(B) + h(B) = 1 + 3 = 4
 B is not in the open list. Add B with f(B) = 4.
o Neighbor C:
 Tentative g(C) = g(A) + cost(A, C) = 0 + 2 = 2
 f(C) = g(C) + h(C) = 2 + 2 = 4
 C is not in the open list. Add C with f(C) = 4.
o Move A to the closed list: [A].
o Open List: [B, C] (both with f values of 4).
3. Step 2: Process Node B
o Remove B from the open list: current = B.
o Node B is not the goal, so we explore its neighbor (D).
o Neighbor D:
 Tentative g(D) = g(B) + cost(B, D) = 1 + 2 = 3
 f(D) = g(D) + h(D) = 3 + 2 = 5
 D is not in the open list. Add D with f(D) = 5.
o Move B to the closed list: [A, B].
o Open List: [C, D] (C with f = 4, D with f = 5).
4. Step 3: Process Node C
o Remove C from the open list: current = C.
o Node C is not the goal, so we explore its neighbors (D and E).
o Neighbor D:
 Tentative g(D) = g(C) + cost(C, D) = 2 + 1 = 3
f(D) = g(D) + h(D) = 3 + 2 = 5

 D is already in the open list with f = 5. No update needed.
o Neighbor E:
 Tentative g(E) = g(C) + cost(C, E) = 2 + 1 = 3
 f(E) = g(E) + h(E) = 3 + 0 = 3
 E is not in the open list. Add E with f(E) = 3.
o Move C to the closed list: [A, B, C].
o Open List: [D, E] (E with f = 3, D with f = 5).
5. Step 4: Process Node E
o Remove E from the open list: current = E.
o Node E is the goal. Path found!
o Reconstruct Path:
 Backtrack from E to C to A.
 Path: A → C → E.
o Open List: [D] (irrelevant now as we have found the goal).

Path: A → C → E
Cost: g(E) = 3

Application of A* Search:
 Pathfinding in Games: Finds the shortest path for game characters or objects, ensuring
efficient movement around obstacles.

 Robotics Navigation: Helps robots autonomously navigate environments by finding


optimal paths while avoiding obstacles.

 GPS and Route Planning: Used in GPS systems to find the fastest or shortest driving
route between two locations.

 Puzzle Solving (AI): Solves puzzles like the 8-puzzle by finding the most efficient
sequence of moves to reach the goal state.

 Network Routing: Finds the shortest path for data packets to travel across complex
networks, optimizing communication.

 Air Traffic Control: Calculates optimal flight paths for aircraft while avoiding restricted
airspaces and potential hazards.

 Speech Recognition: Predicts the most likely sequence of phonemes to match spoken
words, improving speech-to-text accuracy.

 RTS Games: Moves multiple units across complex terrains efficiently while avoiding
enemy forces and obstacles.
 3D Animation Pathfinding: Helps animated characters move naturally in virtual 3D
environments by finding optimal paths.

 Urban Traffic Simulation: Simulates and optimizes traffic flow in cities, identifying the
best routes for vehicles and pedestrians.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy