Primm algorithm, Kruskal algorithm, Dijkstra algorithm, Floride algorithm

Source: Internet
Author: User

The course design of data structure by the way, I summarize the four algorithms, I small white students a ,

If there is anything wrong with the summary, I hope to be able to tell

Primm Algorithm Prim

Find the shortest side, and then the whole of this edge to look for adjacent edges, until all vertices are connected, generate the smallest spanning tree, time complexity O (n2)

Kruskal algorithm Kruskal

Kruskal algorithm, assuming the connected network n= (N,{e}), the initial state of the smallest spanning tree is a non-connected graph t= (v,{}) with only N vertices, and each vertex in the graph

into a connected component. Select the lowest-cost edge in E, and if the fixed vertex of the edge falls on a different connected component in T, the edge is added to T, otherwise the community sub-Edge chooses

The next lowest-cost edge. And so on, until all the vertices in T are on the same connected component

Dijkstra algorithm Dijkstra

Dijkstra algorithm and Primm algorithm have similar places but there are also differences, are greedy algorithm, but the PRIMM algorithm source point is arbitrary

The source points of the Dijkstra algorithm are specific, and they all divide the vertices into two sets

Floride algorithm Floyd

Time complexity: O (n^3);

Algorithm processEdit1, starting from 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. 2, for each pair of vertices u and V, see if there is a vertex w to make the path from u to W to v shorter than known. If it is updated. The graph is represented by the adjacency matrix G, and if there is a way from VI to VJ, then g[i,j]=d,d represents the length of the road; otherwise g[i,j]= Infinity. Defines a matrix D used to record the information of the insertion point, d[i,j] represents the point from VI to VJ, and initializes the d[i,j]=j. Insert each vertex into the graph, comparing the distance from the insertion point to the original distance, g[i,j] = min (G[i,j], g[i,k]+g[k,j]), or d[i,j]=k if the value of g[i,j] becomes smaller. Contains information about the shortest path between two points in G, while in D contains information for the shortest pass path. For example, find the path from V5 to V1. According to D, if D (5,1) =3 is indicated from V5 to V1 through V3, the path is {V5,V3,V1}, if D (5,3) = 3, the V5 is directly connected to the V3, if D (3,1) = 1, the V3 is directly connected to the V1.

The Floride algorithm is the shortest path between two vertices in a weighted graph, and the Dijkstra algorithm is the distance between one vertex and all fixed points.

Floyd algorithm, also known as Freud algorithm, interpolation method, is a method for finding the shortest path between vertices in a given weighted graph.
Algorithm process: 1, starting from any one-sided path. The distance between all two points is the right of the edge, or infinity, if no edge is connected between the two points.
2, 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.
The Dijkstra (Dijkstra) algorithm is a typical single-source shortest path algorithm that calculates the shortest path of a node to all other nodes. The main feature is to extend from the center of the starting point to the outer layer until it expands to the end point.
 
The algorithm steps are as follows:
1. The distance value corresponding to the vertices in the remaining vertex},t at the beginning of the season s={v0},t={
If present, D (V0,VI) is the weighted value on the arc
If not present, D (V0,VI) is ∝
2. Select a vertex w with a minimum distance value from T and not in S, join S
3. Modify the distance value of the vertex in T: If you add a W as the middle vertex, from V0 to VI
The distance value is shorter than the path without W, the distance value is modified
Repeat steps 2 and 3 above until all vertices are included in s, i.e. s=t

Primm algorithm, Kruskal algorithm, Dijkstra algorithm, Floride algorithm

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.