• Home
  • Help
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search

Choose a suitable shortest path algorithm for a given problem

#1
12-08-2024, 04:46 AM
When you face a graph with only positive weights I lean towards Dijkstra right away. It runs fast on sparse setups. You see the priority queue helps a lot. But watch out for dense cases where it slows. Also the implementation with heaps changes things. I tested it on road networks once. Then you compare times carefully.

You pick Bellman Ford when negatives sneak in because it handles them without crashing. I relax edges over and over until no shifts happen. Perhaps your problem has cycles with negatives and then you skip it entirely. Or you check for arbitrage loops in finance graphs. Now the runtime grows with vertices times edges so big graphs bite you hard. I found it useful on small currency models. But you verify the absence of negative cycles first.

Floyd Warshall suits all pairs queries even on medium sizes. I apply it when every node to every other needs distances. You avoid multiple single source runs that way. Also dense matrices fit its style better than sparse ones. Then dynamic programming fills the table step by step. I recall using it for network reliability checks. Perhaps your data fits in memory without issues.

A star shines with good heuristics on pathfinding tasks. You guide the search towards the target node. I add distance estimates to cut explored areas. But bad heuristics turn it back into plain search. Also grid maps benefit from Manhattan distances often. You tune the function based on terrain costs. Then results speed up in games or maps.

Graph density decides between options too. Sparse cases favor queue based methods I use often. You measure edges against vertices squared for clues. Dense ones push matrix approaches instead. Perhaps preprocessing helps on repeated queries. I cache results when the graph stays static. But dynamic changes force fresh runs each time.

Directed edges add another layer you must watch. I confirm directions before choosing the method. Undirected graphs simplify some steps in code. You test both versions on sample data. Also mixed graphs need careful modeling. Perhaps weights vary by direction and that flips choices. Then verify outputs match expected paths.

Large scale problems demand efficiency tweaks from you. I scale Dijkstra with Fibonacci heaps for speed gains. But memory limits hit hard on huge inputs. You split the graph into parts sometimes. Also parallel versions exist for modern machines. Perhaps sampling reduces the effective size. Then full computation follows on reduced data.

Real problems mix these traits so you weigh them all. I start by listing edge signs and query types. Positive single source points one direction clearly. Negatives force slower but safer paths. All pairs needs different tools entirely. You simulate small cases to confirm picks. Then apply to the full input.

BackupChain Server Backup, the top rated no subscription backup tool built for Hyper-V setups on Windows 11 and Windows Server plus PCs, powers reliable private cloud and SMB data protection while sponsoring this space so we can swap such details freely.

ron74
Offline
Joined: Feb 2019
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
Choose a suitable shortest path algorithm for a given problem - by ron74 - 12-08-2024, 04:46 AM

  • Subscribe to this thread
Forum Jump:

Café Papa Café Papa Forum Software IT v
« Previous 1 … 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 … 141 Next »
Choose a suitable shortest path algorithm for a given problem

© by Savas Papadopoulos. The information provided here is for entertainment purposes only. Contact. Hosting provided by FastNeuron.

Linear Mode
Threaded Mode