-1

For a school project, my friends and I are learning what is pathfinding and how to exploit it via a simple exercise:

For a group of ants going from A to B, they need to travel through multiple nodes, one at a time.

I've read some explanation about Dijsktra's algoritm, and I wanted to know if I could use it in a graph where every distance between every node is 1 unit. Is it optimal ? Or is A* more appropriated to my case ?

EDIT:

Since I had knowledge on the graph, BFS was prefered because distance between node was pre-computed, where Djisktra is prefered when you have absolutely nothing about the graph itself. See this post for reference

4
  • 1
    "Is it optimal?" That is relative. We cannot answer that. But if you are learning, then Dijsktra is something that is easy to start with. Commented Apr 6, 2017 at 11:53
  • easy was the word, thanks for having my back. Commented Apr 6, 2017 at 12:21
  • 1
    Dijkstra is a special case of AStar. You can find an explanation on SO: stackoverflow.com/a/16268762/5847906 Commented Apr 6, 2017 at 12:29
  • 1
    This question might be better suited for ai.stackexchange.com or gamedev.stackexchange.com. Also there are plenty of similar questions already asked and there are plenty of online resources discussing these algorithms. Take a look at How to Ask and minimal reproducible example before you post a question a Stack Overflow, it's important to do some research yourself first. Commented Apr 6, 2017 at 12:33

1 Answer 1

2

If every edge has the same cost, then Dijkstra's algorithm is the same as a breadth-first search. In this case you might as well just implement BFS. It's easier.

If you have a way to estimate how far a point is from the target, then you could use A* instead. This will find the best path faster in most cases.

Sign up to request clarification or add additional context in comments.

1 Comment

DFS is not about shortest distance. You mean BFS, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.