Http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html
The above links explained in more detail, below is my own understanding
Dijkstra algorithm
1. Definition
The Dijkstra (Dijkstra) algorithm is a typical single-source shortest path algorithm that calculates the shortest path of a node to all other nodes. That is, from one vertex to the outer layer, to the end, this process also obtains the shortest path (distance) from this vertex to any other point. ( this algorithm requires that no negative weights exist in the graph. )
The weight is the distance
2. Algorithm description
1) Algorithm idea:
Set g= (v,e) is a weighted graph, the figure of the vertex set V into two groups, the first set of the shortest path has been found in the vertex set S(s for sure in the initial s only one source point, each subsequent to find a shortest path, the vertex is added to the set S, Until all vertices are added to s, the algorithm ends, and the second set is the vertex set of the remaining indeterminate shortest paths U (U for unsure).
At the beginning, all the remaining vertex weights are ∞ except v0=0. Starting with the newly added vertex vin S (v0 first), traverse the vertex with V edge in U, and add the least - weighted (shortest) vertex v ' min to S to v ' min as an intermediate point, fixed with V ' The weighted value of vertices with edges (v-->v ' min-->v ' is less than v-->v ', if greater than without modification), until the vertices in U are all added to S.
2) Algorithm steps
A. Initially, S contains only the source point, that is, the weight of the s={v0},v0 is 0. U contains vertices other than v0, that is: u={remaining vertices}, the weights of the remaining vertices are ∞
B. From the newly added vertex vin S ( initially v0), select a minimum distance v ' minfrom u to add V ' min to s (the selected distance is v to V ' The shortest path length).
C. With V ' min as the new considered midpoint, modify the weights of each vertex in U; if v-->v ' min-->v ' is less than v-->v ', if it is greater then do not modify it ( if it is ∞ is obviously to be modified )
D. Repeat steps b and c until all vertices are contained in S.
Perform an animation process such as
Algorithm time complexity of O (N2)
3. Algorithm code implementation:
----------------------------------------Add----------------------------------------later
Floyd algorithm
1. Definition
The Floyd-warshall algorithm (Floyd-warshall algorithm) is an algorithm to solve the shortest path between any two points, which can correctly handle the shortest path problem with the direction graph or the negative weight, and is also used to calculate the transitive closure of the graph. The time complexity of the floyd-warshall algorithm is O (N3), and the space complexity is O (N2).
To find the shortest path for all vertices to all vertices
2. Algorithm description
1) Algorithm idea
The Floyd algorithm is a classical dynamic programming algorithm . In plain language, the first goal is to find the shortest path from point I to J. From the point of view of dynamic planning, we need to make a reinterpretation of this goal (this interpretation is the essence of dynamic planning the most creative)
The shortest path from any node I to any node J is 2 possible, and 1 is straight from I to j,2 from I through several nodes K to J. Therefore, we assume that dis (i,j) is the distance from the shortest path of node u to node V, for each node K, we check whether dis (i,k) + dis (k,j) < dis (I,J) is set up, and if so, Proving that the path from I to K to J is shorter than I directly to the path of J, we set dis (i,j) = Dis (i,k) + dis (k,j)so that when we traverse through all nodes K,dis (i,j) The distance from the shortest path of I to J is recorded.
2) Algorithm Description:
A. Start with any one-sided path. The distance between all two points is the right of the edge, and if no edge is connected between the two points, then the right is infinity.
B. For each pair of vertices u and V, see if there is a vertex w so that the path from u to W to V is shorter than known. If it is updated.
------------------to Be Continued----------------------
Shortest path-dijkstra algorithm and Floyd algorithm