In the A* search algorithm, we use a priority queue with heuristic function to find optimum result with minimum cost. But, how do we get the path after reaching goal?


Every node should have been given a pointer to the node it was reached from. Then you only need to follow and reverse a linked list.

  • $\begingroup$ So, I need to modify the priority queue. Okay, I'll give it a try. $\endgroup$ – Nightmare Sep 19 '13 at 12:19
  • $\begingroup$ @Nightmare, it's not the priority queue you are modifying; you add to each node a pointer to how you got there. Similarly techniques are used in, e.g., breadth-first search or depth-first search to reconstruct the paths. See your favorite algorithms textbook. $\endgroup$ – D.W. Sep 22 '13 at 6:30
  • $\begingroup$ Yes, I already know. I used simple array with sort function. I just modify array structure to record pointer, that's it. $\endgroup$ – Nightmare Sep 23 '13 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.