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

  • Home
  • SEARCH
  • 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 8658401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:45:30+00:00 2026-06-12T15:45:30+00:00

Dijkstra’s Algorithm fails when in a graph we have edges with negative weights. However,

  • 0

Dijkstra’s Algorithm fails when in a graph we have edges with negative weights. However, to this rule there is an exception: If In a directed acyclic graph only the edges that leave the source node are negative (all the other edges are positive), then we can successfully use Dijkstra’s Algorithm.

Now my question is, what if in the above exception the graph has a cycle? I believe Dijkstra won’t work, but I cannot come up with an example of a directed graph that has cycles, and the only negative edges are those leaving the source node which does not work with Dijkstra. Anyone can suggest an example?

  • 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-06-12T15:45:31+00:00Added an answer on June 12, 2026 at 3:45 pm

    In the scenario you describe, Dijkstra’s algorithm will work just fine.

    The reason why it fails in the general case with negative weight since it greedily chooses which node to “close” at each step, and a closed node is never reopened.

    Now, assume the source s has k out edges, to k different nodes.

    Let the order of them be v_1, v_2, ..., v_k (v_1 being the smallest). Note that for each v_i, v_j such that i < j – there will be no path from s to v_i through v_j with a “better” cost then v_i, thus – the order of investigating these first nodes will never change. (and since it doesn’t change, no way a later node will be entered to “closed” before the shortest path is indeed found).

    Thus, at overall – no harm is done – once an edge is in the “closed” – you will never find a “shorter” path to it, since the negative edges are only from the source.


    In here I assume the source in your question means d_in(source)=0, same as a “source” in a DAG.

    If you mean out of the source vertex, it could be a problem since look at a 2 vertices graph such that w(s,t) = -2, w(t,s)=1 – there is a negative cycle in the graph. So, in order to the above explanation to work – you must assume d_in(s) = 0

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

Sidebar

Related Questions

I have set of nodes and edges and i used Dijkstra's algorithm to find
I need to implement Dijkstra's Algorithm in Python. However, I have to use a
Can we use Dijkstra's algorithm with negative weights? STOP! Before you think lol nub
I am trying to understand why Dijkstra's algorithm will not work with negative weights.
In a directed graph with non-negative edge weights I can easily find shortest path
I am using Dijkstra algorithm in a program. Suppose I have a graph with
Lets say I am writing Dijkstra's Algorithm , and I have a priority queue
This is the dijkstra structure i am using :(however the MAXV(which is maximum number
In Dijkstra's algorithm what should I do if there are two or more nodes
I am using Dijkstra algorithm in PHP. But I got this error Fatal error:

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.