A* search

hip-hop, educational · 2:19

Listen on 93

Lyrics

[Verse 1]
Started with a problem, need to find the way
From the starting point to goal, what's the price to pay
Dijkstra's got us covered but he's moving slow
Every single neighbor gets explored, you know
But what if we could guide him with a crystal ball
Heuristic function showing us the optimal call
Manhattan distance, Euclidean too
Admissible estimates that always stay true

[Chorus]
A-star, A-star, f equals g plus h
Best first search with guidance, never second guess
G cost from the start, H cost to the goal
F score guides the way, that's how we take control
Open list, closed list, pick the smallest f
A-star, A-star, better than the rest

[Verse 2]
Initialize the open set with starting node
G cost zero, H from heuristic code
While the open set ain't empty, we continue on
Pick the node with smallest f, then it's gone
Move it to the closed set, mark it as explored
Check each neighbor carefully, see what's in store
If it's in the closed set, skip it, move along
If the path is shorter, update, make it strong

[Chorus]
A-star, A-star, f equals g plus h
Best first search with guidance, never second guess
G cost from the start, H cost to the goal
F score guides the way, that's how we take control
Open list, closed list, pick the smallest f
A-star, A-star, better than the rest

[Bridge]
Admissible heuristic, never overestimate
Consistent is better, monotonic all the way
Parent pointers tracking, reconstruct the path
When you reach the target, do the optimal math

[Verse 3]
Time complexity depends upon the heuristic choice
Perfect information gives algorithms a voice
Space complexity grows with the frontier size
But the paths we discover are the optimal prize
Greedy best first searches fast but might be wrong
Dijkstra finds optimal but takes way too long
A-star combines the best of both these worlds
Optimal and efficient, watch the magic unfurl

[Chorus]
A-star, A-star, f equals g plus h
Best first search with guidance, never second guess
G cost from the start, H cost to the goal
F score guides the way, that's how we take control
Open list, closed list, pick the smallest f
A-star, A-star, better than the rest

[Outro]
From pathfinding games to GPS navigation
A-star algorithm serves every application
Remember the formula, keep the heuristic tight
A-star finds the way through the algorithmic night

← Floyd-Warshall algorithm | Topological sort →