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.

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.

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?

3 Answers
3

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.

amit, this is what I was talking about in my question. I think Longest Path problem is different from Single sourced Longest Path problem. In Longest Path problem, we need to find the single longest path in the whole graph. But in my question above, single sourced means we are given a vertex S, then find out which path is longest oriented from S. They are different problems, right?
–
Jackson TaleMay 5 '12 at 14:30

1

ah, ok, I think I made a mistake. If single sourced longest path problem can be solved, then we just for each vertex we do single-source longest path, then compare them all, then solve the longest path problem. This is not possible as the longest path problem is NP. ok, I guess what I thought wrong.
–
Jackson TaleMay 5 '12 at 14:33

can you please possibly use simplest words to describe why longest path problem can't be solved if I replace MIN with MAX in Dijkstra?
–
Jackson TaleMay 5 '12 at 14:35

1

@JacksonTale: The idea behind dijkstra's algorithm is doing local relaxation. Note that in dijkstra's algorithm, when a node with minimal distance is picked and removed from the list of nodes, it is OK, we will never need to modify it again, while for the max problem - it is not true.
–
amitMay 5 '12 at 14:43

1

@JacksonTale: I believe a modification exist, but I cannot think of it at the moment. As you already know however, I prefer reducing problems to existing algorithms instead of modifying algorithms. In this case, I'd create a new weight function w'(e) = -w(e), and invoke Bellman Ford with w'. Since the graph is a DAG, there are no cycles, and specifically no negative cycles, and BF will return the shortest path according to w', which is the longest path according to w! What do you think? Is that fits your problem as well?
–
amitMay 6 '12 at 14:53

But if you assume only negative weights, you can easily find the longest path. To prove correctness, just take absolute values of all weights and you get exactly the usual Dijkstra's algorithm with positive weights.

I think your answer is doing a trick. If I assume only negative weights, the longest path is like shortest path in all positive weights. I don't think it is what the excise is seeking for.
–
Jackson TaleMay 5 '12 at 15:01

@JacksonTale, yes, this is just a trick. But it's not clear from the excise text, what does it mean. Otherwise, amit's answer is very good.
–
Evgeny KluevMay 5 '12 at 15:05

Thanks for answering. I guess what the excise really mean is for the real longest path problem. My bad to add such an assumption.
–
Jackson TaleMay 5 '12 at 15:06