Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 726727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:29:06+00:00 2026-05-14T06:29:06+00:00

Single Source shortest Path Dijkstra’s – directed and undirected – works only for positive

  • 0
Single Source shortest Path

Dijkstra’s – directed and undirected – works only for positive edge weights – cycles ??

Bellman Ford – directed – no cycles should exist

All source shortest path

Floyd Warshall – no info

Minimum Spanning Tree 

( no info about edge weights or nature of graph or cycles)

Kruskal’s

Prim’s – undirected

Baruvka’s

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:29:06+00:00Added an answer on May 14, 2026 at 6:29 am

    I’m not sure what the question is but here goes…

    The classic implementation of Dijkstra’s algorithm can only handle positive edge weights, but there is a way to make it work with negative edge costs. Whenever you update a node, put the updated node back in the queue. However, it’s arguable whether this is really Dijkstra or a Bellman-Ford with a priority queue.

    For example consider this graph:

    1 – 2 (100)
    2 – 3 (-200)
    1 – 3 (50)
    3 – 4 (100)

    Classical Dijkstra would set D[1] = 0, D[2] = 100, D[3] = 50, D[4] = 150, D[3] = -100 and stop. However, when setting D[3] = -100, add 3 back into the queue and continue the algorithm. That will give D[4] = 0, which is correct. I’m not sure if this is considered “Dijkstra’s algorithm” however.

    As for Bellman-Ford, the graph doesn’t necessarily have to be directed, and (negative cost cycles, other cycles make no difference anyway) cycles can exist, just make sure that you detect the cycles. A cycle is detected when you extract a node from the queue n times, where n is the number of nodes. You can do the same check to detect a cycle in the “modified Dijkstra’s algorithm” I outlined above.

    Floyd Warshall – the cost is cubic in the number of nodes. Inefficient for anything but very small graphs. It assumes there are no negative cost cycles, but you can use it to detect such cycles, see wikipedia.

    MST – use Kruskal’s when the number of edges is closer to O(n) than O(n2). Use Prim’s otherwise. Both will work on any kind of graphs, even if they contains negative edge weights and cycles.

    Another shortest paths algorithm I personally like a lot is Dial’s algorithm. I like to think of it like counting sort on graphs. Also read this rather exhaustive paper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Both can be used to find the shortest path from single source. BFS runs
Hey i have been studying the bellman ford algorithm for single source shortest path
I use Mercurial/TortoiseHg as my source control. So far I have a single app
Either I'm not, or it isn't working... I have a single Source class that
I've got a functional fullCalendar http://arshaw.com/fullcalendar/ working retrieving a single source from Google Calendar
I had a single source file which had all the class definitions and functions.
I heard from more than a single source that SVG is dying, it is
What OSS (or free) tools are available for drafting a single source for documentation
I'm trying to single source a form page which can be in edit mode
I am trying to understand why Dijkstra's algorithm will not work with negative weights.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.