Dijkstra algorithm for searching the right graph to find the shortest distance of two points in the graph

Source: Internet
Author: User

The Dijkstra algorithm, which is used to search the right graph, finds the shortest distance of two points in the graph, neither DFS search nor BFS search.
The Dijkstra algorithm is applied to the graph with no power graph, or all sides have equal weights, and the Dijkstra algorithm is equivalent to BFS search.

Http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html

2. Algorithm description
1) Algorithm idea: Set g= (V,e) is a weighted to the graph, the figure of the vertex set V into two groups, the first set of the shortest path of the vertex set (s), the initial s only one source point, each subsequent to a shortest path, will be added to the set S, until all the vertices are added to the S, The algorithm ends, and the second set is the vertex set (denoted by u) of the remaining indeterminate shortest paths, and the second set of vertices is added to s in order of ascending shortest path length. During the join process, the shortest path length that is always maintained from the source Point V to the vertices in S is not longer than the shortest path length from the source point V to any vertex in U. In addition, each vertex corresponds to a distance, the distance from the vertex in S is the shortest path length from V to the vertex, and the distance from the vertex in U is the current shortest path length from V to the vertex that includes only the vertex in S as the middle vertex.

Example

Do not look at the algorithm animation, the time to understand the algorithm, thinking less than the speed of the GIF animation, these two graphs for understanding the algorithm most useful
The emphasis needs to be understood by the phrase "to add the vertices of the second group to s in ascending order of shortest path length." In the process of joining, the shortest path length that always remains from the source Point V to the vertices in S is not longer than the shortest path length from the source point V to any vertex in U "

in fact, the Dijkstra algorithm is a sort process , in the above example, according to a to the remaining points in the diagram of the shortest path length of the order, the shorter the path is found, the longer the path to be found, to find the shortest path A to F, we found in turn
Shortest path to a–> C 3
A–> Shortest path to c–> B 5
A–> Shortest path to c–> D 6
A–> Shortest Path to c–> E 7
a–> c–> d–> F Shortest Path 9
The additional effect of the Dijkstra algorithm operation is to get another message, a to C path is the shortest, followed by A to B, a to D, a to E, a to F

Why does the Dijkstra algorithm not apply to graphs with negative weights?
In the last example, when a point is selected into the set S, it means that the shortest path from a to this point has been found, such as the second step, the C point is selected into the set S, the shortest path of a to C has been found, but if there is a negative right side, you can not say so. For example, suppose there is a point z,z is only connected to a and C, the right from A to Z is 50, the right from Z to C is-49, and now the shortest path from a to C is obviously a–> z–> C

For graphs with negative weights, the Floyd algorithm should be used

http://blog.csdn.net/mu399/article/details/50903876

Dijkstra algorithm for searching the right graph to find the shortest distance of two points in the graph

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.