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 7885007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:57:04+00:00 2026-06-03T04:57:04+00:00

Ok, I posted this question because of this exercise: Can we modify Dijkstra’s algorithm

  • 0

Ok, I posted this question because of this exercise:

Can we modify Dijkstra’s algorithm to solve the single-source longest path problem by changing minimum to maximum? If so, then prove your algorithm correct. If not, then provide a counterexample.

For this exercise or all things related to Dijkstra’s algorithm, I assume there are no negative weights in the graph. Otherwise, it makes not much sense, as even for shortest path problem, Dijkstra can’t work properly if negative edge exists.


Ok, my intuition answered it for me:

Yes, I think it can be modified.

I just

  1. initialise distance array to MININT
  2. change distance[w] > distance[v]+weight to distance[w] < distance[v]+weight

Then I did some research to verify my answer. I found this post:

Longest path between from a source to certain nodes in a DAG

First I thought my answer was wrong because of the post above. But I found that maybe the answer in the post above is wrong. It mixed up The Single-Source Longest Path Problem with The Longest Path Problem.

Also in wiki of Bellman–Ford algorithm, it said correctly :

The Bellman–Ford algorithm computes single-source shortest paths in a weighted digraph. For graphs with only non-negative edge weights, the faster Dijkstra’s algorithm also solves the problem. Thus, Bellman–Ford is used primarily for graphs with negative edge weights.

So I think my answer is correct, right?
Dijkstra can really be The Single-Source Longest Path Problem and my modifications are also correct, right?

  • 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-03T04:57:05+00:00Added an answer on June 3, 2026 at 4:57 am

    No, we cannot1 – or at the very least, no polynomial reduction/modification is known – longest path problem is NP-Hard, while dijkstra runs in polynomial time!

    If we can find a modfication to dijsktra to answer longest-path problem in polynomial time, we can derive P=NP

    If not, then provide a counterexample.

    This is very bad task. The counter example can provide a specific modification is wrong, while there could be a different modification that is OK.

    The truth is we do not know if longest-path problem is solveable in polynomial time or not, but the general assumption is – it is not.


    regarding just changing the relaxation step:

            A
           / \
          1   2
         /     \
        B<--1---C
    edges are (A,B),(A,C),(C,B)
    

    dijkstra from A will first pick B, and then B is never reachable – because it is out of the set of distances.

    At the very least, one will have also to change min heap into max heap, but it will have a different counter-example why it fails.


    (1) probably, maybe if P=NP it is possible, but it is very unlikely.

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

Sidebar

Related Questions

I posted this question on Reddit Programming and did not get a single response.
I'm a JS beginner. I posted this question because I've been trying to find
I actually posted this question because I found similar questions but not a perfect
A few months ago I posted this question because I tried to follow all
Because there was an error in the code when I posted this question, it
I posted this question here on purpose, although - for my case - it
I posted this question on superuser a bit ago, but I haven't gotten an
I posted this question at ActiveState but got no reply from support or in
I posted this question on the IntelliJ community forums but it seems as if
I just posted this question and learned about <see cref=> , however when i

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.