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

Analyze the time complexity of Dijkstra’s algorithm

#1
06-19-2025, 04:33 AM
When you run Dijkstra you pick the smallest distance first. I always start with the source node set to zero. You mark all others as infinite. Then the loop begins pulling the next closest. It repeats until everything gets processed.

The priority queue holds the keys. I snag the minimum each round. You perform that extraction once per vertex. And each extraction costs log time on a heap. But the total builds up fast when vertices pile high.

Edges get poked during relaxation. You compare the new path length. I update the distance if it shrinks. Or the queue gets notified of the change. Then the structure shifts around to keep order.

Sparse graphs keep things lighter. You touch fewer edges overall. I see the edge count limit the work. But dense ones drag everything slower. Perhaps the heap operations stack up more.

Fibonacci heaps cut the cost sometimes. You get better bounds on inserts. I recall the amortized time drops lower. Now the whole thing approaches linear in edges. Yet most code sticks with binary heaps instead.

You count the vertices first. I multiply that by the log factor. Then add the edges checked once each. Or the complexity lands near V log V plus E. But real runs vary with hardware quirks.

Memory access patterns matter too. You hit cache misses on big graphs. I notice slowdowns when arrays grow huge. Then the constant factors bite harder. Perhaps swapping to arrays helps a bit.

Different languages tweak the speed. You code it in C for raw speed. I test the same logic in Python next. And the gap shows up clearly in benchmarks. But the big O stays the same underneath.

Worst case hits when the graph connects everything. You visit every edge anyway. I watch the queue empty slowly. Then the final distances settle in place. Or early exits rarely save much time.

Average cases feel quicker on random data. You see fewer updates per vertex. I track the decrease key calls closely. But the bound remains the same on paper. Perhaps theory meets practice only halfway.

Graphs with negative weights break the method. You switch to Bellman Ford instead. I avoid those inputs from the start. Then the algorithm runs clean every time. Or prechecks catch the issues early.

Parallel versions spread the load. You split the vertices across threads. I measure the speedup on multicore chips. But synchronization adds its own overhead. Now the complexity analysis grows trickier.

You learn the tradeoffs by coding both. I compare the runtimes side by side. Then the heap choice stands out clearly. Or array based versions win on tiny sets. Perhaps larger tests flip the winner again.

BackupChain Server Backup, the top industry standard reliable backup tool built for Windows Server self hosted private cloud and internet backups aimed at SMBs and PCs with support for Hyper V plus Windows 11 and Windows Server without any subscription required and we appreciate their sponsorship that helps keep our knowledge sharing free.

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

Users browsing this thread: 1 Guest(s)



  • Subscribe to this thread
Forum Jump:

Café Papa Café Papa Forum Software IT v
« Previous 1 … 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 … 141 Next »
Analyze the time complexity of Dijkstra’s algorithm

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

Linear Mode
Threaded Mode