Data structure-6.5 figure

Preface-Data Structure

The data structure needs to be chewed repeatedly, and the answers to the problems encountered in the development can be obtained at any time.

Shortest path (directed net)

  • Find the shortest path between two vertices (solve the shortest example of the path from A to B)
  • The shortest path of a single source point (not the shortest path of any two points, that is a pair of vertices): Given a starting point (single source point) and a directed network G = {V, E} find the source point to the other Shortest path between vertices

Dijkstra algorithm

  • Description

  • Set up and gradually expand a set S (store the vertices of the shortest path that have been calculated),

  • V (all vertices)-S, which is actually W

  • Until V (all vertices)-S is empty

  • example

  • And it is the sum weight between the two points (that is, the sum of the weights) is the smallest, such as: 1-2-4-5 = 11 + 12 = 23 <1-5 = 30
    Insert picture description here

  • At last Insert picture description here

  • Summary algorithm

  • Suppose the source point V1 then S contains V1, W (all vertices except V1) = V (all vertices set)-S(V1)

  • If there is an arc <Vi,Vj>, the distance between the two vertices is the weight, otherwise it is ∞

  • Choose a vertex Vm with the smallest weight and add it to S. Each time a vertex is added to S, the distance to each vertex must be corrected

  • If <Vi,Vm> + <Vm,Vj> <<Vi,Vj>, then change the distance from Vi to the next vertex to the distance from Vm to the next vertex <Vi-Vj+1> -> <Vm- Vj+1>

  • Until W is empty and S contains all vertices

Guess you like

Origin blog.csdn.net/weixin_41732253/article/details/109632726