Graph2
G(V,E,W), E~O(V^2) for complete graph
Order of graph: V
Size of graph: E
Complete graph: has one edge between each pair of vertices.
Simple graph: has at most one edge between any pair of vertices.
Multi-Graph:can have multiple edges between pairs of vertices.(usually not considered)
Single-Source Shortest Path Problem: find a path(a sequece of edges) with shortest weight
Two algorithms:
I.Dijkstra, assuming non-negative edges, O(VlogV+E)
node has fields ( or save it to a dictionary)
1. distance d: current weight from the starting node, decreasing from positive infinity for each check(this is O(E) check).
2. predecessor node: from which node that gives current d.
II. Bellman-Ford: for positive/negative edges, O(V*E)
this algorithm considers cycles of negative weight, and gives you the shortest number for all the vertices that have finite numbers, and then mark all the other vertices as being indeterminate/negative infinity. That's the termination condition.
III. Floyd-Warshall algorithm: for positive/negative edges(no negative cycles). Dynamic Programming.
dd

浙公网安备 33010602011771号