Greedy Best-First maze algorithm
Greedy Best-First Search always moves to the cell that looks closest to the exit, ignoring how far it has already come.
How it works
It's A* without the g: cells are ranked only by the estimated distance to the exit (Manhattan distance). The search dives straight at the goal and only spreads out when walls stop it.
On open ground that's very fast, and in a maze it often reaches the exit after exploring the fewest cells of any solver here. But it doesn't guarantee the shortest path, and a dead end that points at the exit can lure it a long way in.
What to watch for
Watch it lunge straight at the bottom-right corner, bounce off walls, and sometimes get pulled deep into a dead end that looked promising.
Properties
- Shortest path
- No
- Finds the exit
- Always, in a finite maze
- Explores
- Often the fewest cells
- Memory
- Priority queue
Race it
Pick it in the race and see who reaches the exit first, or run it in the studio.
FAQ
Why isn't Greedy Best-First's path the shortest?
It never considers how long the path so far is, only how close each cell looks to the exit.
Greedy or A*?
Greedy usually explores fewer cells; A* guarantees the shortest path.