2018-03-06 17:42:02
First, the shortest-circuit problem
problem Description: in the network, for all paths between two different vertices, the value of the edge and the smallest path.
- This path is the shortest path between two points (shortest path)
- The first vertex is the source point (source)
- Last vertex is end point (Destination)
Problem classification:
- Single Source Shortest path problem : from a fixed source point, the shortest path to all other vertices is obtained.
- (with direction) no power map
- (with direction) right to figure
- multi-source Shortest path problem : Find the shortest path between any two vertices.
1) Single source shortest path algorithm for unauthorized graphs
BFS can solve such problems.
2) Single source shortest path algorithm for power graphs
The Dijkstra algorithm solves the single source shortest path problem without negative edges.
3) Multi-source Shortest path algorithm
This algorithm was published by Robert W. Floyd (Robert Floyd) in 1962 on "Communications of the ACM". That same year Stephen Warshall (Stephen Vauchers) also published the algorithm independently. Floyd This cow man is a wonderful, he originally read the literature at the University of Chicago, but because the American economy is not very prosperous, find a job more difficult, helpless to Westinghouse Electric Company when a computer operator, in the IBM650 room night, and thus began his computer career.
Let's think about it, according to our previous experience, if you want to shorten the distance between any two points (for example, from vertex A to vertex B), you can only introduce a third point (vertex K) and pass through this vertex K relay, which is a->k->b, which may reduce the original distance from vertex A to vertex b. So what is the point in the 1~n that this relay vertex k is? Sometimes it is even shorter to pass through two or more points, not just through a point, a->k1->k2b-> or a->k1->k2...->k->i...->b. For example, the distance from city 4th to City 3rd (4->3) e[4][3] was originally 12. If you only pass through City 1th (4->1->3), the journey will be shortened to one (e[4][1]+e[1][3]=5+6=11). In fact, City 1th to 3rd City can also transit through the city of 2nd, making the 1th to 3rd city journey shortened to 5 (e[1][2]+e[2][3]=2+3=5). So if you go through two cities at 1th and 2nd, the distance from city 4th to City 3rd will be shortened to 10. With this example, we find that each vertex has the potential to shorten the distance between the other two vertices.
The Floyd algorithm is only allowed to pass through the number No. 0 node first, to see if it will be shortened, if it is shortened and modified, and then only allowed through the 0, 1th nodes, to see if it is shorter, plus modification, until the middle node arrives at all possible nodes.
Second, smallest spanning tree (Minimum Spanning trees)
What is the minimum spanning tree?
The minimum spanning tree algorithm uses the greedy thought, each step is selected the weight least edge.
- Prim algorithm-Let a small tree grow
First randomly selects the starting point, and then continues to grow the current node outward, looking for the shortest node to join.
- Kruskal algorithm-merging forests into trees
Third, topological sorting
Topological order : if there is a forward path from V to W in the diagram, V must precede w. The sequence of vertices that satisfy this condition is called a topological order.
The process of obtaining a topological order is topological ordering .
AOV (Activity on Vertex) If there is a reasonable topological order, it must be a directed acyclic graph (Directed acyclic graph, DAG).
For example, the course of the computer Academy is output as a topological sequence.
A clever algorithm is to put a node with a degree of 0 into the queue.
Critical path Issues:
The correlation algorithm of graph graph-graph