God left practice with algorithm (Figure, topological sorting, minimum spanning tree algorithm) together

Figure?
Undirected graph, directed graph
how to describe a chart?
Adjacency table method, adjacency matrix
there may be unified as there are pictures to the directed graph, and not
whether it is a directed graph or no can follow have expressed to the directed graph
Here Insert Picture Description
adjacency table method:
Here Insert Picture Description
Here Insert Picture Description
adjacency list method, and adjacency matrix is the most classic of two representations, in fact there are many representations

Topological sorting

Give you a view of
Here Insert Picture Description
an example, our compiler compile a file, it is the sort carried out in accordance with the topology
Here Insert Picture Description
if that file must first compile the compiler B E, D file, the file needs to be compiled to compile C D A document compiled file need to build the B, C file
to be topologically sorted must be a directed graph, and there is no loop,
Here Insert Picture Description
the minimum spanning tree algorithm
minimum spanning tree algorithm, a certain application is no phase diagram
has two algorithms, one algorithm is the K P algorithm
K algorithm:
Here Insert Picture Description
Here Insert Picture Description
P algorithm:

Here Insert Picture Description
Here Insert Picture Description
Each time unlock a node will be introducing many new edge, looking smallest weight edge in all these edges inside to see if the node his connection is not already unlocked, if it has been unlocked, then to find the weight of the second small side

The difference between P and K algorithm algorithm:
K algorithm to use disjoint-set, because thinkers K algorithm is that the collections and collections merge so they need to set and check
P algorithm does not require a disjoint-set, is a collection of thoughts and merging individual point, a point and a heavy weight of the side connected by nodes unlocked

Published 230 original articles · won praise 28 · views 9323

Guess you like

Origin blog.csdn.net/weixin_43767691/article/details/103433164