Summary of the data structure diagram and related algorithms

1. First we need to know the concept of FIG relevant, definitions and related terms, such as the degree of vertex, the degree of the first time, arc, directed and undirected complete graph complete graph, the path and the path length, simple path, loop communication, and communication components connected graph, strongly connected graph strongly connected component and, right, and network

① simple path: the sequence of unique apex path is called simple path

FIG communication ②: If any of the figures that are communicated between said two of the graph of FIG communication vertices

③ no connected components referred to maximal connected subgraph FIG.

④ strong graph: if there is in respect of each vertex of the graph there is a path that said strongly connected graph, where the maximum intensity strongly connected graph is called the sub-component in the drawing Unicom

2. FIG storage

There are three main ways: ① ② adjacency matrix of the adjacent table edge set ③

Two commonly used is the adjacency matrix and adjacency list, adjacency matrix using a two-dimensional array to represent the relationship between the vertices in the graph with vertex adjacency list of each vertex figure is created as a single current vertex list with other neighbors vertices are connected together, we must not create a single list 㤇 current vertex and the remaining vertices are connected together can make the appropriate changes according to the selected programming language in the concrete realization of, for example, Java language can be used to represent a List collection with the rest of the current vertex the relationship between vertices, set each element is associated with a

3. graph traversal There are three main methods: ① ② depth-first traversal breadth-first traversal

It should be noted that distinguish it from a different point of traversing the tree, because the figure is likely to produce circuits, so we need to add a tag used to mark whether the current vertex or edge before been visited, if access when traversing the graph after then we skip to access the next vertex or edge

4. The minimum spanning tree algorithm

There are two main algorithms: ① Prim algorithm ② Kruskal algorithm

Prim core algorithms: an array used to record the remaining vertex d shortest path to the current vertex, every time the vertex to the current vertex selection shortest mark edge connector and that the vertex is visited, and to the current vertex point as a starting point to check whether update the shortest path to the rest of the current vertex vertex, and Dijstra this algorithm in some places is very similar, it can be understood to be shining

Kruskal's algorithm core: for all edges in the graph from small to large sort, according to the right side from small to large test all sides, if the current test is not on the same side then the current Unicom in that this edge is added to the minimum spanning tree otherwise join edges generates a loop that should be rejected, and repeating steps above until the test side of all the number of edges can be equal to the number of vertices minus one, if the number of sides of the end of the minimum spanning tree is less than a top FIG change points minus 1 is then disconnected

Kruskal's algorithm idea is relatively simple to understand them a little better than Prim's algorithm

Both algorithms are directed to the undirected graph

 

The shortest path algorithm

There are the following four: ① Dijstra algorithm ② Bellman-Ford algorithm ③ SPFA algorithm ④ Floyd algorithm

There are two exam more often exam: Dijstra algorithm and Floyd algorithm

Dijstra algorithm and Prim's algorithm is similar, using an array d to record the source point to the remainder of the shortest path vertices (this is the d-array recording Prim algorithm is not the same as) the beginning of time to select a source, and each of selecting a source point is the shortest distance from the vertex to the vertex nodes and the remaining intermediate numerals have access, since the intermediate node checks whether the source to the path such that the remaining vertices shortest path is then updated if the source reaches the rest of the vertices

Floyd algorithm is a full source shortest path, that is, to solve the shortest path between FIG any vertices, and rather simple algorithm, using three cycles, check is made to an intermediate k vertices, when the path between the vertices i and j is shorter, so if shorter update path between i and j, k attention needs to be placed in the outermost loop

Guess you like

Origin blog.csdn.net/qq_39445165/article/details/91818775