# How can the A* algorithm be optimized?

How can the A* algorithm be optimized?

Any references that shows the optimization of A* algorithm are also appreciated.

• What do you mean by "optimization of A star algorithm"? Do you mean optimized implementations? – nbro Apr 16 '19 at 13:19
• @nbro how can we optimize A* algorithm? what does this mean? – Lexi Apr 16 '19 at 13:27
• Are you asking the meaning of the sentence "how can we optimize A* algorithm?"? It likely means how you can change the standard A* algorithm to make it more efficient (either in terms of time or space complexity or in terms of practical time required to find the solution). – nbro Apr 16 '19 at 14:12
• @nbro yes.. can you answer that? – Lexi Apr 16 '19 at 14:23

## 2 Answers

Check below reference url for A* algorithms ... https://takinginitiative.wordpress.com/2011/05/02/optimizing-the-a-algorithm/ https://en.wikipedia.org/wiki/Heap_%28data_structure%29

• Hey, welcome to the site. Posts just linking to reference material are better suited as comments. – Philip Raeisghasem Apr 16 '19 at 16:08

The first step of optimisation is to measure where inside the implementation most time is spent -- you don't actually optimise the algorithm itself, but a specific implementation of it. This step should give you an overview of where you can make improvements. Speculative changes usually don't do much.

There are several aspects of A* which would be candidates. You are keeping a list of paths currently under investigation. If it is very long, processing might take more time. You could try and prune this list (though it might mean that you won't actually find the best path anymore). Or you could investigate efficient ways of storing it.

Each step you need to compute the 'cost' of each path. This could be cached to stop you from repeating calculations. The heuristic function could be slow -- again something to investigate.

Let me stress again that you need to measure the performance first. There is no point in randomly trying to make things faster; you could waste a lot of time for very little gain. And typically with optimisation, readability of the code suffers, and it becomes harder to maintain. You might find that other parts of your system take a lot longer than the actual path finding, so your time might better be spent on those.