This week's study of the graph theory, learned all these
Two methods of storage diagram: adjacency matrix (Map[n][n]), adjacency table (Headlis[n], vector<int> g[n])
The method of saving the picture, each has the good, my understanding is, if is not that kind of very dense diagram, resembles the complete graph such diagram, the adjacency table generally will be much quicker, after all, reduces the edge traversal.
Minimum spanning Tree Kruskal
The algorithm now feels that it is useful to ask for an algorithm that connects all points and the sum of the weights of the edges,
First, the edge by the weight of the edge in ascending order, each time to select the smallest edge, if not connected, connect, and record the weights, with a and check set to determine whether two points are connected,
And check the set to determine whether connectivity is easy to achieve, and check the compression path of the set is also very simple. This algorithm feels a bit greedy.
Shortest path Dijkstra, Bellman-ford, Floyd, SPFA
Dijkstra
Applicable to the case of a positive edge, a direction diagram, a non-graph are applicable
This algorithm is to take a step to see the meaning of a step, choose the shortest path to take a step, and then go to see whether all points can pass this point can be shorter path.
D[] The meaning of this array must be established well, for example, the shortest path is recorded to the shortest distance, the shortest time is to save to a point in the shortest time
First initialize, D[n] are set to INF, vis[] are set to 0, and then start s,d[s]=0, traverse n times, each time find the smallest distance to go to the point, and then go to the mark, and then to update the point to the rest of the point can be shortened
Path, so, Mark N times, that is to say all the points have gone, can update all updated.
Optimization method: With the adjacency table, you can reduce the traversal, and then d[] replaced by a priority queue, small first out of the team, so instead of the loop N to find the smallest weight value,
Bellman-ford
Can do a negative right
The algorithm I use relatively little, not very understanding, welcome to correct.
My understanding is the cycle n-1 times, each check each side, if the starting point can arrive, to relax this edge even two points, do not know why need n-1 times can relax ...
Floyd
Feel this more violent, the direct triple loop to traverse the number of n, K cycle n times, is to see whether K this point can shorten the weight, can shorten
Use the first estimate will not time out. Initialization is the addition of the read-in Edge, the d[i][i]=0
Spfa
An algorithm that is seen on the net is generally slower than Dijkstra.
My favorite, feel like Bellman-ford optimization, and feel a little bfs meaning, very interesting
is to start from the beginning, traverse this point can go to all sides, and then see can be optimized, can optimize, to test the optimized point of all sides, see Eng can not continue to optimize, so deep
Until it cannot be optimized, it exits, and then it is a fully optimized array d[] in front of you, hahaha.
Initial augmented path algorithm for network flow
Look at the "algorithm competition-Getting Started classic" written very concise, looked at a long time did not understand, Baidu, so easy, haha, suddenly read the maximum flow problem, estimated recently no time to look at the back of the
Write a summary later
ACM Summer Camp Third Week summary