Is Dijkstra's algorithm, dynamic programming

The entire implementation of Dijkstra's algorithms that I saw does not have a recursive function, but I also read that, by definition, dynamic programming is an algorithm with a recursive function and the "memory" of things already calculated.

So, Dijkstra's algorithm with a loop qualified as dynamic programming?
Or in order to qualify as a dynamic algorithm, I need to change the loop into a recursive function.

+9
source share
7 answers

You ask two questions:

Dynamic algorithms mean splitting a procedure into simpler tasks. Several dynamic algorithms exclude the idea of ​​recursion, but are not limited to.

Given the Dijkstra algorithm, the classical solution is specified by the for loop and is not a solution to the dynamic algorithm.

However, from the point of view of dynamic programming, Dijkstra's algorithm is a sequential approximation scheme that solves the functional dynamic programming equation for the shortest path problem by the Riching method.

In fact, Dijkstra explains the logic of the algorithm, namely:

Problem 2. Find the path of minimum total length between two given nodes P and Q. 

Note: taken from Wikipedia

0
source

All implementations of Dijkstra's algorithms that I have seen do not have a recursive function.

Recursion gives us a stack. But we don’t need a stack here. We need a priority queue. An efficient way to implement Dijkstra's algorithm uses heap (stl priority_queue in c ++).

but I also read that, by definition, dynamic programming is an algorithm with a recursive function and the “memory” of things already calculated.

Dynamic programming should not be written in a recursive way, although most people prefer to write it in a recursive way.

For instance:

 int dp[MAX]={-1,-1,...}; find fibonacci(int nthTerm){ if(n <= 1) return n; if(dp[n]!=-1) return dp[n]; return dp[n]=fibonacci(n-1)+fibonacci(n-2); } 

recursive implementation of DP

and

 int dp[MAX]={0,1,-1,-1,-1,..}; int lastFound = 1; int fibonacci(int nthTerm){ for(int i=lastFound+1;i<=n;i++){ dp[i]=dp[i-1]+dp[i-2]; } return dp[n]; } 

This is an iterative way of writing to save stack memory.

Remember that any algorithm 1) that does not recount a result that is already found, and 2) uses an existing result to find the desired result, can be called DP.

So is Dijkstra's algorithm with a loop qualified as dynamic programming?

Dijkstra is a DP!

Or in order to qualify as a dynamic algorithm, I need to convert the loop into a recursive function.

no

+16
source

There is an article about this entitled "Dijkstrass Algorithm, Revised: Dynamic Programming" by Moshe Snedovich. http://matwbn.icm.edu.pl/ksiazki/cc/cc35/cc3536.pdf

The paper states that Dijkstra's algorithm is strongly inspired by the Bellmans Principle of Optimality and that conceptually and technically this is a procedure for sequentially approaching dynamic programming par excellence.

+1
source

Dijkstra's algorithm is similar to the water filling algorithm. At every step, he chooses local minima, so many consider him a greedy algorithm. If you try the same algorithm by choosing any arbitrary path, rather than local minima, then you will find out that it still works. The choice of local minima is explained only by the fact that the water was optimal, as I mentioned earlier, since this is an algorithm for filling with water. So, the basic concept of Dijkstra's algorithm is to preserve the previous result in order to predict the upcoming result, and this is what the Dynamic Approach represents.

See link for more details.

Why does Dijkstra's algorithm work?

+1
source

First post ...

Take a look at the shortest path search process using the Djikstra method and classic dynamic programming. We start with the source node in both algorithms (i.e. In Forward DP). The next step is the same for both algorithms: we look at all the child nodes and estimate the costs to achieve them (these are just the arc lengths from the node source for its children). Then the algorithms diverge: in DP, we look at all the other nodes in the graph and calculate the best "policy" for reaching the source of the node, taking into account any other node we can be in (we form the "policy" "based on the" current state "). , in a limited connection, we only need to study the nodes that are children of the source children, but we still go through more nodes than Djikstra's ...

For Djikstra, in the second and next steps we do not study all the “remaining” related nodes. We study the cost to get to the node children who had the shortest distance to the source. This means that DP leads to longer execution times than Djikstra for most deterministic short-circuit tasks.

In Djikstra, when the path from the source to the destination is found, the algorithm ends. But in DP, the algorithm works exactly in N steps, where N is the number of nodes in the graph. In some problems, Djikstra can work in the order of the N square, but for most practical problems with sparse connectivity, it usually goes in less than N steps.

I got my basics from the Bertsekas book on dynamic programming and optimal control http://www.athenasc.com/dpbook.html

0
source

Dijkstra is a greedy algorithm, you can solve the problem of the shortest path using dynamic programming, but dynamic programming would require the algorithm to go through each individual path to reach the shortest path. he may use some optimality constraints using Memoization, but he will have to evaluate all the possible paths on the network.

Dijkstra is smarter than this, he does not go through all possible paths, he simply selects the nodes that lie on the shortest path. therefore, he does not need to evaluate all the ways to get to his destination, and that is why the complexity of Dijkstra in the worst case is completely independent of the number of edges $ O (V ^ 2) $.

-1
source

No.

Dynamic programming follows a bottom-up strategy. those. solve all the subproblems and finally come to the result.

But in Dijkstra's algorithm, we follow a top-down strategy. those. we solve the solution one by one, caching local optima. This caching process is called Memoization .

So, I would say Dijkstra's algorithm uses Greedy + Memoization .

-2
source

Source: https://habr.com/ru/post/970620/


All Articles