Why the Dijkstra algorithm does not apply to cases where the edge length is negative

Source: Internet
Author: User

Original address: http://lixing123.com/?p=280

Dijkstra algorithm (This Dutch word is really hard to read ...) But Dijkstra is a very NB computer scientist, goto harmful theory, signal volume and PV primitive, philosopher dinner problem, banker algorithm, etc., is this Daniel made out, is the forward/non-weighted graph (that is, each side has a length), the calculation of the shortest distance between two points of the effective method, In the case of heap sequencing, its time complexity is O (Nlog (n+m)), (where N represents the number of nodes, M represents the number of edges) is very close to linear, or very good.

However, the Dijkstra algorithm has one limitation, which is that it only applies to graphs with a negative edge length. If there is a negative long side length in a picture, then the Dijkstra algorithm does not apply. Another algorithm is needed at this time.

Why doesn't it work? In fact, it is easy to find counter-examples. Suppose a weighted graph, some side length is negative. Assuming that the minimum side length is-10, we add all the side length to 10, so we can get a non-negative weighted graph. At this time, the shortest path from node s to Node T is calculated by Dijkstra algorithm l,l Total N, the total length is t; So for the original, each edge is subtracted by 10, so the length of L in the original is t-10*n. This is the result calculated by the Diskstra algorithm.

So the question is: for the figure after adding 10, suppose there is a path m from S to T, the length is T1, it consists of N1, which is more than the edge of L, then after the restoration, each side needs to subtract 10, then the total length of M is t1-10*n1. So, is the total length of m necessarily longer than the total length of l? Not necessarily. If n1>n, that is to say, M is more than the number of sides of L, then M minus more than L minus, then t1-10*n1<t-10*n is possible. At this point the Dijkstra algorithm is not established.

In addition, there is a more simple example: if a picture has a total length of a negative ring, then the Dijkstra algorithm may be along this ring has been around, around the end of time ...

In addition, if a picture has a negative side, but there is no total length of negative ring, at this time can be calculated with the Bellman-ford algorithm. Although it is slower than the Dijkstra, but people use a broader range ah.

Why the Dijkstra algorithm does not apply to cases where the edge length is negative

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.