Introduction to Freud's algorithm
Like the Dijkstra algorithm, the Freud (Floyd) algorithm is an algorithm for finding the shortest path between vertices in a given weighted graph. The algorithm is named after one of the founders, the 1978 Turing Prize winner, and Professor Robert Floyd of the Stanford University computer Science department.
Basic ideas
by Floyd calculating the shortest path of each vertex in g= (v,e), we need to introduce a matrix s, the element a[i][j in matrix S] to represent the distance between vertex I (vertex) and Vertex J (J Vertex).
Assuming that the number of vertices in graph G is n, you need to update the Matrix S n times. At the beginning, the distance of the vertex a[i][j] in the matrix S is the weight of vertex i to vertex j, and if I and J are not adjacent, then a[i][j]=∞. The next step is to update the Matrix S n times. On the 1th update, if the distance of "a[i][j" > "A[i][0]+a[0][j]" (A[i][0]+a[0][j] means "distance from the 1th vertex between I and J"), update a[i][j] to "a[i][0]+a[0][j". Similarly, when the K update, if the "a[i][j] distance" > "a[i][k]+a[k][j]", then update a[i][j] to "a[i][k]+a[k][j." After the update n times, the operation is complete!
Simply looking at the above theory may be more difficult to understand, the following examples to illustrate the algorithm.
Diagram of Freud's algorithm
The above figure G4 is an example to illustrate the algorithm of Freud.
Initial state : S is the matrix that records the shortest path between each vertex.
1th Step : Initialize S.
The distance of the vertex a[i][j] in the matrix S is the weighted value of vertex i to vertex j; If I and J are not adjacent, then a[i][j]=∞. In fact, the original matrix of the graph is copied into S.
Note: A[i][j] represents the distance between vertex i (vertex i) and Vertex J (j Vertex) in matrix S.