Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What graph traversal algorithm should I use for this?

Tags:

algorithm

I need to traverse a directed graph in a certain way and I'm not sure the algorithm to use. Perhaps Stackoverflow can help.

The situation - I have a directed graph where the edges have a number associated with them. Let's assume this number is a distance measured in feet, miles, ..., whatever. I'd like to traverse from a start node and find all edges that are some defined distance from the start node

For example, I want to start at some node and traverse the graph and find every edge where I've traveled 100 miles from the start. For example(2), start_node ---- edge-1(80 miles) ---> node(2) ---- edge-2(40 miles) ---> node(3) ---edge-3(50 miles) --- start_node ---- edge-4(40 miles) ---> node(4) ---- edge-5(70 miles) ---> node(5) ---edge-6(50 miles) ---

Starting at start_node and traveling 100 miles the answer would be edge-2, edge-5. Any thoughts on what traversal algorithm I should be using/considering?

Thanks

like image 774
BobL Avatar asked Mar 16 '26 14:03

BobL


1 Answers

I would choose Dijkstra algorithm. Just stop when the path to the last marked node is more than defined.

like image 140
Vitalii Fedorenko Avatar answered Mar 18 '26 06:03

Vitalii Fedorenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!