dijkstra algorithm, dynamic programming and greedy

The dijkstra algorithm is greedy, not dynamic programming.

The so-called ineffectiveness means that once the state is determined, it will not be changed by subsequent and future decisions, that is, only the pre-effects and no after-effects affect state decisions.
The term "follow-up" here naturally requires you to find a "processing sequence" and combine the state transition equation to jointly make decisions about the "state".
Therefore, you must first decompose the problem into sub-problems based on the idea of ​​optimal sub-structure, and then assume that the states of these sub-problems have all been determined before then and write the state transition equations.
Secondly, you must find a "processing sequence" to achieve "the status of the sub-problems has been determined before this."
Finally, it can be judged whether the "state" has no aftereffect. If you find the state transition equation and the processing sequence, then it has no aftereffect, otherwise it does not.

[Try to use dynamic programming to solve the single source shortest path problem]
State transition equation: d[e] = min{ d[a]+graph[a][e], d[b]+graph[b][e], d [c]+graph[c][e],…} It is
easy to know the boundary conditions, d[S]=0.
In the equation, a, b, and c are all points that are adjacent to e and whose shortest distances are all known.
But it is impossible to find a processing sequence to ensure that each time a new point is processed, the state of its neighboring points is determined before that.

[Dijkstra algorithm]
In fact, every time the state is determined, it is impossible to determine whose state is known before the calculation. In the actual operation of the algorithm, the intermediate point is first determined, and then the d[] array is updated. status. Therefore, the "order" of processing is not determined here, and the idea of ​​dijkstra's algorithm does not completely conform to dynamic programming.

[Without dynamic programming]
Since it cannot be solved in one traversal, it can be looped multiple times and continuously update the minimum value until it can no longer be smaller. This is the Bellman Ford algorithm and the Floyd algorithm.

Guess you like

Origin blog.csdn.net/sinat_37517996/article/details/104548055